diff --git a/test/alignment_tests.py b/test/alignment_tests.py new file mode 100644 index 0000000..803acda --- /dev/null +++ b/test/alignment_tests.py @@ -0,0 +1,51 @@ +import os +import sys +import glob +import pytest +import ifcopenshell +import ifcopenshell.express + +schema_iden = sys.argv[-1] + +schema = ifcopenshell.express.parse(f"{schema_iden}.exp") +ifcopenshell.register_schema(schema) + +filenames = glob.glob( + os.path.join(os.path.dirname(__file__), "../models/**/*.ifc"), recursive=True +) +files = list(map(ifcopenshell.open, filenames)) +alignments = [f.by_type("IfcAlignment") for f in files] +pairs = [ + (os.path.basename(fn), al) for fn, als in zip(filenames, alignments) for al in als +] + + +@pytest.mark.parametrize("filename_alignment", pairs) +def test_alignment_final_segment_length(filename_alignment): + filename, alignment = filename_alignment + horizontal = alignment.IsNestedBy[0].RelatedObjects[0] + last_segment = horizontal.IsNestedBy[0].RelatedObjects[-1] + segment_length = last_segment.DesignParameters.SegmentLength + assert ( + segment_length == 0.0 + ), f"In {filename}, {alignment} has final segment length {segment_length}" + + +@pytest.mark.parametrize("filename_alignment", pairs) +def test_alignment_project_aggregation(filename_alignment): + filename, alignment = filename_alignment + while True: + try: + previous, alignment = alignment, alignment.Decomposes[0].RelatingObject + except IndexError: + alignment = None + if alignment and alignment.is_a("IfcProject"): + break + elif alignment and alignment.is_a("IfcAlignment"): + continue + else: + assert False, f"In {filename}, {previous} decomposes {alignment}" + + +if __name__ == "__main__": + pytest.main(["-sx", __file__]) diff --git a/validate.sh b/validate.sh index d50377d..ca6c7fe 100755 --- a/validate.sh +++ b/validate.sh @@ -1,3 +1,5 @@ +set -e + # obtain most recent express schema git clone --depth 1 https://github.com/buildingSMART/IFC4.3.x-output /tmp/IFC4.3.x-output @@ -22,3 +24,5 @@ find models -name '*.ifc' -exec perl -pi -e "s/(?<=FILE_SCHEMA \(\(')IFC\w+/$sch # validate models find models -name '*.ifc' -print0 | xargs -0 -n1 python ifc-pipeline-validation/application/validate.py + +python test/alignment_tests.py $schema_identifier