diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate.py b/src/ifcopenshell-python/test/fixture_generate.py similarity index 86% rename from src/ifcopenshell-python/test/fixtures/rules/generate.py rename to src/ifcopenshell-python/test/fixture_generate.py index 51f9b04ad5..cefb2a7ace 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate.py +++ b/src/ifcopenshell-python/test/fixture_generate.py @@ -52,15 +52,17 @@ def write_fixture(file: ifcopenshell.file, source: str, result: Result, stem: st prefix = "fail" if expected_count == 1 else f"fail-expected-{expected_count}" case _: prefix = result - Path(f"{prefix}-{stem}.ifc").write_text(content) + (Path(source).parent / f"{prefix}-{stem}.ifc").write_text(content) if __name__ == "__main__": - directory = Path(__file__).parent + root = Path(__file__).parent.parent + directory = Path(__file__).parent / "fixtures/rules" for path in directory.glob("*.ifc"): path.unlink() for path in sorted(directory.glob("generate_*.py")): + module = f"test.fixtures.rules.{path.stem}" print(f"=== {path.name} ===") - subprocess.run([sys.executable, str(path)], cwd=directory, check=True) + subprocess.run([sys.executable, "-m", module], cwd=root, check=True) diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_00.py b/src/ifcopenshell-python/test/fixtures/rules/generate_00.py index b5937af566..2460a2cd37 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_00.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_00.py @@ -1,7 +1,7 @@ import time import ifcopenshell -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture for i in range(3): f = ifcopenshell.file(schema="IFC2X3") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_01.py b/src/ifcopenshell-python/test/fixtures/rules/generate_01.py index 2da9bc1273..b3dc34408a 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_01.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_01.py @@ -1,5 +1,5 @@ import ifcopenshell -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture for i, box_alignment in enumerate(["top-left", "center", "invalid", "CENTER"]): f = ifcopenshell.file(schema="IFC2X3") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_02.py b/src/ifcopenshell-python/test/fixtures/rules/generate_02.py index b45c40ba45..f4f9ebd4f4 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_02.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_02.py @@ -1,7 +1,7 @@ import time import ifcopenshell -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture latitudes = [ (False, (-361, 0, 0), 1), diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_03.py b/src/ifcopenshell-python/test/fixtures/rules/generate_03.py index 85f0ec45d2..4ce7e50f95 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_03.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_03.py @@ -1,5 +1,5 @@ import ifcopenshell -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture for depth in (-1.0, 0.0, 1.0): f = ifcopenshell.file(schema="IFC2X3") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_04.py b/src/ifcopenshell-python/test/fixtures/rules/generate_04.py index 66e74f0064..2f64e38fa2 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_04.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_04.py @@ -1,5 +1,5 @@ import ifcopenshell -from generate import fail_if, normalize_header, write_fixture +from ...fixture_generate import fail_if, normalize_header, write_fixture for i, (r1, r2) in enumerate( [("SUPPLIER", None), ("SUPPLIER", "Valid"), ("USERDEFINED", "Valid"), ("USERDEFINED", None)] diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_05.py b/src/ifcopenshell-python/test/fixtures/rules/generate_05.py index 72fd359d34..ad6ebcdb2f 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_05.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_05.py @@ -1,5 +1,5 @@ import ifcopenshell -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture options = { "IfcPostalAddress": ({}, {"Country": "The Netherlands"}, {"Country": "The Netherlands", "Town": "Eindhoven"}), diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_06.py b/src/ifcopenshell-python/test/fixtures/rules/generate_06.py index 8676912048..718ce10bc2 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_06.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_06.py @@ -2,7 +2,7 @@ import itertools import time import ifcopenshell -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture for pty, ety in itertools.product(("GRILLE", "USERDEFINED"), (None, "Something")): f = ifcopenshell.file(schema="IFC2X3") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_07.py b/src/ifcopenshell-python/test/fixtures/rules/generate_07.py index 9dc2b109bd..02d19de3c5 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_07.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_07.py @@ -1,5 +1,5 @@ import ifcopenshell -from generate import fail_if, normalize_header, write_fixture +from ...fixture_generate import fail_if, normalize_header, write_fixture create_none = lambda f: None create_polyline = lambda f: f.createIfcPolyline( diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_08.py b/src/ifcopenshell-python/test/fixtures/rules/generate_08.py index 33984c0192..9e2f935c47 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_08.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_08.py @@ -1,5 +1,5 @@ import ifcopenshell -from generate import fail_if, normalize_header, write_fixture +from ...fixture_generate import fail_if, normalize_header, write_fixture create_plane = lambda f: f.createIfcPlane(f.createIfcAxis2Placement3D(f.createIfcCartesianPoint((0.0, 0.0, 0.0)))) create_polyline = lambda f: f.createIfcPolyline( diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_09.py b/src/ifcopenshell-python/test/fixtures/rules/generate_09.py index 44c2eb7adf..6a98196102 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_09.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_09.py @@ -1,5 +1,5 @@ import ifcopenshell -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture pts = [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0)] dims = [(2, 3, 3), (3, 3, 2), (2, 2, 2), (3, 3, 3)] diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_10.py b/src/ifcopenshell-python/test/fixtures/rules/generate_10.py index 6ced635ee0..b2cfdfca7d 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_10.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_10.py @@ -1,7 +1,7 @@ import itertools import ifcopenshell -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture defaults = {"Girth": 1.0, "WallThickness": 0.11} depths = [2.0, 3.0] diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_11.py b/src/ifcopenshell-python/test/fixtures/rules/generate_11.py index f9059f03d5..37768412fd 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_11.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_11.py @@ -1,6 +1,6 @@ import ifcopenshell import ifcopenshell.util.schema -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture depth = 1.0 for dir_x, dir_z in ((0.0, -1.0), (0.0, 0.0), (1.0, 0.0), (1.0, 0.001), (0.0, 1.0)): diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_12.py b/src/ifcopenshell-python/test/fixtures/rules/generate_12.py index a2f1931b95..77136e803b 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_12.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_12.py @@ -1,5 +1,5 @@ import ifcopenshell -from generate import normalize_header, write_fixture +from ...fixture_generate import normalize_header, write_fixture coords = [(0.0, 0.0), (10.0, 0.0), (10.0, 10.0), (0.0, 10.0)] make_3d = lambda cs: [c + (0.0,) for c in cs] diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_13.py b/src/ifcopenshell-python/test/fixtures/rules/generate_13.py index a4d5b21ac6..200ffcf2cf 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_13.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_13.py @@ -1,5 +1,5 @@ import ifcopenshell -from generate import normalize_header, write_fixture +from ...fixture_generate import normalize_header, write_fixture coords = [(0.0, 0.0), (10.0, 0.0), (10.0, 10.0), (0.0, 10.0)] make_3d = lambda cs: [c + (0.0,) for c in cs] diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_14.py b/src/ifcopenshell-python/test/fixtures/rules/generate_14.py index 9c263da807..1d82f570fd 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_14.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_14.py @@ -1,5 +1,5 @@ import ifcopenshell -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture dims = [ (1, 0, 0, 0, 0, 0, 0), diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_15.py b/src/ifcopenshell-python/test/fixtures/rules/generate_15.py index 591d4648b0..3bb91bab55 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_15.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_15.py @@ -1,5 +1,5 @@ import ifcopenshell -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture coords = [(0.0, 0.0), (10.0, 0.0)] coords_2 = [(0.0, 0.0), (10.0, 0.0), (10.0, 10.0), (0.0, 10.0)] diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_16.py b/src/ifcopenshell-python/test/fixtures/rules/generate_16.py index 84bdfe51eb..a22ec7163e 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_16.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_16.py @@ -1,7 +1,7 @@ import time import ifcopenshell -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture names = [("Same", "Same"), ("Different", "SomethingElse")] diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_17.py b/src/ifcopenshell-python/test/fixtures/rules/generate_17.py index 9d831ace37..d67799cd1d 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_17.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_17.py @@ -1,7 +1,7 @@ import time import ifcopenshell -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture for i, nm in enumerate(("no-mls", "mls", "mlsu")): f = ifcopenshell.file(schema="IFC2X3") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_18.py b/src/ifcopenshell-python/test/fixtures/rules/generate_18.py index 87c3f05018..637e1dbbd1 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_18.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_18.py @@ -1,5 +1,5 @@ import ifcopenshell -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture for i, type_decl in enumerate(("IfcLengthMeasure", "IfcPlaneAngleMeasure")): f = ifcopenshell.file(schema="IFC4X3") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_19.py b/src/ifcopenshell-python/test/fixtures/rules/generate_19.py index 9812b5f92a..327e0da7fb 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_19.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_19.py @@ -1,5 +1,5 @@ import ifcopenshell -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture make_nd = lambda d: lambda *c: (c + (0.0,)) if d == 3 else c diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_20.py b/src/ifcopenshell-python/test/fixtures/rules/generate_20.py index 68d3364ae2..2c0ac7bd8f 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_20.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_20.py @@ -1,5 +1,5 @@ import ifcopenshell -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture task = lambda f: f.createIfcTask(ifcopenshell.guid.new(), None, "sleep", IsMilestone=True) wall = lambda f: f.createIfcWall(ifcopenshell.guid.new()) diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_21.py b/src/ifcopenshell-python/test/fixtures/rules/generate_21.py index 232c0e75d6..8e87988546 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_21.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_21.py @@ -1,7 +1,7 @@ import itertools import ifcopenshell -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture def EXISTS(v): diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_22.py b/src/ifcopenshell-python/test/fixtures/rules/generate_22.py index 535a03b083..800e0e2a46 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_22.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_22.py @@ -1,5 +1,5 @@ import ifcopenshell -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture for cnt in range(0, 3): f = ifcopenshell.file(schema="IFC4") diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_23.py b/src/ifcopenshell-python/test/fixtures/rules/generate_23.py index 08303191b4..a415f32fa6 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_23.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_23.py @@ -1,5 +1,5 @@ import ifcopenshell -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture fns = [ (False, lambda f: f.createIfcLengthMeasure(-1.0)), diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_24.py b/src/ifcopenshell-python/test/fixtures/rules/generate_24.py index 56696a4660..022762512b 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_24.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_24.py @@ -1,7 +1,7 @@ import time import ifcopenshell -from generate import normalize_header, pass_if, write_fixture +from ...fixture_generate import normalize_header, pass_if, write_fixture for ents in [ ("IfcWall",), diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_25.py b/src/ifcopenshell-python/test/fixtures/rules/generate_25.py index 765c1effe7..9901a83635 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_25.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_25.py @@ -1,5 +1,5 @@ import ifcopenshell -from generate import fail_if, normalize_header, write_fixture +from ...fixture_generate import fail_if, normalize_header, write_fixture segs = [ lambda _: None, diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_26.py b/src/ifcopenshell-python/test/fixtures/rules/generate_26.py index 4f373bcb7c..1154bad08a 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_26.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_26.py @@ -1,5 +1,5 @@ import ifcopenshell -from generate import normalize_header, write_fixture +from ...fixture_generate import normalize_header, write_fixture cases = ( ("pass", "label-values", ("test1", "test2")), diff --git a/src/ifcopenshell-python/test/fixtures/rules/generate_27.py b/src/ifcopenshell-python/test/fixtures/rules/generate_27.py index 91d9248ca6..b82c078a29 100644 --- a/src/ifcopenshell-python/test/fixtures/rules/generate_27.py +++ b/src/ifcopenshell-python/test/fixtures/rules/generate_27.py @@ -1,5 +1,5 @@ import ifcopenshell -from generate import normalize_header, write_fixture +from ...fixture_generate import normalize_header, write_fixture ifc_file = ifcopenshell.file(schema="IFC2X3") ifc_file.create_entity( diff --git a/src/ifcopenshell-python/test/fixtures/validate/fail-header-attr-too-few.ifc b/src/ifcopenshell-python/test/fixtures/validate/fail-expected-2-header-attr-too-few.ifc similarity index 100% rename from src/ifcopenshell-python/test/fixtures/validate/fail-header-attr-too-few.ifc rename to src/ifcopenshell-python/test/fixtures/validate/fail-expected-2-header-attr-too-few.ifc diff --git a/src/ifcopenshell-python/test/fixtures/validate/fail-invalid-selected-enumeration.ifc b/src/ifcopenshell-python/test/fixtures/validate/fail-expected-2-invalid-selected-enumeration.ifc similarity index 100% rename from src/ifcopenshell-python/test/fixtures/validate/fail-invalid-selected-enumeration.ifc rename to src/ifcopenshell-python/test/fixtures/validate/fail-expected-2-invalid-selected-enumeration.ifc diff --git a/src/ifcopenshell-python/test/fixtures/validate/fail-selected-simple-type-empty-typed-value.ifc b/src/ifcopenshell-python/test/fixtures/validate/fail-expected-2-selected-simple-type-empty-typed-value.ifc similarity index 100% rename from src/ifcopenshell-python/test/fixtures/validate/fail-selected-simple-type-empty-typed-value.ifc rename to src/ifcopenshell-python/test/fixtures/validate/fail-expected-2-selected-simple-type-empty-typed-value.ifc diff --git a/src/ifcopenshell-python/test/fixtures/validate/fail-selected-simple-type-non-existant-type.ifc b/src/ifcopenshell-python/test/fixtures/validate/fail-expected-2-selected-simple-type-non-existant-type.ifc similarity index 100% rename from src/ifcopenshell-python/test/fixtures/validate/fail-selected-simple-type-non-existant-type.ifc rename to src/ifcopenshell-python/test/fixtures/validate/fail-expected-2-selected-simple-type-non-existant-type.ifc diff --git a/src/ifcopenshell-python/test/fixtures/validate/fail-invalid-entity.ifc b/src/ifcopenshell-python/test/fixtures/validate/fail-expected-3-invalid-entity.ifc similarity index 82% rename from src/ifcopenshell-python/test/fixtures/validate/fail-invalid-entity.ifc rename to src/ifcopenshell-python/test/fixtures/validate/fail-expected-3-invalid-entity.ifc index b6367d784d..599a3c41c4 100644 --- a/src/ifcopenshell-python/test/fixtures/validate/fail-invalid-entity.ifc +++ b/src/ifcopenshell-python/test/fixtures/validate/fail-expected-3-invalid-entity.ifc @@ -5,7 +5,9 @@ FILE_NAME('','2022-10-01T16:31:47',(''),(''),'IfcOpenShell 0.7.0','IfcOpenShell FILE_SCHEMA(('IFC4')); ENDSEC; DATA; +/* Non-existent entity. */ #1=IFCBUILTELEMENT('2CbOYFeCHBku9$oytmyQ2e',$,$,$,$,$,$,$); +/* Non-existsent entity used as part of an attribute. */ #2=IFCRELASSOCIATESMATERIAL('0e6aLxV9b8OvwguVdjzRsn',$,$,$,(#1),#3); #3=IFCMATERIAL('brick',$,$); ENDSEC; diff --git a/src/ifcopenshell-python/test/fixtures/validate/generate_00.py b/src/ifcopenshell-python/test/fixtures/validate/generate_00.py index 372c25a65b..5b0e363b3e 100644 --- a/src/ifcopenshell-python/test/fixtures/validate/generate_00.py +++ b/src/ifcopenshell-python/test/fixtures/validate/generate_00.py @@ -1,8 +1,7 @@ -from pathlib import Path - import ifcopenshell import ifcopenshell.api.owner import ifcopenshell.api.root +from ...fixture_generate import normalize_header, pass_if, write_fixture guid1 = "3pdqyORIn8KBHZAhhtJ72T" guid2 = "1sEzC8v31DshmvW5t5P631" @@ -23,5 +22,5 @@ for schema in ("IFC2X3", "IFC4", "IFC4X3"): wall1.GlobalId = guid1 wall2.GlobalId = guid1 if status == "fail" else guid2 - filename = f"{status}-{'not-' if status == 'pass' else ''}duplicated-guids-{schema.lower()}.ifc" - f.write(Path(__file__).parent / filename) + normalize_header(f) + write_fixture(f, __file__, pass_if(status == "pass"), f"duplicated-guids-{schema.lower()}") diff --git a/src/ifcopenshell-python/test/fixtures/validate/pass-not-duplicated-guids-ifc2x3.ifc b/src/ifcopenshell-python/test/fixtures/validate/pass-duplicated-guids-ifc2x3.ifc similarity index 100% rename from src/ifcopenshell-python/test/fixtures/validate/pass-not-duplicated-guids-ifc2x3.ifc rename to src/ifcopenshell-python/test/fixtures/validate/pass-duplicated-guids-ifc2x3.ifc diff --git a/src/ifcopenshell-python/test/fixtures/validate/pass-not-duplicated-guids-ifc4.ifc b/src/ifcopenshell-python/test/fixtures/validate/pass-duplicated-guids-ifc4.ifc similarity index 100% rename from src/ifcopenshell-python/test/fixtures/validate/pass-not-duplicated-guids-ifc4.ifc rename to src/ifcopenshell-python/test/fixtures/validate/pass-duplicated-guids-ifc4.ifc diff --git a/src/ifcopenshell-python/test/fixtures/validate/pass-not-duplicated-guids-ifc4x3.ifc b/src/ifcopenshell-python/test/fixtures/validate/pass-duplicated-guids-ifc4x3.ifc similarity index 100% rename from src/ifcopenshell-python/test/fixtures/validate/pass-not-duplicated-guids-ifc4x3.ifc rename to src/ifcopenshell-python/test/fixtures/validate/pass-duplicated-guids-ifc4x3.ifc diff --git a/src/ifcopenshell-python/test/test_rules.py b/src/ifcopenshell-python/test/test_rules.py index 3596d9b4a7..7bb12dd211 100644 --- a/src/ifcopenshell-python/test/test_rules.py +++ b/src/ifcopenshell-python/test/test_rules.py @@ -5,7 +5,7 @@ import tabulate import ifcopenshell.express.rule_executor import ifcopenshell.validate -from .fixtures.rules.generate import FailObj, Result, parse_result +from .fixture_generate import FailObj, Result, parse_result def pytest_generate_tests(metafunc: pytest.Metafunc) -> None: diff --git a/src/ifcopenshell-python/test/test_validate.py b/src/ifcopenshell-python/test/test_validate.py index d3eff78f33..4dd42a7a05 100644 --- a/src/ifcopenshell-python/test/test_validate.py +++ b/src/ifcopenshell-python/test/test_validate.py @@ -16,29 +16,50 @@ # You should have received a copy of the GNU Lesser General Public License # along with IfcOpenShell. If not, see . -import glob -import os +from pathlib import Path import pytest +import tabulate import ifcopenshell.validate +from .fixture_generate import FailObj, Result, parse_result + +_filepaths = list((Path(__file__).parent / "fixtures/validate").glob("*.ifc")) @pytest.mark.parametrize( - "file", - glob.glob(os.path.join(os.path.dirname(__file__), "fixtures/validate/*.ifc")), + "filepath,expected_result", + [(fp, parse_result(fp)) for fp in _filepaths], + ids=[fp.name for fp in _filepaths], ) -def test_file(file): +def test_file(filepath: Path, expected_result: Result): logger = ifcopenshell.validate.json_logger() try: - ifcopenshell.validate.validate(file, logger) - except ifcopenshell.SchemaError as e: + ifcopenshell.validate.validate(filepath, logger) + except ifcopenshell.SchemaError: pytest.skip() - file = os.path.basename(file) - if file.startswith("fail-"): - assert len(logger.statements) > 0 - if file.startswith("pass-"): - assert len(logger.statements) == 0 + 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__":