Skip to content

Commit 0de0b18

Browse files
committed
Use exitcodes.
1 parent 5a1f83b commit 0de0b18

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

tests/test_cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import pytest
77
from pytask import cli
8+
from pytask import ExitCode
89

910

1011
@pytest.mark.end_to_end
@@ -22,5 +23,5 @@ def task_1(produces):
2223
result = runner.invoke(cli, [tmp_path.as_posix(), "-n", "2", "--delay", "5"])
2324
end = time()
2425

25-
assert result.exit_code == 0
26+
assert result.exit_code == ExitCode.OK
2627
assert end - start > 5

tests/test_config.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import textwrap
55

66
import pytest
7+
from pytask import ExitCode
78
from pytask import main
89
from pytask_parallel.backends import PARALLEL_BACKENDS
910

@@ -29,15 +30,15 @@ def test_interplay_between_debugging_and_parallel(tmp_path, pdb, n_workers, expe
2930
@pytest.mark.parametrize(
3031
"configuration_option, value, exit_code",
3132
[
32-
("n_workers", "auto", 0),
33-
("n_workers", 1, 0),
34-
("n_workers", 2, 0),
35-
("delay", 0.1, 0),
36-
("delay", 1, 0),
37-
("parallel_backend", "unknown_backend", 2),
33+
("n_workers", "auto", ExitCode.OK),
34+
("n_workers", 1, ExitCode.OK),
35+
("n_workers", 2, ExitCode.OK),
36+
("delay", 0.1, ExitCode.OK),
37+
("delay", 1, ExitCode.OK),
38+
("parallel_backend", "unknown_backend", ExitCode.CONFIGURATION_FAILED),
3839
]
3940
+ [
40-
("parallel_backend", parallel_backend, 0)
41+
("parallel_backend", parallel_backend, ExitCode.OK)
4142
for parallel_backend in PARALLEL_BACKENDS
4243
],
4344
)
@@ -55,5 +56,5 @@ def test_reading_values_from_config_file(
5556
assert session.exit_code == exit_code
5657
if value == "auto":
5758
value = os.cpu_count() - 1
58-
if session.exit_code == 0:
59+
if session.exit_code == ExitCode.OK:
5960
assert session.config[configuration_option] == value

tests/test_execute.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pytest
99
from pytask import cli
10+
from pytask import ExitCode
1011
from pytask import main
1112
from pytask import Task
1213
from pytask_parallel.backends import PARALLEL_BACKENDS
@@ -39,7 +40,7 @@ def task_2(produces):
3940

4041
session = main({"paths": tmp_path})
4142

42-
assert session.exit_code == 0
43+
assert session.exit_code == ExitCode.OK
4344
assert session.execution_end - session.execution_start > 10
4445

4546
tmp_path.joinpath("out_1.txt").unlink()
@@ -49,7 +50,7 @@ def task_2(produces):
4950
{"paths": tmp_path, "n_workers": 2, "parallel_backend": parallel_backend}
5051
)
5152

52-
assert session.exit_code == 0
53+
assert session.exit_code == ExitCode.OK
5354
assert session.execution_end - session.execution_start < 10
5455

5556

@@ -76,7 +77,7 @@ def task_2(produces):
7677
result = runner.invoke(cli, [tmp_path.as_posix()])
7778
end = time()
7879

79-
assert result.exit_code == 0
80+
assert result.exit_code == ExitCode.OK
8081
assert end - start > 10
8182

8283
tmp_path.joinpath("out_1.txt").unlink()
@@ -95,7 +96,7 @@ def task_2(produces):
9596
)
9697
end = time()
9798

98-
assert result.exit_code == 0
99+
assert result.exit_code == ExitCode.OK
99100
assert "Started 2 workers." in result.output
100101
assert end - start < 10
101102

@@ -162,6 +163,7 @@ def task_2(produces):
162163
}
163164
)
164165

166+
assert session.exit_code == ExitCode.OK
165167
assert 3 < session.execution_end - session.execution_start < 10
166168

167169

@@ -190,6 +192,7 @@ def task_3():
190192
}
191193
)
192194

195+
assert session.exit_code == ExitCode.OK
193196
assert len(session.tasks) == 3
194197
assert len(session.execution_reports) == 2
195198

@@ -229,7 +232,7 @@ def task_5():
229232
{"paths": tmp_path, "parallel_backend": parallel_backend, "n_workers": 2}
230233
)
231234

232-
assert session.exit_code == 0
235+
assert session.exit_code == ExitCode.OK
233236
first_task_name = session.execution_reports[0].task.name
234237
assert first_task_name.endswith("task_0") or first_task_name.endswith("task_3")
235238
last_task_name = session.execution_reports[-1].task.name
@@ -256,7 +259,7 @@ def task_raising_error():
256259
args.append("--show-locals")
257260
result = runner.invoke(cli, args)
258261

259-
assert result.exit_code == 1
262+
assert result.exit_code == ExitCode.FAILED
260263
assert "───── Traceback" in result.output
261264
assert ("───── locals" in result.output) is show_locals
262265
assert ("[0, 1, 2, 3, 4]" in result.output) is show_locals
@@ -285,4 +288,4 @@ def task_example(produces):
285288
{"paths": tmp_path, "parallel_backend": parallel_backend, "n_workers": 2}
286289
)
287290

288-
assert session.exit_code == 0
291+
assert session.exit_code == ExitCode.OK

0 commit comments

Comments
 (0)