Skip to content

Commit 45df476

Browse files
committed
Merge branch 'mr/pmderodat/e3-test' into 'master'
Add tests for e3-test See merge request it/e3-testsuite!57
2 parents 078f0d3 + c1fe0ee commit 45df476

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

tests/tests/test_e3_test.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
"""Tests for the e3-test script."""
2+
3+
from contextlib import chdir
4+
import sys
5+
6+
import yaml
7+
8+
from e3.fs import cp, mkdir
9+
from e3.testsuite import Testsuite as Suite
10+
import e3.testsuite.driver.classic as classic
11+
from e3.testsuite.main import main
12+
from e3.testsuite.result import TestStatus as Status
13+
14+
15+
if __name__ == "__main__":
16+
17+
class MyDriver(classic.ClassicTestDriver):
18+
def run(self):
19+
pass
20+
21+
class MySuite(Suite):
22+
tests_subdir = "tests"
23+
test_driver_map = {"my_driver": MyDriver}
24+
25+
sys.exit(MySuite().testsuite_main())
26+
27+
28+
from .utils import check_result_dirs
29+
30+
31+
def setup_testsuite(tmp_path, **config):
32+
"""Set up the testsuite tree under the given temporary directory."""
33+
# Copy this file to act at the testsuite script (see the __name__ check
34+
# above).
35+
cp(__file__, str(tmp_path / "run.py"))
36+
37+
# Create the hierarchy of test directories
38+
for test_dir in [
39+
"tests/a",
40+
"tests/b",
41+
"tests/c/0",
42+
"tests/c/1",
43+
"tests/c/2",
44+
]:
45+
p = tmp_path / test_dir
46+
mkdir(p)
47+
with (p / "test.yaml").open("w") as f:
48+
yaml.dump({"driver": "my_driver"}, f)
49+
50+
with (tmp_path / "e3-test.yaml").open("w") as f:
51+
yaml.dump({"main": "run.py", **config}, f)
52+
53+
54+
def test_root_dir(caplog, tmp_path):
55+
"""Check root directory computation for e3-test."""
56+
setup_testsuite(tmp_path)
57+
58+
# e3-tests is expected to run all tests present in the current working
59+
# directory as well as in its subdirectories.
60+
for cwd, *expected_results in [
61+
("tests/a", "a"),
62+
("tests/b", "b"),
63+
("tests/c", "c__0", "c__1", "c__2"),
64+
("tests/c/0", "c__0"),
65+
("tests/c/1", "c__1"),
66+
("tests/c/2", "c__2"),
67+
]:
68+
with chdir(tmp_path / cwd):
69+
assert main() == 0
70+
check_result_dirs(
71+
new={t: Status.PASS for t in expected_results},
72+
new_dir=str(tmp_path / "out" / "new"),
73+
)
74+
75+
76+
def test_default_args(caplog, tmp_path):
77+
"""Check handling for the default_args entry in e3-test.yaml."""
78+
setup_testsuite(tmp_path, default_args=["-o", "my_results"])
79+
with chdir(tmp_path / "tests" / "b"):
80+
assert main() == 0
81+
check_result_dirs(
82+
new={"b": Status.PASS},
83+
new_dir=str(tmp_path / "my_results" / "new"),
84+
)
85+
86+
87+
def test_invalid_e3_test_yaml(caplog, tmp_path):
88+
"""Check validation code for missing/incorrect e3-test.yaml files."""
89+
90+
def check_errors(messages):
91+
assert main() == 1
92+
assert [
93+
r.getMessage() for r in caplog.records if r.levelname == "ERROR"
94+
] == messages
95+
caplog.clear()
96+
97+
with chdir(tmp_path):
98+
# Missing e3-test.yaml
99+
check_errors(["cannot find e3-test.yaml"])
100+
101+
# Missing "main" entry
102+
with (tmp_path / "e3-test.yaml").open("w") as f:
103+
yaml.dump({"dummy": None}, f)
104+
105+
check_errors(["cannot find testsuite main"])

0 commit comments

Comments
 (0)