From cb92be2b087604ffa4a9df7564dcd2328e5b2d8c Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 5 Jan 2023 17:16:46 +1100 Subject: [PATCH] No need to specify SI unit names as they can be derived from the unit type --- src/blenderbim/blenderbim/core/unit.py | 8 ++++---- src/blenderbim/blenderbim/tool/unit.py | 4 ---- src/blenderbim/test/core/test_unit.py | 11 ++++------- src/blenderbim/test/tool/test_unit.py | 6 ------ 4 files changed, 8 insertions(+), 21 deletions(-) diff --git a/src/blenderbim/blenderbim/core/unit.py b/src/blenderbim/blenderbim/core/unit.py index e21ea62816..942e4057cb 100644 --- a/src/blenderbim/blenderbim/core/unit.py +++ b/src/blenderbim/blenderbim/core/unit.py @@ -24,9 +24,9 @@ def assign_scene_units(ifc, unit): if unit.is_scene_unit_metric(): prefix = unit.get_scene_unit_si_prefix() - lengthunit = ifc.run("unit.add_si_unit", unit_type="LENGTHUNIT", name=length_name, prefix=prefix) - areaunit = ifc.run("unit.add_si_unit", unit_type="AREAUNIT", name=area_name, prefix=prefix) - volumeunit = ifc.run("unit.add_si_unit", unit_type="VOLUMEUNIT", name=volume_name, prefix=prefix) + lengthunit = ifc.run("unit.add_si_unit", unit_type="LENGTHUNIT", prefix=prefix) + areaunit = ifc.run("unit.add_si_unit", unit_type="AREAUNIT", prefix=prefix) + volumeunit = ifc.run("unit.add_si_unit", unit_type="VOLUMEUNIT", prefix=prefix) else: lengthunit = ifc.run("unit.add_conversion_based_unit", name=length_name) areaunit = ifc.run("unit.add_conversion_based_unit", name=area_name) @@ -68,7 +68,7 @@ def add_monetary_unit(ifc, unit): def add_si_unit(ifc, unit, unit_type=None): - result = ifc.run("unit.add_si_unit", unit_type=unit_type, name=unit.get_si_name_from_unit_type(unit_type)) + result = ifc.run("unit.add_si_unit", unit_type=unit_type) unit.import_units() return result diff --git a/src/blenderbim/blenderbim/tool/unit.py b/src/blenderbim/blenderbim/tool/unit.py index ebd9f1c152..3e064db335 100644 --- a/src/blenderbim/blenderbim/tool/unit.py +++ b/src/blenderbim/blenderbim/tool/unit.py @@ -83,10 +83,6 @@ class Unit(blenderbim.core.tool.Unit): return return props.length_unit.replace("METERS", "") - @classmethod - def get_si_name_from_unit_type(cls, unit_type): - return ifcopenshell.util.unit.si_type_names.get(unit_type, None) - @classmethod def import_unit_attributes(cls, unit): def callback(name, prop, data): diff --git a/src/blenderbim/test/core/test_unit.py b/src/blenderbim/test/core/test_unit.py index 3e77d582a8..40c101a0d9 100644 --- a/src/blenderbim/test/core/test_unit.py +++ b/src/blenderbim/test/core/test_unit.py @@ -26,17 +26,15 @@ class TestAssignSceneUnits: unit.get_scene_unit_name("length").should_be_called().will_return("name") unit.get_scene_unit_si_prefix().should_be_called().will_return("prefix") ifc.run( - "unit.add_si_unit", unit_type="LENGTHUNIT", name="name", prefix="prefix" + "unit.add_si_unit", unit_type="LENGTHUNIT", prefix="prefix" ).should_be_called().will_return("lengthunit") unit.get_scene_unit_name("area").should_be_called().will_return("name") - ifc.run("unit.add_si_unit", unit_type="AREAUNIT", name="name", prefix="prefix").should_be_called().will_return( - "areaunit" - ) + ifc.run("unit.add_si_unit", unit_type="AREAUNIT", prefix="prefix").should_be_called().will_return("areaunit") unit.get_scene_unit_name("volume").should_be_called().will_return("name") ifc.run( - "unit.add_si_unit", unit_type="VOLUMEUNIT", name="name", prefix="prefix" + "unit.add_si_unit", unit_type="VOLUMEUNIT", prefix="prefix" ).should_be_called().will_return("volumeunit") ifc.run("unit.add_conversion_based_unit", name="degree").should_be_called().will_return("planeangleunit") @@ -104,8 +102,7 @@ class TestAddMonetaryUnit: class TestAddSIUnit: def test_run(self, ifc, unit): - unit.get_si_name_from_unit_type("unit_type").should_be_called().will_return("name") - ifc.run("unit.add_si_unit", unit_type="unit_type", name="name").should_be_called().will_return("unit") + ifc.run("unit.add_si_unit", unit_type="unit_type").should_be_called().will_return("unit") unit.import_units().should_be_called() assert subject.add_si_unit(ifc, unit, unit_type="unit_type") == "unit" diff --git a/src/blenderbim/test/tool/test_unit.py b/src/blenderbim/test/tool/test_unit.py index 626b6d0247..12b80356d1 100644 --- a/src/blenderbim/test/tool/test_unit.py +++ b/src/blenderbim/test/tool/test_unit.py @@ -148,12 +148,6 @@ class TestGetSceneUnitSIPrefix: assert subject.get_scene_unit_si_prefix() is None -class TestGetSINameFromUnitType: - def test_run(self): - for key, value in ifcopenshell.util.unit.si_type_names.items(): - assert subject.get_si_name_from_unit_type(key) == value - - class TestImportUnitAttributes(NewFile): def test_importing_derived_units(self): ifc = ifcopenshell.file()