Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit ce42376

Browse files
committed
Feature PS-9868:
Configure tox to run tests on different environments. Fix some issue with code on different python versions.
1 parent 7bba905 commit ce42376

File tree

6 files changed

+191
-24
lines changed

6 files changed

+191
-24
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ gradient-statsd = "*"
1414
click = "*"
1515
terminaltables = "*"
1616
colorclass = "*"
17+
tox = "*"
1718

1819
[dev-packages]
1920
twine = "*"

Pipfile.lock

Lines changed: 59 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

paperspace/commands/logs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ class ListLogsCommand(CommandBase):
1414
is_logs_complete = False
1515

1616
def execute(self, job_id):
17+
table_title = "Job %s logs" % job_id
1718
table_data = [("LINE", "MESSAGE")]
18-
table = terminaltables.AsciiTable(table_data, title=f"Job {job_id} logs")
19+
table = terminaltables.AsciiTable(table_data, title=table_title)
1920

2021
while not self.is_logs_complete:
2122
response = self._get_logs(job_id)

tests/example_responses.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,3 +2247,51 @@
22472247
"experimentId": "es47og38wzhnuo"
22482248
}
22492249
]
2250+
2251+
LIST_OF_LOGS_FOR_JOB = [
2252+
{
2253+
"line": 1,
2254+
"timestamp": "2019-04-03T15:56:35.457Z",
2255+
"message": "Traceback (most recent call last):"
2256+
}, {
2257+
"line": 2,
2258+
"timestamp": "2019-04-03T15:56:35.458Z",
2259+
"message": " File \"generate_figures.py\", line 15, in \u003cmodule\u003e"
2260+
}, {
2261+
"line": 3,
2262+
"timestamp": "2019-04-03T15:56:35.458Z",
2263+
"message": " import dnnlib.tflib as tflib"
2264+
}, {
2265+
"line": 4,
2266+
"timestamp": "2019-04-03T15:56:35.458Z",
2267+
"message": " File \"/paperspace/dnnlib/tflib/__init__.py\", line 8, in \u003cmodule\u003e"
2268+
}, {
2269+
"line": 5,
2270+
"timestamp": "2019-04-03T15:56:35.458Z",
2271+
"message": " from . import autosummary"
2272+
}, {
2273+
"line": 6,
2274+
"timestamp": "2019-04-03T15:56:35.458Z",
2275+
"message": " File \"/paperspace/dnnlib/tflib/autosummary.py\", line 31, in \u003cmodule\u003e"
2276+
}, {
2277+
"line": 7,
2278+
"timestamp": "2019-04-03T15:56:35.458Z",
2279+
"message": " from . import tfutil"
2280+
}, {
2281+
"line": 8,
2282+
"timestamp": "2019-04-03T15:56:35.458Z",
2283+
"message": " File \"/paperspace/dnnlib/tflib/tfutil.py\", line 34, in \u003cmodule\u003e"
2284+
}, {
2285+
"line": 9,
2286+
"timestamp": "2019-04-03T15:56:35.458Z",
2287+
"message": " def shape_to_list(shape: Iterable[tf.Dimension]) -\u003e List[Union[int, None]]:"
2288+
}, {
2289+
"line": 10,
2290+
"timestamp": "2019-04-03T15:56:35.458Z",
2291+
"message": "AttributeError: module 'tensorflow' has no attribute 'Dimension'"
2292+
}, {
2293+
"line": 11,
2294+
"timestamp": "2019-04-03T15:56:46.168Z",
2295+
"message": "PSEOF"
2296+
}
2297+
]

tests/functional/test_logs.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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

tox.ini

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[run]
2+
omit = tests/*
3+
4+
[tool:pytest]
5+
addopts = --cov=paperspace
6+
7+
[tox]
8+
envlist =
9+
check
10+
{py27,py34,py35,py36,py37}-{pt44}-{ptc26}
11+
skip_missing_interpreters = True
12+
13+
[testenv]
14+
changedir = tests
15+
16+
extras = testing
17+
setenv =
18+
PYTHONUNBUFFERED=yes
19+
passenv =
20+
*
21+
deps =
22+
mock
23+
pt44: pytest==4.4.1
24+
25+
ptc26: pytest-cov==2.6.1
26+
pip_pre = true
27+
28+
commands =
29+
pytest --cov=paperspace --cov-append
30+
31+
[testenv:check]
32+
deps =
33+
flake8
34+
skip_install = true
35+
usedevelop = false
36+
commands =
37+
flake8 paperspace tests setup.py

0 commit comments

Comments
 (0)