diff --git a/src/ifcopenshell-python/ifcopenshell/api/spatial/remove_container.py b/src/ifcopenshell-python/ifcopenshell/api/spatial/remove_container.py index 2907fab1ff..b8417b3143 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/spatial/remove_container.py +++ b/src/ifcopenshell-python/ifcopenshell/api/spatial/remove_container.py @@ -55,9 +55,7 @@ class Usecase: ifcopenshell.api.run("spatial.remove_container", model, product=wall) """ self.file = file - self.settings = {"product": None} - for key, value in settings.items(): - self.settings[key] = value + self.settings = {"product": product} def execute(self): contained_in_structure = self.settings["product"].ContainedInStructure diff --git a/src/ifcopenshell-python/ifcopenshell/api/system/assign_system.py b/src/ifcopenshell-python/ifcopenshell/api/system/assign_system.py index 03f947987d..ad4786c030 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/system/assign_system.py +++ b/src/ifcopenshell-python/ifcopenshell/api/system/assign_system.py @@ -18,34 +18,7 @@ import ifcopenshell import ifcopenshell.api - - -ASSIGNABLE_DICT = { - "IfcZone": ("IfcZone", "IfcSpace", "IfcSpatialZone"), - "IfcBuiltSystem": ( - "IfcBuiltElement", - "IfcFurnishingElement", - "IfcElementAssembly", - "IfcTransportElement", - ), - "IfcBuildingSystem": ( - "IfcBuildingElement", - "IfcFurnishingElement", - "IfcElementAssembly", - "IfcTransportElement", - ), - "IfcDistributionSystem": ("IfcDistributionElement",), - "IfcStructuralAnalysisModel": ("IfcStructuralMember", "IfcStructuralConnection"), - "IfcSystem": ("IfcProduct",), - "IfcGroup": ("IfcObjectDefinition",), -} - - -def is_assignable(product, system) -> bool: - for assignable in ASSIGNABLE_DICT.get(system.is_a(), ()): - if product.is_a(assignable): - return True - return False +import ifcopenshell.util.system class Usecase: @@ -82,7 +55,7 @@ class Usecase: def execute(self): system = self.settings["system"] product = self.settings["product"] - if not is_assignable(product, system): + if not ifcopenshell.util.system.is_assignable(product, system): raise TypeError(f"You cannot assign an {product.is_a()} to an {system.is_a()}") if not self.settings["system"].IsGroupedBy: diff --git a/src/ifcopenshell-python/ifcopenshell/util/system.py b/src/ifcopenshell-python/ifcopenshell/util/system.py index 91dc441b32..630df515ef 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/system.py +++ b/src/ifcopenshell-python/ifcopenshell/util/system.py @@ -17,6 +17,34 @@ # along with IfcOpenShell. If not, see . +group_types = { + "IfcZone": ("IfcZone", "IfcSpace", "IfcSpatialZone"), + "IfcBuiltSystem": ( + "IfcBuiltElement", + "IfcFurnishingElement", + "IfcElementAssembly", + "IfcTransportElement", + ), + "IfcBuildingSystem": ( + "IfcBuildingElement", + "IfcFurnishingElement", + "IfcElementAssembly", + "IfcTransportElement", + ), + "IfcDistributionSystem": ("IfcDistributionElement",), + "IfcStructuralAnalysisModel": ("IfcStructuralMember", "IfcStructuralConnection"), + "IfcSystem": ("IfcProduct",), + "IfcGroup": ("IfcObjectDefinition",), +} + + +def is_assignable(product, system) -> bool: + for assignable in group_types.get(system.is_a(), ()): + if product.is_a(assignable): + return True + return False + + def get_system_elements(system): results = [] for rel in system.IsGroupedBy: diff --git a/src/ifcopenshell-python/test/api/unit/test_add_si_unit.py b/src/ifcopenshell-python/test/api/unit/test_add_si_unit.py index 124bf7fa40..8ebc7234ad 100644 --- a/src/ifcopenshell-python/test/api/unit/test_add_si_unit.py +++ b/src/ifcopenshell-python/test/api/unit/test_add_si_unit.py @@ -22,7 +22,7 @@ import ifcopenshell.api class TestAddSIUnit(test.bootstrap.IFC4): def test_run(self): - unit = ifcopenshell.api.run("unit.add_si_unit", self.file, unit_type="LENGTHUNIT", name="METRE", prefix="MILLI") + unit = ifcopenshell.api.run("unit.add_si_unit", self.file, unit_type="LENGTHUNIT", prefix="MILLI") assert unit.UnitType == "LENGTHUNIT" assert unit.Name == "METRE" assert unit.Prefix == "MILLI" diff --git a/src/ifcopenshell-python/test/test_rules.py b/src/ifcopenshell-python/test/test_rules.py index eda686c0a0..c6dba38927 100644 --- a/src/ifcopenshell-python/test/test_rules.py +++ b/src/ifcopenshell-python/test/test_rules.py @@ -5,6 +5,7 @@ import glob import pytest import tabulate +import ifcopenshell.validate import ifcopenshell.express.rule_executor @@ -40,4 +41,4 @@ def test_file(filename): if __name__ == "__main__": - pytest.main(["-sx", __file__]) \ No newline at end of file + pytest.main(["-sx", __file__]) diff --git a/src/ifcopenshell-python/test/test_write.py b/src/ifcopenshell-python/test/test_write.py index 5ed2d69f19..e98a539dcb 100644 --- a/src/ifcopenshell-python/test/test_write.py +++ b/src/ifcopenshell-python/test/test_write.py @@ -26,7 +26,7 @@ TEST_FILE_DIR = Path("../../test/input/") class TestWrite: - def setup(self): + def setup_method(self): self.model = ifcopenshell.open(TEST_FILE_DIR / "WallInstance_IFC4Add2.ifc") def assert_model_is_written(self, filename, format=None, zipped=False):