2025-12-19 18:53:04 +05:00
|
|
|
import glob
|
2022-12-26 11:29:32 +01:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
import tabulate
|
|
|
|
|
|
|
|
|
|
import ifcopenshell.express.rule_executor
|
2025-12-19 18:53:04 +05:00
|
|
|
import ifcopenshell.validate
|
2022-12-26 11:29:32 +01:00
|
|
|
|
2026-07-26 18:03:09 +10:00
|
|
|
|
2026-07-29 21:59:03 +03:00
|
|
|
def pytest_generate_tests(metafunc):
|
|
|
|
|
if "filename" not in metafunc.fixturenames:
|
|
|
|
|
return
|
|
|
|
|
rule = metafunc.config.getoption("--rule")
|
|
|
|
|
filenames = [
|
2024-07-26 12:00:28 +10:00
|
|
|
fn
|
|
|
|
|
for fn in glob.glob(os.path.join(os.path.dirname(__file__), "fixtures/rules/*.ifc"))
|
2026-07-29 21:59:03 +03:00
|
|
|
if not rule or rule in os.path.basename(fn)
|
|
|
|
|
]
|
|
|
|
|
metafunc.parametrize("filename", filenames, ids=[os.path.basename(fn) for fn in filenames])
|
|
|
|
|
|
|
|
|
|
|
2022-12-26 11:29:32 +01:00
|
|
|
def test_file(filename):
|
|
|
|
|
base = os.path.basename(filename)
|
|
|
|
|
file = ifcopenshell.open(filename)
|
|
|
|
|
logger = ifcopenshell.validate.json_logger()
|
|
|
|
|
ifcopenshell.express.rule_executor.run(file, logger)
|
|
|
|
|
results = logger.statements
|
|
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
print(base)
|
|
|
|
|
print()
|
|
|
|
|
print(f"{len(results)} errors")
|
|
|
|
|
|
|
|
|
|
if results:
|
2024-07-26 12:00:28 +10:00
|
|
|
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(),
|
|
|
|
|
)
|
|
|
|
|
)
|
2022-12-26 11:29:32 +01:00
|
|
|
|
|
|
|
|
if base.startswith("fail-"):
|
|
|
|
|
assert len(results) > 0
|
|
|
|
|
if base.startswith("pass-"):
|
|
|
|
|
assert len(results) == 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2026-07-26 18:03:09 +10:00
|
|
|
pytest.main(["-sx", __file__, "--import-mode=importlib"])
|