-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathtest_scripts.py
More file actions
59 lines (49 loc) · 1.4 KB
/
Copy pathtest_scripts.py
File metadata and controls
59 lines (49 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# %% IMPORTS
import json
import os
import pydantic as pdt
import pytest
from _pytest import capture as pc
from bikes import scripts
# %% SCRIPTS
def test_schema(capsys: pc.CaptureFixture[str]) -> None:
# given
args = ["prog", "--schema"]
# when
scripts.main(args)
captured = capsys.readouterr()
# then
assert captured.err == "", "Captured error should be empty!"
assert json.loads(captured.out), "Captured output should be a JSON!"
@pytest.mark.parametrize(
"scenario",
[
"valid",
pytest.param(
"invalid",
marks=pytest.mark.xfail(
reason="Invalid config.",
raises=pdt.ValidationError,
),
),
],
)
def test_main(scenario: str, confs_path: str, extra_config: str) -> None:
# given
folder = os.path.join(confs_path, scenario)
confs = sorted(os.listdir(folder))
# when
for conf in confs: # one job per config
config = os.path.join(folder, conf)
argv = [config, "-e", extra_config]
status = scripts.main(argv=argv)
# then
assert status == 0, f"Job should succeed for config: {config}"
def test_main__no_configs() -> None:
# given
argv: list[str] = []
# when
with pytest.raises(RuntimeError) as error:
scripts.main(argv)
# then
assert error.match("No configs provided."), "RuntimeError should be raised!"