Fix fundamental bug where area and volume units were ignored on new projects.

This commit is contained in:
Dion Moult
2023-05-04 21:43:18 +10:00
parent 41e58a3d46
commit 539b3a243b
5 changed files with 73 additions and 73 deletions
+6 -7
View File
@@ -23,16 +23,15 @@ from test.core.bootstrap import ifc, unit
class TestAssignSceneUnits:
def test_creating_and_assigning_metric_units(self, ifc, unit):
unit.is_scene_unit_metric().should_be_called().will_return(True)
unit.get_scene_unit_name("length").should_be_called().will_return("name")
unit.get_scene_unit_si_prefix().should_be_called().will_return("prefix")
unit.get_scene_unit_si_prefix("LENGTHUNIT").should_be_called().will_return("prefix")
unit.get_scene_unit_si_prefix("AREAUNIT").should_be_called().will_return("prefix")
unit.get_scene_unit_si_prefix("VOLUMEUNIT").should_be_called().will_return("prefix")
ifc.run(
"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", 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", prefix="prefix"
).should_be_called().will_return("volumeunit")
@@ -44,13 +43,13 @@ class TestAssignSceneUnits:
def test_creating_and_assigning_imperial_units(self, ifc, unit):
unit.is_scene_unit_metric().should_be_called().will_return(False)
unit.get_scene_unit_name("length").should_be_called().will_return("lengthname")
unit.get_scene_unit_name("LENGTHUNIT").should_be_called().will_return("lengthname")
ifc.run("unit.add_conversion_based_unit", name="lengthname").should_be_called().will_return("lengthunit")
unit.get_scene_unit_name("area").should_be_called().will_return("areaname")
unit.get_scene_unit_name("AREAUNIT").should_be_called().will_return("areaname")
ifc.run("unit.add_conversion_based_unit", name="areaname").should_be_called().will_return("areaunit")
unit.get_scene_unit_name("volume").should_be_called().will_return("volumename")
unit.get_scene_unit_name("VOLUMEUNIT").should_be_called().will_return("volumename")
ifc.run("unit.add_conversion_based_unit", name="volumename").should_be_called().will_return("volumeunit")
ifc.run("unit.add_conversion_based_unit", name="degree").should_be_called().will_return("planeangleunit")
+32 -28
View File
@@ -97,55 +97,59 @@ class TestExportUnitAttributes(NewFile):
class TestGetSceneUnitName(NewFile):
def test_getting_a_metric_name(self):
bpy.context.scene.unit_settings.system = "METRIC"
assert subject.get_scene_unit_name("length") == "METRE"
assert subject.get_scene_unit_name("area") == "SQUARE_METRE"
assert subject.get_scene_unit_name("volume") == "CUBIC_METRE"
def test_getting_an_imperial_name(self):
bpy.context.scene.unit_settings.system = "IMPERIAL"
bpy.context.scene.unit_settings.length_unit = "MILES"
assert subject.get_scene_unit_name("length") == "mile"
assert subject.get_scene_unit_name("area") == "square mile"
assert subject.get_scene_unit_name("volume") == "cubic mile"
bpy.context.scene.BIMProperties.area_unit = "square foot"
bpy.context.scene.BIMProperties.volume_unit = "cubic inch"
assert subject.get_scene_unit_name("LENGTHUNIT") == "mile"
assert subject.get_scene_unit_name("AREAUNIT") == "square foot"
assert subject.get_scene_unit_name("VOLUMEUNIT") == "cubic inch"
bpy.context.scene.unit_settings.length_unit = "FEET"
assert subject.get_scene_unit_name("length") == "foot"
assert subject.get_scene_unit_name("area") == "square foot"
assert subject.get_scene_unit_name("volume") == "cubic foot"
assert subject.get_scene_unit_name("LENGTHUNIT") == "foot"
assert subject.get_scene_unit_name("AREAUNIT") == "square foot"
assert subject.get_scene_unit_name("VOLUMEUNIT") == "cubic inch"
bpy.context.scene.unit_settings.length_unit = "INCHES"
assert subject.get_scene_unit_name("length") == "inch"
assert subject.get_scene_unit_name("area") == "square inch"
assert subject.get_scene_unit_name("volume") == "cubic inch"
assert subject.get_scene_unit_name("LENGTHUNIT") == "inch"
assert subject.get_scene_unit_name("AREAUNIT") == "square foot"
assert subject.get_scene_unit_name("VOLUMEUNIT") == "cubic inch"
bpy.context.scene.unit_settings.length_unit = "THOU"
assert subject.get_scene_unit_name("length") == "thou"
assert subject.get_scene_unit_name("area") == "square thou"
assert subject.get_scene_unit_name("volume") == "cubic thou"
assert subject.get_scene_unit_name("LENGTHUNIT") == "thou"
assert subject.get_scene_unit_name("AREAUNIT") == "square foot"
assert subject.get_scene_unit_name("VOLUMEUNIT") == "cubic inch"
bpy.context.scene.unit_settings.length_unit = "ADAPTIVE"
assert subject.get_scene_unit_name("length") == "foot"
assert subject.get_scene_unit_name("area") == "square foot"
assert subject.get_scene_unit_name("volume") == "cubic foot"
assert subject.get_scene_unit_name("LENGTHUNIT") == "foot"
assert subject.get_scene_unit_name("AREAUNIT") == "square foot"
assert subject.get_scene_unit_name("VOLUMEUNIT") == "cubic inch"
def test_getting_a_name_with_no_unit_system(self):
bpy.context.scene.unit_settings.system = "NONE"
assert subject.get_scene_unit_name("length") == "METRE"
assert subject.get_scene_unit_name("LENGTHUNIT") == "foot"
class TestGetSceneUnitSIPrefix:
def test_run(self):
bpy.context.scene.unit_settings.system = "METRIC"
bpy.context.scene.unit_settings.length_unit = "METERS"
assert subject.get_scene_unit_si_prefix() is None
assert subject.get_scene_unit_si_prefix("LENGTHUNIT") is None
bpy.context.scene.unit_settings.length_unit = "MICROMETERS"
assert subject.get_scene_unit_si_prefix() == "MICRO"
assert subject.get_scene_unit_si_prefix("LENGTHUNIT") == "MICRO"
bpy.context.scene.unit_settings.length_unit = "MILLIMETERS"
assert subject.get_scene_unit_si_prefix() == "MILLI"
assert subject.get_scene_unit_si_prefix("LENGTHUNIT") == "MILLI"
bpy.context.scene.unit_settings.length_unit = "CENTIMETERS"
assert subject.get_scene_unit_si_prefix() == "CENTI"
assert subject.get_scene_unit_si_prefix("LENGTHUNIT") == "CENTI"
bpy.context.scene.unit_settings.length_unit = "KILOMETERS"
assert subject.get_scene_unit_si_prefix() == "KILO"
assert subject.get_scene_unit_si_prefix("LENGTHUNIT") == "KILO"
bpy.context.scene.unit_settings.length_unit = "ADAPTIVE"
assert subject.get_scene_unit_si_prefix() is None
assert subject.get_scene_unit_si_prefix("LENGTHUNIT") is None
bpy.context.scene.BIMProperties.area_unit = "SQUARE_METRE"
assert subject.get_scene_unit_si_prefix("AREAUNIT") is None
bpy.context.scene.BIMProperties.area_unit = "MILLI/SQUARE_METRE"
assert subject.get_scene_unit_si_prefix("AREAUNIT") == "MILLI"
bpy.context.scene.BIMProperties.volume_unit = "CUBIC_METRE"
assert subject.get_scene_unit_si_prefix("VOLUMEUNIT") is None
bpy.context.scene.BIMProperties.volume_unit = "MILLI/CUBIC_METRE"
assert subject.get_scene_unit_si_prefix("VOLUMEUNIT") == "MILLI"
class TestImportUnitAttributes(NewFile):