From c0f547c6e48d919f2c824df1371e3796da2a12cc Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 29 Nov 2021 20:14:50 +1100 Subject: [PATCH] Test expectations for new remove_deep2 proposal. See #1812. --- .../test/util/test_element.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/ifcopenshell-python/test/util/test_element.py b/src/ifcopenshell-python/test/util/test_element.py index c3434930ae..05ff96968c 100644 --- a/src/ifcopenshell-python/test/util/test_element.py +++ b/src/ifcopenshell-python/test/util/test_element.py @@ -359,6 +359,33 @@ class TestRemoveDeepIFC4(test.bootstrap.IFC4): assert self.file.by_guid("id2") +class TestRemoveDeep2IFC4(test.bootstrap.IFC4): + def test_removing_an_element_along_with_all_direct_attributes_recursively(self): + owner = self.file.createIfcOwnerHistory() + element = self.file.createIfcWall(GlobalId="id", OwnerHistory=owner) + subject.remove_deep2(self.file, element) + with pytest.raises(RuntimeError): + self.file.by_id(1) + self.file.by_id(2) + + def test_removing_an_element_recursively_except_if_an_element_is_referenced_elsewhere(self): + owner = self.file.createIfcOwnerHistory() + element = self.file.createIfcWall(GlobalId="id1", OwnerHistory=owner) + element2 = self.file.createIfcWall(GlobalId="id2", OwnerHistory=owner) + subject.remove_deep2(self.file, element) + with pytest.raises(RuntimeError): + self.file.by_guid("id1") + assert self.file.by_id(1) + assert self.file.by_guid("id2") + + def test_removing_an_element_still_referenced_somewhere(self): + owner = self.file.createIfcOwnerHistory() + element = self.file.createIfcWall(GlobalId="id1", OwnerHistory=owner) + subject.remove_deep2(self.file, owner) + assert self.file.by_id(1) + assert self.file.by_guid("id1") + + class TestCopyIFC4(test.bootstrap.IFC4): def test_copying_an_element(self): element = self.file.createIfcWall(GlobalId="id", Name="name")