-
-
Notifications
You must be signed in to change notification settings - Fork 964
Expand file tree
/
Copy pathtest_rules.py
More file actions
53 lines (41 loc) · 1.49 KB
/
Copy pathtest_rules.py
File metadata and controls
53 lines (41 loc) · 1.49 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
from pathlib import Path
import pytest
import tabulate
import ifcopenshell.express.rule_executor
import ifcopenshell.validate
from .fixture_generate import FailObj, Result, parse_result
def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
if "filepath" not in metafunc.fixturenames:
return
rule = metafunc.config.getoption("--rule")
filepaths = [fp for fp in (Path(__file__).parent / "fixtures/rules").glob("*.ifc") if not rule or rule in fp.name]
metafunc.parametrize(
"filepath,expected_result",
[(fp, parse_result(fp)) for fp in filepaths],
ids=[fp.name for fp in filepaths],
)
def test_file(filepath: Path, expected_result: Result):
file = ifcopenshell.open(filepath)
logger = ifcopenshell.validate.json_logger()
ifcopenshell.express.rule_executor.run(file, logger)
results = logger.statements
print()
print(filepath.name)
print()
print(f"{len(results)} errors")
if results:
print(
tabulate.tabulate(
[[c or "" for c in r.values()] for r in results],
maxcolwidths=[20, 100, 20],
tablefmt="simple_grid",
headers=results[0].keys(),
)
)
match expected_result:
case FailObj(expected_count=expected_count):
assert len(results) == expected_count
case "pass":
assert len(results) == 0
if __name__ == "__main__":
pytest.main(["-sx", __file__, "--import-mode=importlib"])