|
| 1 | +import mock |
| 2 | +from click.testing import CliRunner |
| 3 | + |
| 4 | +from paperspace.cli import cli |
| 5 | +from paperspace.client import default_headers |
| 6 | +from tests import MockResponse, example_responses |
| 7 | + |
| 8 | + |
| 9 | +class TestListLogs(object): |
| 10 | + URL = "https://logs.paperspace.io" |
| 11 | + EXPECTED_HEADERS = default_headers.copy() |
| 12 | + EXPECTED_RESPONSE_JSON = example_responses.LIST_OF_LOGS_FOR_JOB |
| 13 | + BASIC_COMMAND = ["logs", "list"] |
| 14 | + EXPECTED_STDOUT = """+Job jztdeungdkzjv logs------------------------------------------------------------------+ |
| 15 | +| LINE | MESSAGE | |
| 16 | ++------+---------------------------------------------------------------------------------+ |
| 17 | +| 1 | Traceback (most recent call last): | |
| 18 | +| 2 | File "generate_figures.py", line 15, in <module> | |
| 19 | +| 3 | import dnnlib.tflib as tflib | |
| 20 | +| 4 | File "/paperspace/dnnlib/tflib/__init__.py", line 8, in <module> | |
| 21 | +| 5 | from . import autosummary | |
| 22 | +| 6 | File "/paperspace/dnnlib/tflib/autosummary.py", line 31, in <module> | |
| 23 | +| 7 | from . import tfutil | |
| 24 | +| 8 | File "/paperspace/dnnlib/tflib/tfutil.py", line 34, in <module> | |
| 25 | +| 9 | def shape_to_list(shape: Iterable[tf.Dimension]) -> List[Union[int, None]]: | |
| 26 | +| 10 | AttributeError: module 'tensorflow' has no attribute 'Dimension' | |
| 27 | +| 11 | PSEOF | |
| 28 | ++------+---------------------------------------------------------------------------------+ |
| 29 | +""" |
| 30 | + |
| 31 | + @mock.patch("paperspace.cli.cli.client.requests.get") |
| 32 | + def test_should_send_valid_get_request_and_print_table_with_logs(self, get_patched): |
| 33 | + get_patched.return_value = MockResponse(json_data=self.EXPECTED_RESPONSE_JSON, status_code=200) |
| 34 | + |
| 35 | + cli_runner = CliRunner() |
| 36 | + result = cli_runner.invoke(cli.cli, self.BASIC_COMMAND) |
| 37 | + |
| 38 | + get_patched.assert_called_with(self.URL, |
| 39 | + headers=self.EXPECTED_HEADERS, |
| 40 | + json=None, |
| 41 | + params=None) |
| 42 | + |
| 43 | + assert result.output == self.EXPECTED_STDOUT |
| 44 | + assert result.exit_code == 0 |
0 commit comments