|
| 1 | +import copy |
1 | 2 | import os |
2 | 3 | import shutil |
3 | 4 | import tempfile |
@@ -98,6 +99,11 @@ class TestExperimentsCreateSingleNode(object): |
98 | 99 | "experiments", "create", "singlenode", |
99 | 100 | "--optionsFile", # path added in test, |
100 | 101 | ] |
| 102 | + FULL_OPTIONS_COMMAND_WITH_OPTIONS_FILE_AND_SOME_VALUES_OVERWRITTEN_IN_LINE = [ |
| 103 | + "experiments", "create", "singlenode", |
| 104 | + "--name", "some_other_name", |
| 105 | + "--optionsFile", # path added in test, |
| 106 | + ] |
101 | 107 | BASIC_OPTIONS_REQUEST = { |
102 | 108 | "projectHandle": u"testHandle", |
103 | 109 | "container": u"testContainer", |
@@ -173,6 +179,29 @@ def test_should_read_options_from_config_file( |
173 | 179 | data=None) |
174 | 180 | assert result.exit_code == 0, result.exc_info |
175 | 181 |
|
| 182 | + @mock.patch("gradient.api_sdk.clients.http_client.requests.post") |
| 183 | + def test_should_read_options_from_config_file_and_overwrite_options_with_values_provided_in_terminal( |
| 184 | + self, post_patched, create_single_node_experiment_config_path): |
| 185 | + post_patched.return_value = MockResponse(self.RESPONSE_JSON_200) |
| 186 | + request_json = copy.deepcopy(self.FULL_OPTIONS_REQUEST) |
| 187 | + request_json["name"] = "some_other_name" |
| 188 | + request_json["projectHandle"] = "some_other_project_id" |
| 189 | + |
| 190 | + command = self.FULL_OPTIONS_COMMAND_WITH_OPTIONS_FILE_AND_SOME_VALUES_OVERWRITTEN_IN_LINE[:] |
| 191 | + command = command[:] + [create_single_node_experiment_config_path, "--projectId", "some_other_project_id"] |
| 192 | + |
| 193 | + runner = CliRunner() |
| 194 | + result = runner.invoke(cli.cli, command) |
| 195 | + |
| 196 | + assert self.EXPECTED_STDOUT in result.output, result.exc_info |
| 197 | + post_patched.assert_called_once_with(self.URL_V2, |
| 198 | + headers=EXPECTED_HEADERS_WITH_CHANGED_API_KEY, |
| 199 | + json=request_json, |
| 200 | + params=None, |
| 201 | + files=None, |
| 202 | + data=None) |
| 203 | + assert result.exit_code == 0, result.exc_info |
| 204 | + |
176 | 205 | @mock.patch("gradient.api_sdk.clients.http_client.requests.post") |
177 | 206 | def test_should_send_proper_data_and_print_message_when_create_experiment_was_run_with_full_options(self, |
178 | 207 | post_patched): |
@@ -953,6 +982,11 @@ class TestExperimentsCreateAndStartSingleNode(TestExperimentsCreateSingleNode): |
953 | 982 | "experiments", "run", "singlenode", |
954 | 983 | "--optionsFile", # path added in test, |
955 | 984 | ] |
| 985 | + FULL_OPTIONS_COMMAND_WITH_OPTIONS_FILE_AND_SOME_VALUES_OVERWRITTEN_IN_LINE = [ |
| 986 | + "experiments", "run", "singlenode", |
| 987 | + "--name", "some_other_name", |
| 988 | + "--optionsFile", # path added in test, |
| 989 | + ] |
956 | 990 | EXPECTED_STDOUT = "New experiment created and started with ID: sadkfhlskdjh\n" |
957 | 991 |
|
958 | 992 |
|
|
0 commit comments