mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 21:42:19 +00:00
validate fixtures: validate expected error count
This commit is contained in:
+5
-3
@@ -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}"
|
prefix = "fail" if expected_count == 1 else f"fail-expected-{expected_count}"
|
||||||
case _:
|
case _:
|
||||||
prefix = result
|
prefix = result
|
||||||
Path(f"{prefix}-{stem}.ifc").write_text(content)
|
(Path(source).parent / f"{prefix}-{stem}.ifc").write_text(content)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
directory = Path(__file__).parent
|
root = Path(__file__).parent.parent
|
||||||
|
directory = Path(__file__).parent / "fixtures/rules"
|
||||||
|
|
||||||
for path in directory.glob("*.ifc"):
|
for path in directory.glob("*.ifc"):
|
||||||
path.unlink()
|
path.unlink()
|
||||||
|
|
||||||
for path in sorted(directory.glob("generate_*.py")):
|
for path in sorted(directory.glob("generate_*.py")):
|
||||||
|
module = f"test.fixtures.rules.{path.stem}"
|
||||||
print(f"=== {path.name} ===")
|
print(f"=== {path.name} ===")
|
||||||
subprocess.run([sys.executable, str(path)], cwd=directory, check=True)
|
subprocess.run([sys.executable, "-m", module], cwd=root, check=True)
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import ifcopenshell
|
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):
|
for i in range(3):
|
||||||
f = ifcopenshell.file(schema="IFC2X3")
|
f = ifcopenshell.file(schema="IFC2X3")
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell
|
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"]):
|
for i, box_alignment in enumerate(["top-left", "center", "invalid", "CENTER"]):
|
||||||
f = ifcopenshell.file(schema="IFC2X3")
|
f = ifcopenshell.file(schema="IFC2X3")
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
from generate import normalize_header, pass_if, write_fixture
|
from ...fixture_generate import normalize_header, pass_if, write_fixture
|
||||||
|
|
||||||
latitudes = [
|
latitudes = [
|
||||||
(False, (-361, 0, 0), 1),
|
(False, (-361, 0, 0), 1),
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell
|
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):
|
for depth in (-1.0, 0.0, 1.0):
|
||||||
f = ifcopenshell.file(schema="IFC2X3")
|
f = ifcopenshell.file(schema="IFC2X3")
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell
|
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(
|
for i, (r1, r2) in enumerate(
|
||||||
[("SUPPLIER", None), ("SUPPLIER", "Valid"), ("USERDEFINED", "Valid"), ("USERDEFINED", None)]
|
[("SUPPLIER", None), ("SUPPLIER", "Valid"), ("USERDEFINED", "Valid"), ("USERDEFINED", None)]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
from generate import normalize_header, pass_if, write_fixture
|
from ...fixture_generate import normalize_header, pass_if, write_fixture
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
"IfcPostalAddress": ({}, {"Country": "The Netherlands"}, {"Country": "The Netherlands", "Town": "Eindhoven"}),
|
"IfcPostalAddress": ({}, {"Country": "The Netherlands"}, {"Country": "The Netherlands", "Town": "Eindhoven"}),
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import itertools
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import ifcopenshell
|
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")):
|
for pty, ety in itertools.product(("GRILLE", "USERDEFINED"), (None, "Something")):
|
||||||
f = ifcopenshell.file(schema="IFC2X3")
|
f = ifcopenshell.file(schema="IFC2X3")
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell
|
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_none = lambda f: None
|
||||||
create_polyline = lambda f: f.createIfcPolyline(
|
create_polyline = lambda f: f.createIfcPolyline(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell
|
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_plane = lambda f: f.createIfcPlane(f.createIfcAxis2Placement3D(f.createIfcCartesianPoint((0.0, 0.0, 0.0))))
|
||||||
create_polyline = lambda f: f.createIfcPolyline(
|
create_polyline = lambda f: f.createIfcPolyline(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell
|
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)]
|
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)]
|
dims = [(2, 3, 3), (3, 3, 2), (2, 2, 2), (3, 3, 3)]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
import ifcopenshell
|
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}
|
defaults = {"Girth": 1.0, "WallThickness": 0.11}
|
||||||
depths = [2.0, 3.0]
|
depths = [2.0, 3.0]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.util.schema
|
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
|
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)):
|
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)):
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell
|
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)]
|
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]
|
make_3d = lambda cs: [c + (0.0,) for c in cs]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell
|
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)]
|
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]
|
make_3d = lambda cs: [c + (0.0,) for c in cs]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
from generate import normalize_header, pass_if, write_fixture
|
from ...fixture_generate import normalize_header, pass_if, write_fixture
|
||||||
|
|
||||||
dims = [
|
dims = [
|
||||||
(1, 0, 0, 0, 0, 0, 0),
|
(1, 0, 0, 0, 0, 0, 0),
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell
|
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 = [(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)]
|
coords_2 = [(0.0, 0.0), (10.0, 0.0), (10.0, 10.0), (0.0, 10.0)]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import ifcopenshell
|
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")]
|
names = [("Same", "Same"), ("Different", "SomethingElse")]
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import ifcopenshell
|
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")):
|
for i, nm in enumerate(("no-mls", "mls", "mlsu")):
|
||||||
f = ifcopenshell.file(schema="IFC2X3")
|
f = ifcopenshell.file(schema="IFC2X3")
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell
|
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")):
|
for i, type_decl in enumerate(("IfcLengthMeasure", "IfcPlaneAngleMeasure")):
|
||||||
f = ifcopenshell.file(schema="IFC4X3")
|
f = ifcopenshell.file(schema="IFC4X3")
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell
|
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
|
make_nd = lambda d: lambda *c: (c + (0.0,)) if d == 3 else c
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell
|
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)
|
task = lambda f: f.createIfcTask(ifcopenshell.guid.new(), None, "sleep", IsMilestone=True)
|
||||||
wall = lambda f: f.createIfcWall(ifcopenshell.guid.new())
|
wall = lambda f: f.createIfcWall(ifcopenshell.guid.new())
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
from generate import normalize_header, pass_if, write_fixture
|
from ...fixture_generate import normalize_header, pass_if, write_fixture
|
||||||
|
|
||||||
|
|
||||||
def EXISTS(v):
|
def EXISTS(v):
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell
|
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):
|
for cnt in range(0, 3):
|
||||||
f = ifcopenshell.file(schema="IFC4")
|
f = ifcopenshell.file(schema="IFC4")
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
from generate import normalize_header, pass_if, write_fixture
|
from ...fixture_generate import normalize_header, pass_if, write_fixture
|
||||||
|
|
||||||
fns = [
|
fns = [
|
||||||
(False, lambda f: f.createIfcLengthMeasure(-1.0)),
|
(False, lambda f: f.createIfcLengthMeasure(-1.0)),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
from generate import normalize_header, pass_if, write_fixture
|
from ...fixture_generate import normalize_header, pass_if, write_fixture
|
||||||
|
|
||||||
for ents in [
|
for ents in [
|
||||||
("IfcWall",),
|
("IfcWall",),
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
from generate import fail_if, normalize_header, write_fixture
|
from ...fixture_generate import fail_if, normalize_header, write_fixture
|
||||||
|
|
||||||
segs = [
|
segs = [
|
||||||
lambda _: None,
|
lambda _: None,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
from generate import normalize_header, write_fixture
|
from ...fixture_generate import normalize_header, write_fixture
|
||||||
|
|
||||||
cases = (
|
cases = (
|
||||||
("pass", "label-values", ("test1", "test2")),
|
("pass", "label-values", ("test1", "test2")),
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell
|
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 = ifcopenshell.file(schema="IFC2X3")
|
||||||
ifc_file.create_entity(
|
ifc_file.create_entity(
|
||||||
|
|||||||
+2
@@ -5,7 +5,9 @@ FILE_NAME('','2022-10-01T16:31:47',(''),(''),'IfcOpenShell 0.7.0','IfcOpenShell
|
|||||||
FILE_SCHEMA(('IFC4'));
|
FILE_SCHEMA(('IFC4'));
|
||||||
ENDSEC;
|
ENDSEC;
|
||||||
DATA;
|
DATA;
|
||||||
|
/* Non-existent entity. */
|
||||||
#1=IFCBUILTELEMENT('2CbOYFeCHBku9$oytmyQ2e',$,$,$,$,$,$,$);
|
#1=IFCBUILTELEMENT('2CbOYFeCHBku9$oytmyQ2e',$,$,$,$,$,$,$);
|
||||||
|
/* Non-existsent entity used as part of an attribute. */
|
||||||
#2=IFCRELASSOCIATESMATERIAL('0e6aLxV9b8OvwguVdjzRsn',$,$,$,(#1),#3);
|
#2=IFCRELASSOCIATESMATERIAL('0e6aLxV9b8OvwguVdjzRsn',$,$,$,(#1),#3);
|
||||||
#3=IFCMATERIAL('brick',$,$);
|
#3=IFCMATERIAL('brick',$,$);
|
||||||
ENDSEC;
|
ENDSEC;
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.api.owner
|
import ifcopenshell.api.owner
|
||||||
import ifcopenshell.api.root
|
import ifcopenshell.api.root
|
||||||
|
from ...fixture_generate import normalize_header, pass_if, write_fixture
|
||||||
|
|
||||||
guid1 = "3pdqyORIn8KBHZAhhtJ72T"
|
guid1 = "3pdqyORIn8KBHZAhhtJ72T"
|
||||||
guid2 = "1sEzC8v31DshmvW5t5P631"
|
guid2 = "1sEzC8v31DshmvW5t5P631"
|
||||||
@@ -23,5 +22,5 @@ for schema in ("IFC2X3", "IFC4", "IFC4X3"):
|
|||||||
wall1.GlobalId = guid1
|
wall1.GlobalId = guid1
|
||||||
wall2.GlobalId = guid1 if status == "fail" else guid2
|
wall2.GlobalId = guid1 if status == "fail" else guid2
|
||||||
|
|
||||||
filename = f"{status}-{'not-' if status == 'pass' else ''}duplicated-guids-{schema.lower()}.ifc"
|
normalize_header(f)
|
||||||
f.write(Path(__file__).parent / filename)
|
write_fixture(f, __file__, pass_if(status == "pass"), f"duplicated-guids-{schema.lower()}")
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import tabulate
|
|||||||
|
|
||||||
import ifcopenshell.express.rule_executor
|
import ifcopenshell.express.rule_executor
|
||||||
import ifcopenshell.validate
|
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:
|
def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
|
||||||
|
|||||||
@@ -16,29 +16,50 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import glob
|
from pathlib import Path
|
||||||
import os
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
import tabulate
|
||||||
|
|
||||||
import ifcopenshell.validate
|
import ifcopenshell.validate
|
||||||
|
from .fixture_generate import FailObj, Result, parse_result
|
||||||
|
|
||||||
|
_filepaths = list((Path(__file__).parent / "fixtures/validate").glob("*.ifc"))
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"file",
|
"filepath,expected_result",
|
||||||
glob.glob(os.path.join(os.path.dirname(__file__), "fixtures/validate/*.ifc")),
|
[(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()
|
logger = ifcopenshell.validate.json_logger()
|
||||||
try:
|
try:
|
||||||
ifcopenshell.validate.validate(file, logger)
|
ifcopenshell.validate.validate(filepath, logger)
|
||||||
except ifcopenshell.SchemaError as e:
|
except ifcopenshell.SchemaError:
|
||||||
pytest.skip()
|
pytest.skip()
|
||||||
file = os.path.basename(file)
|
results = logger.statements
|
||||||
if file.startswith("fail-"):
|
|
||||||
assert len(logger.statements) > 0
|
print()
|
||||||
if file.startswith("pass-"):
|
print(filepath.name)
|
||||||
assert len(logger.statements) == 0
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user