11import mock
22from click .testing import CliRunner
33
4- from paperspace import cli , constants , commands
4+ from paperspace import cli , constants
5+ from paperspace .commands import experiments as experiments_commands
56from tests import example_responses
67
78
@@ -22,7 +23,7 @@ def json(self):
2223
2324class TestExperimentsCreateSingleNode (object ):
2425 URL = "https://services.paperspace.io/experiments/v1/experiments/"
25- EXPECTED_HEADERS = commands .default_headers
26+ EXPECTED_HEADERS = experiments_commands .default_headers
2627 BASIC_OPTIONS_COMMAND = [
2728 "experiments" , "create" , "singlenode" ,
2829 "--name" , "exp1" ,
@@ -87,7 +88,7 @@ class TestExperimentsCreateSingleNode(object):
8788 RESPONSE_CONTENT_404_PROJECT_NOT_FOUND = b'{"details":{"handle":"wrong_handle"},"error":"Project not found"}\n '
8889 EXPECTED_STDOUT_PROJECT_NOT_FOUND = "Project not found\n handle: wrong_handle\n "
8990
90- @mock .patch ("paperspace.cli.commands .client.requests.post" )
91+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.post" )
9192 def test_should_send_proper_data_and_print_message_when_create_experiment_was_run_with_basic_options (self ,
9293 post_patched ):
9394 post_patched .return_value = MockResponse (self .RESPONSE_JSON_200 , 200 , self .RESPONSE_CONTENT_200 )
@@ -102,7 +103,7 @@ def test_should_send_proper_data_and_print_message_when_create_experiment_was_ru
102103 assert result .output == self .EXPECTED_STDOUT
103104 assert result .exit_code == 0
104105
105- @mock .patch ("paperspace.cli.commands .client.requests.post" )
106+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.post" )
106107 def test_should_send_proper_data_and_print_message_when_create_experiment_was_run_with_full_options (self ,
107108 post_patched ):
108109 post_patched .return_value = MockResponse (self .RESPONSE_JSON_200 , 200 , self .RESPONSE_CONTENT_200 )
@@ -117,7 +118,7 @@ def test_should_send_proper_data_and_print_message_when_create_experiment_was_ru
117118 assert result .output == self .EXPECTED_STDOUT
118119 assert result .exit_code == 0
119120
120- @mock .patch ("paperspace.cli.commands .client.requests.post" )
121+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.post" )
121122 def test_should_send_proper_data_and_print_message_when_create_wrong_project_handle_was_given (self , post_patched ):
122123 post_patched .return_value = MockResponse (self .RESPONSE_JSON_404_PROJECT_NOT_FOUND , 404 ,
123124 self .RESPONSE_CONTENT_404_PROJECT_NOT_FOUND )
@@ -135,7 +136,7 @@ def test_should_send_proper_data_and_print_message_when_create_wrong_project_han
135136
136137class TestExperimentsCreateMultiNode (object ):
137138 URL = "https://services.paperspace.io/experiments/v1/experiments/"
138- EXPECTED_HEADERS = commands .default_headers
139+ EXPECTED_HEADERS = experiments_commands .default_headers
139140 BASIC_OPTIONS_COMMAND = [
140141 "experiments" , "create" , "multinode" ,
141142 "--name" , "multinode_mpi" ,
@@ -226,7 +227,7 @@ class TestExperimentsCreateMultiNode(object):
226227 RESPONSE_CONTENT_200 = b'{"handle":"sadkfhlskdjh","message":"success"}\n '
227228 EXPECTED_STDOUT = "New experiment created with handle: sadkfhlskdjh\n "
228229
229- @mock .patch ("paperspace.cli.commands .client.requests.post" )
230+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.post" )
230231 def test_should_send_proper_data_and_print_message_when_create_experiment_was_run_with_basic_options (self ,
231232 post_patched ):
232233 post_patched .return_value = MockResponse (self .RESPONSE_JSON_200 , 200 , self .RESPONSE_CONTENT_200 )
@@ -241,7 +242,7 @@ def test_should_send_proper_data_and_print_message_when_create_experiment_was_ru
241242 assert result .output == self .EXPECTED_STDOUT
242243 assert result .exit_code == 0
243244
244- @mock .patch ("paperspace.cli.commands .client.requests.post" )
245+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.post" )
245246 def test_should_send_proper_data_and_print_message_when_create_experiment_was_run_with_full_options (self ,
246247 post_patched ):
247248 post_patched .return_value = MockResponse (self .RESPONSE_JSON_200 , 200 , self .RESPONSE_CONTENT_200 )
@@ -505,7 +506,7 @@ class TestExperimentDetail(object):
505506+---------------------+----------------+
506507"""
507508
508- @mock .patch ("paperspace.cli.commands .client.requests.get" )
509+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.get" )
509510 def test_should_send_get_request_and_print_single_node_experiment_details_in_a_table (self , get_patched ):
510511 get_patched .return_value = MockResponse (self .SINGLE_NODE_RESPONSE_JSON , 200 , "fake content" )
511512
@@ -515,7 +516,7 @@ def test_should_send_get_request_and_print_single_node_experiment_details_in_a_t
515516 assert result .output == self .SINGLE_NODE_DETAILS_STDOUT
516517 assert result .exit_code == 0
517518
518- @mock .patch ("paperspace.cli.commands .client.requests.get" )
519+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.get" )
519520 def test_should_send_get_request_and_print_multi_node_experiment_details_in_a_table (self , get_patched ):
520521 get_patched .return_value = MockResponse (self .MULTI_NODE_DETAILS_JSON , 200 , "fake content" )
521522
@@ -525,7 +526,7 @@ def test_should_send_get_request_and_print_multi_node_experiment_details_in_a_ta
525526 assert result .output == self .MULTI_NODE_DETAILS_STDOUT
526527 assert result .exit_code == 0
527528
528- @mock .patch ("paperspace.cli.commands .client.requests.get" )
529+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.get" )
529530 def test_should_send_get_request_and_print_request_content_when_response_data_was_malformed (self , get_patched ):
530531 get_patched .return_value = MockResponse ({}, 200 , "fake content" )
531532 g = """Error parsing response data
@@ -715,7 +716,7 @@ class TestExperimentList(object):
715716+---------------+---------------+---------+
716717"""
717718
718- @mock .patch ("paperspace.cli.commands .client.requests.get" )
719+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.get" )
719720 def test_should_send_get_request_and_print_list_of_experiments (self , get_patched ):
720721 get_patched .return_value = MockResponse (self .LIST_JSON , 200 , "fake content" )
721722
@@ -724,8 +725,8 @@ def test_should_send_get_request_and_print_list_of_experiments(self, get_patched
724725
725726 assert result .output == self .DETAILS_STDOUT
726727
727- @mock .patch ("paperspace.cli.commands .pydoc" )
728- @mock .patch ("paperspace.cli.commands .client.requests.get" )
728+ @mock .patch ("paperspace.cli.experiments_commands .pydoc" )
729+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.get" )
729730 def test_should_send_get_request_and_paginate_list_when_output_table_len_is_gt_lines_in_terminal (self , get_patched ,
730731 pydoc_patched ):
731732 list_json = {"data" : self .LIST_JSON ["data" ] * 40 }
@@ -737,7 +738,7 @@ def test_should_send_get_request_and_paginate_list_when_output_table_len_is_gt_l
737738 pydoc_patched .pager .assert_called_once ()
738739 assert result .exit_code == 0
739740
740- @mock .patch ("paperspace.cli.commands .client.requests.get" )
741+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.get" )
741742 def test_should_send_get_request_and_print_list_of_experiments_filtered_with_two_projects (self , get_patched ):
742743 get_patched .return_value = MockResponse (example_responses .LIST_OF_EXPERIMENTS_FILTERED_WITH_TWO_PROJECTS , 200 ,
743744 "fake content" )
@@ -747,7 +748,7 @@ def test_should_send_get_request_and_print_list_of_experiments_filtered_with_two
747748
748749 assert result .output == example_responses .LIST_OF_EXPERIMENTS_FILTERED_WITH_TWO_PROJECTS_STDOUT
749750
750- @mock .patch ("paperspace.cli.commands .client.requests.get" )
751+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.get" )
751752 def test_should_send_get_request_and_print_list_of_experiments_filtered_with_two_projects_but_none_found (
752753 self , get_patched ):
753754 get_patched .return_value = MockResponse (example_responses .LIST_OF_EXPERIMENTS_FILTERED_BUT_NONE_FOUND , 200 ,
@@ -764,7 +765,7 @@ class TestStartExperiment(object):
764765 RESPONSE_JSON = {"message" : "success" }
765766 START_STDOUT = "Experiment started\n "
766767
767- @mock .patch ("paperspace.cli.commands .client.requests.put" )
768+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.put" )
768769 def test_should_send_put_request_and_print_confirmation (self , put_patched ):
769770 put_patched .return_value = MockResponse (self .RESPONSE_JSON , 200 , "fake content" )
770771
0 commit comments