1
1
import mock
2
2
from click .testing import CliRunner
3
3
4
- from paperspace import cli , constants , commands
4
+ from paperspace import cli , constants
5
+ from paperspace .commands import experiments as experiments_commands
5
6
from tests import example_responses
6
7
7
8
@@ -22,7 +23,7 @@ def json(self):
22
23
23
24
class TestExperimentsCreateSingleNode (object ):
24
25
URL = "https://services.paperspace.io/experiments/v1/experiments/"
25
- EXPECTED_HEADERS = commands .default_headers
26
+ EXPECTED_HEADERS = experiments_commands .default_headers
26
27
BASIC_OPTIONS_COMMAND = [
27
28
"experiments" , "create" , "singlenode" ,
28
29
"--name" , "exp1" ,
@@ -87,7 +88,7 @@ class TestExperimentsCreateSingleNode(object):
87
88
RESPONSE_CONTENT_404_PROJECT_NOT_FOUND = b'{"details":{"handle":"wrong_handle"},"error":"Project not found"}\n '
88
89
EXPECTED_STDOUT_PROJECT_NOT_FOUND = "Project not found\n handle: wrong_handle\n "
89
90
90
- @mock .patch ("paperspace.cli.commands .client.requests.post" )
91
+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.post" )
91
92
def test_should_send_proper_data_and_print_message_when_create_experiment_was_run_with_basic_options (self ,
92
93
post_patched ):
93
94
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
102
103
assert result .output == self .EXPECTED_STDOUT
103
104
assert result .exit_code == 0
104
105
105
- @mock .patch ("paperspace.cli.commands .client.requests.post" )
106
+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.post" )
106
107
def test_should_send_proper_data_and_print_message_when_create_experiment_was_run_with_full_options (self ,
107
108
post_patched ):
108
109
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
117
118
assert result .output == self .EXPECTED_STDOUT
118
119
assert result .exit_code == 0
119
120
120
- @mock .patch ("paperspace.cli.commands .client.requests.post" )
121
+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.post" )
121
122
def test_should_send_proper_data_and_print_message_when_create_wrong_project_handle_was_given (self , post_patched ):
122
123
post_patched .return_value = MockResponse (self .RESPONSE_JSON_404_PROJECT_NOT_FOUND , 404 ,
123
124
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
135
136
136
137
class TestExperimentsCreateMultiNode (object ):
137
138
URL = "https://services.paperspace.io/experiments/v1/experiments/"
138
- EXPECTED_HEADERS = commands .default_headers
139
+ EXPECTED_HEADERS = experiments_commands .default_headers
139
140
BASIC_OPTIONS_COMMAND = [
140
141
"experiments" , "create" , "multinode" ,
141
142
"--name" , "multinode_mpi" ,
@@ -226,7 +227,7 @@ class TestExperimentsCreateMultiNode(object):
226
227
RESPONSE_CONTENT_200 = b'{"handle":"sadkfhlskdjh","message":"success"}\n '
227
228
EXPECTED_STDOUT = "New experiment created with handle: sadkfhlskdjh\n "
228
229
229
- @mock .patch ("paperspace.cli.commands .client.requests.post" )
230
+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.post" )
230
231
def test_should_send_proper_data_and_print_message_when_create_experiment_was_run_with_basic_options (self ,
231
232
post_patched ):
232
233
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
241
242
assert result .output == self .EXPECTED_STDOUT
242
243
assert result .exit_code == 0
243
244
244
- @mock .patch ("paperspace.cli.commands .client.requests.post" )
245
+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.post" )
245
246
def test_should_send_proper_data_and_print_message_when_create_experiment_was_run_with_full_options (self ,
246
247
post_patched ):
247
248
post_patched .return_value = MockResponse (self .RESPONSE_JSON_200 , 200 , self .RESPONSE_CONTENT_200 )
@@ -505,7 +506,7 @@ class TestExperimentDetail(object):
505
506
+---------------------+----------------+
506
507
"""
507
508
508
- @mock .patch ("paperspace.cli.commands .client.requests.get" )
509
+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.get" )
509
510
def test_should_send_get_request_and_print_single_node_experiment_details_in_a_table (self , get_patched ):
510
511
get_patched .return_value = MockResponse (self .SINGLE_NODE_RESPONSE_JSON , 200 , "fake content" )
511
512
@@ -515,7 +516,7 @@ def test_should_send_get_request_and_print_single_node_experiment_details_in_a_t
515
516
assert result .output == self .SINGLE_NODE_DETAILS_STDOUT
516
517
assert result .exit_code == 0
517
518
518
- @mock .patch ("paperspace.cli.commands .client.requests.get" )
519
+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.get" )
519
520
def test_should_send_get_request_and_print_multi_node_experiment_details_in_a_table (self , get_patched ):
520
521
get_patched .return_value = MockResponse (self .MULTI_NODE_DETAILS_JSON , 200 , "fake content" )
521
522
@@ -525,7 +526,7 @@ def test_should_send_get_request_and_print_multi_node_experiment_details_in_a_ta
525
526
assert result .output == self .MULTI_NODE_DETAILS_STDOUT
526
527
assert result .exit_code == 0
527
528
528
- @mock .patch ("paperspace.cli.commands .client.requests.get" )
529
+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.get" )
529
530
def test_should_send_get_request_and_print_request_content_when_response_data_was_malformed (self , get_patched ):
530
531
get_patched .return_value = MockResponse ({}, 200 , "fake content" )
531
532
g = """Error parsing response data
@@ -715,7 +716,7 @@ class TestExperimentList(object):
715
716
+---------------+---------------+---------+
716
717
"""
717
718
718
- @mock .patch ("paperspace.cli.commands .client.requests.get" )
719
+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.get" )
719
720
def test_should_send_get_request_and_print_list_of_experiments (self , get_patched ):
720
721
get_patched .return_value = MockResponse (self .LIST_JSON , 200 , "fake content" )
721
722
@@ -724,8 +725,8 @@ def test_should_send_get_request_and_print_list_of_experiments(self, get_patched
724
725
725
726
assert result .output == self .DETAILS_STDOUT
726
727
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" )
729
730
def test_should_send_get_request_and_paginate_list_when_output_table_len_is_gt_lines_in_terminal (self , get_patched ,
730
731
pydoc_patched ):
731
732
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
737
738
pydoc_patched .pager .assert_called_once ()
738
739
assert result .exit_code == 0
739
740
740
- @mock .patch ("paperspace.cli.commands .client.requests.get" )
741
+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.get" )
741
742
def test_should_send_get_request_and_print_list_of_experiments_filtered_with_two_projects (self , get_patched ):
742
743
get_patched .return_value = MockResponse (example_responses .LIST_OF_EXPERIMENTS_FILTERED_WITH_TWO_PROJECTS , 200 ,
743
744
"fake content" )
@@ -747,7 +748,7 @@ def test_should_send_get_request_and_print_list_of_experiments_filtered_with_two
747
748
748
749
assert result .output == example_responses .LIST_OF_EXPERIMENTS_FILTERED_WITH_TWO_PROJECTS_STDOUT
749
750
750
- @mock .patch ("paperspace.cli.commands .client.requests.get" )
751
+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.get" )
751
752
def test_should_send_get_request_and_print_list_of_experiments_filtered_with_two_projects_but_none_found (
752
753
self , get_patched ):
753
754
get_patched .return_value = MockResponse (example_responses .LIST_OF_EXPERIMENTS_FILTERED_BUT_NONE_FOUND , 200 ,
@@ -764,7 +765,7 @@ class TestStartExperiment(object):
764
765
RESPONSE_JSON = {"message" : "success" }
765
766
START_STDOUT = "Experiment started\n "
766
767
767
- @mock .patch ("paperspace.cli.commands .client.requests.put" )
768
+ @mock .patch ("paperspace.cli.experiments_commands .client.requests.put" )
768
769
def test_should_send_put_request_and_print_confirmation (self , put_patched ):
769
770
put_patched .return_value = MockResponse (self .RESPONSE_JSON , 200 , "fake content" )
770
771
0 commit comments