From 931fd9cc9f1655bf5ab76d07c690d8df41b77b3a Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 28 Feb 2024 15:10:49 +0500 Subject: [PATCH] reassign_class - cover with tests --- .../test/api/root/test_reassign_class.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/ifcopenshell-python/test/api/root/test_reassign_class.py b/src/ifcopenshell-python/test/api/root/test_reassign_class.py index 3049b4cd3b..fc9a7f4b2b 100644 --- a/src/ifcopenshell-python/test/api/root/test_reassign_class.py +++ b/src/ifcopenshell-python/test/api/root/test_reassign_class.py @@ -50,3 +50,45 @@ class TestReassignClass(test.bootstrap.IFC4): ) assert new.PredefinedType == "USERDEFINED" assert new.ElementType == "FOO" + + def test_reassign_class_for_type_occurrences(self): + element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType") + element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + ifcopenshell.api.run("type.assign_type", self.file, related_object=element1, relating_type=element_type) + element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + ifcopenshell.api.run("type.assign_type", self.file, related_object=element2, relating_type=element_type) + + element_type = ifcopenshell.api.run( + "root.reassign_class", self.file, product=element_type, ifc_class="IfcSlabType" + ) + + # type occurrences have reassigned classes + occurrences = ifcopenshell.util.element.get_types(element_type) + assert len(occurrences) == 2 + assert all(o.is_a("IfcSlab") for o in occurrences) + + # original clases are gone + assert len(self.file.by_type("IfcWall")) == 0 + assert len(self.file.by_type("IfcWallType")) == 0 + + def test_reassigning_type_class_and_its_occurrences_classes_if_entity_was_typed(self): + element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType") + element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + ifcopenshell.api.run("type.assign_type", self.file, related_object=element1, relating_type=element_type) + element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + ifcopenshell.api.run("type.assign_type", self.file, related_object=element2, relating_type=element_type) + + element1 = ifcopenshell.api.run("root.reassign_class", self.file, product=element1, ifc_class="IfcSlab") + + # occurrence type has reassigned class + element_type = ifcopenshell.util.element.get_type(element1) + assert element_type.is_a("IfcSlabType") + + # other type occurrences have reassigned classes + occurrences = ifcopenshell.util.element.get_types(element_type) + assert len(occurrences) == 2 + assert all(o.is_a("IfcSlab") for o in occurrences) + + # original clases are gone + assert len(self.file.by_type("IfcWall")) == 0 + assert len(self.file.by_type("IfcWallType")) == 0