Files
IfcOpenShell/src/ifcopenshell-python/test/test_rules.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.1 KiB
Python
Raw Normal View History

2022-12-26 11:29:32 +01:00
import os
import sys
import glob
import pytest
import tabulate
import ifcopenshell.validate
2022-12-26 11:29:32 +01:00
import ifcopenshell.express.rule_executor
@pytest.mark.parametrize(
"filename",
[fn for fn in glob.glob(os.path.join(os.path.dirname(__file__), "fixtures/rules/*.ifc")) if len(sys.argv) < 2 or sys.argv[1] in os.path.basename(fn)],
)
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:
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()
))
if base.startswith("fail-"):
assert len(results) > 0
if base.startswith("pass-"):
assert len(results) == 0
if __name__ == "__main__":
pytest.main(["-sx", __file__])