44from paperspace import cli , constants
55
66
7+ @mock .patch ("paperspace.cli.client.API" )
78@mock .patch ("paperspace.cli.experiments_commands" )
8- def test_should_execute_create_experiment_command_when_cli_singlenode_command_was_executed (commands_patched ):
9+ def test_should_execute_create_experiment_command_when_cli_singlenode_command_was_executed (commands_patched ,
10+ api_patched ):
11+ api_patched .return_value = mock .MagicMock ()
912 runner = CliRunner ()
1013 command = "experiments create singlenode " \
1114 "--name exp1 " \
1215 "--projectHandle testHandle " \
1316 "--container testContainer " \
1417 "--machineType testType " \
1518 "--command testCommand " \
16- "--workspaceUrl wUrl"
19+ "--workspaceUrl wUrl " \
20+ "--apiKey some_key"
1721 expected_kwargs = {"name" : u"exp1" ,
1822 "projectHandle" : u"testHandle" ,
1923 "container" : u"testContainer" ,
@@ -26,11 +30,14 @@ def test_should_execute_create_experiment_command_when_cli_singlenode_command_wa
2630 result = runner .invoke (cli .cli , command .split ())
2731
2832 assert result .exit_code == 0
29- commands_patched .create_experiment .assert_called_once_with (expected_kwargs )
33+ commands_patched .create_experiment .assert_called_once_with (expected_kwargs , api = api_patched () )
3034
3135
36+ @mock .patch ("paperspace.cli.client.API" )
3237@mock .patch ("paperspace.cli.experiments_commands" )
33- def test_should_execute_create_experiment_command_when_cli_multinode_mpi_command_was_executed (commands_patched ):
38+ def test_should_execute_create_experiment_command_when_cli_multinode_mpi_command_was_executed (commands_patched ,
39+ api_patched ):
40+ api_patched .return_value = mock .MagicMock ()
3441 runner = CliRunner ()
3542 command = "experiments create multinode " \
3643 "--name exp1 " \
@@ -44,7 +51,8 @@ def test_should_execute_create_experiment_command_when_cli_multinode_mpi_command
4451 "--parameterServerMachineType testParameterServerMachineType " \
4552 "--parameterServerCommand testParameterServerCommand " \
4653 "--parameterServerCount 3 " \
47- "--workspaceUrl wUrl"
54+ "--workspaceUrl wUrl " \
55+ "--apiKey some_key"
4856 expected_kwargs = {"name" : u"exp1" ,
4957 "projectHandle" : u"testHandle" ,
5058 "experimentTypeId" : constants .ExperimentType .MPI_MULTI_NODE ,
@@ -62,11 +70,14 @@ def test_should_execute_create_experiment_command_when_cli_multinode_mpi_command
6270 result = runner .invoke (cli .cli , command .split ())
6371
6472 assert result .exit_code == 0
65- commands_patched .create_experiment .assert_called_once_with (expected_kwargs )
73+ commands_patched .create_experiment .assert_called_once_with (expected_kwargs , api = api_patched () )
6674
6775
76+ @mock .patch ("paperspace.cli.client.API" )
6877@mock .patch ("paperspace.cli.experiments_commands" )
69- def test_should_execute_create_experiment_command_when_cli_multinode_grpc_command_was_executed (commands_patched ):
78+ def test_should_execute_create_experiment_command_when_cli_multinode_grpc_command_was_executed (commands_patched ,
79+ api_patched ):
80+ api_patched .return_value = mock .MagicMock ()
7081 runner = CliRunner ()
7182 command = "experiments create multinode " \
7283 "--name exp1 " \
@@ -98,20 +109,23 @@ def test_should_execute_create_experiment_command_when_cli_multinode_grpc_comman
98109 result = runner .invoke (cli .cli , command .split ())
99110
100111 assert result .exit_code == 0
101- commands_patched .create_experiment .assert_called_once_with (expected_kwargs )
112+ commands_patched .create_experiment .assert_called_once_with (expected_kwargs , api = api_patched () )
102113
103114
115+ @mock .patch ("paperspace.cli.client.API" )
104116@mock .patch ("paperspace.cli.experiments_commands" )
105117def test_should_execute_create_experiment_command_when_cli_create_and_start_singlenode_command_was_executed (
106- commands_patched ):
118+ commands_patched , api_patched ):
119+ api_patched .return_value = mock .MagicMock ()
107120 runner = CliRunner ()
108121 command = "experiments createAndStart singlenode " \
109122 "--name exp1 " \
110123 "--projectHandle testHandle " \
111124 "--container testContainer " \
112125 "--machineType testType " \
113126 "--command testCommand " \
114- "--workspaceUrl wUrl"
127+ "--workspaceUrl wUrl " \
128+ "--apiKey some_key"
115129 expected_kwargs = {"name" : u"exp1" ,
116130 "projectHandle" : u"testHandle" ,
117131 "container" : u"testContainer" ,
@@ -124,12 +138,14 @@ def test_should_execute_create_experiment_command_when_cli_create_and_start_sing
124138 result = runner .invoke (cli .cli , command .split ())
125139
126140 assert result .exit_code == 0
127- commands_patched .create_and_start_experiment .assert_called_once_with (expected_kwargs )
141+ commands_patched .create_and_start_experiment .assert_called_once_with (expected_kwargs , api = api_patched () )
128142
129143
144+ @mock .patch ("paperspace.cli.client.API" )
130145@mock .patch ("paperspace.cli.experiments_commands" )
131146def test_should_execute_create_experiment_command_when_cli_create_and_start_multinode_mpi_command_was_executed (
132- commands_patched ):
147+ commands_patched , api_patched ):
148+ api_patched .return_value = mock .MagicMock ()
133149 runner = CliRunner ()
134150 command = "experiments createAndStart multinode " \
135151 "--name exp1 " \
@@ -161,4 +177,4 @@ def test_should_execute_create_experiment_command_when_cli_create_and_start_mult
161177 result = runner .invoke (cli .cli , command .split ())
162178
163179 assert result .exit_code == 0
164- commands_patched .create_and_start_experiment .assert_called_once_with (expected_kwargs )
180+ commands_patched .create_and_start_experiment .assert_called_once_with (expected_kwargs , api = api_patched () )
0 commit comments