Skip to content

Commit

Permalink
#8 Validate project aggregation and final segment length using bespok…
Browse files Browse the repository at this point in the history
…e tests
  • Loading branch information
aothms committed Sep 5, 2023
1 parent ed62691 commit 6161fd5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/alignment_tests.py
Original file line number Diff line number Diff line change
@@ -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__])
4 changes: 4 additions & 0 deletions validate.sh
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

0 comments on commit 6161fd5

Please sign in to comment.