From 74adde3030c73ee4c601d9fcf919da874b32ce83 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 27 Mar 2024 17:52:18 +0500 Subject: [PATCH] ExtractElemenets - add some tests --- src/ifcpatch/test/test_ExtractElements.py | 50 ++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/ifcpatch/test/test_ExtractElements.py b/src/ifcpatch/test/test_ExtractElements.py index 5878a9a32b..5cb2df1c46 100644 --- a/src/ifcpatch/test/test_ExtractElements.py +++ b/src/ifcpatch/test/test_ExtractElements.py @@ -20,11 +20,59 @@ import os import pytest import ifcpatch import ifcopenshell +import ifcopenshell.api +import ifcopenshell.util.element class TestExtractElements: + def test_basic(self): + ifc_file = ifcopenshell.file() + project = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcProject") + wall = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcWall") + output = ifcpatch.execute({"file": ifc_file, "recipe": "ExtractElements", "arguments": ["IfcWall"]}) + + assert output.by_type("IfcProject")[0].GlobalId == project.GlobalId + assert output.by_type("IfcWall")[0].GlobalId == wall.GlobalId + + def test_keep_spatial_structure(self): + ifc_file = ifcopenshell.file() + project = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcProject") + + site = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcSite") + building = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcBuilding") + storey = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcBuildingStorey") + wall = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcWall") + ifcopenshell.api.run("aggregate.assign_object", ifc_file, product=building, relating_object=site) + ifcopenshell.api.run("aggregate.assign_object", ifc_file, product=storey, relating_object=building) + ifcopenshell.api.run("spatial.assign_container", ifc_file, product=wall, relating_structure=storey) + + output = ifcpatch.execute({"file": ifc_file, "recipe": "ExtractElements", "arguments": ["IfcWall"]}) + + wall_new = output.by_type("IfcWall")[0] + assert (storey_new := ifcopenshell.util.element.get_container(wall_new)).GlobalId == storey.GlobalId + assert (building_new := ifcopenshell.util.element.get_aggregate(storey_new)).GlobalId == building.GlobalId + assert (site_new := ifcopenshell.util.element.get_aggregate(building_new)).GlobalId == site.GlobalId + + def test_keep_aggregate_in_spatial_structure(self): + ifc_file = ifcopenshell.file() + project = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcProject") + + element = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcElementAssembly") + container = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcBuildingStorey") + subelement = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcWall") + ifcopenshell.api.run("spatial.assign_container", ifc_file, product=element, relating_structure=container) + ifcopenshell.api.run("aggregate.assign_object", ifc_file, product=subelement, relating_object=element) + + output = ifcpatch.execute({"file": ifc_file, "recipe": "ExtractElements", "arguments": ["IfcWall"]}) + + wall_new = output.by_type("IfcWall")[0] + assembly = output.by_type("IfcElementAssembly")[0] + + assert ifcopenshell.util.element.get_aggregate(wall_new).GlobalId == element.GlobalId + assert ifcopenshell.util.element.get_container(assembly).GlobalId == container.GlobalId + def test_getting_the_psets_of_a_product_as_a_dictionary(self): ifc = ifcopenshell.open(os.path.join(os.getcwd(), "test", "files", "basic.ifc")) - output = ifcpatch.execute({"input": ifc, "recipe": "ExtractElements", "arguments": [".IfcWall"]}) + output = ifcpatch.execute({"file": ifc, "recipe": "ExtractElements", "arguments": ["IfcWall"]}) assert output.by_type("IfcWall") assert not output.by_type("IfcSlab")