2024-08-13 15:47:27 +10:00
|
|
|
# Bonsai - OpenBIM Blender Add-on
|
2021-10-12 18:31:18 +11:00
|
|
|
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
|
|
|
|
#
|
2024-08-13 15:47:27 +10:00
|
|
|
# This file is part of Bonsai.
|
2021-10-12 18:31:18 +11:00
|
|
|
#
|
2024-08-13 15:47:27 +10:00
|
|
|
# Bonsai is free software: you can redistribute it and/or modify
|
2021-10-12 18:31:18 +11:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
2024-08-13 15:47:27 +10:00
|
|
|
# Bonsai is distributed in the hope that it will be useful,
|
2021-10-12 18:31:18 +11:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2024-08-13 15:47:27 +10:00
|
|
|
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
2021-10-12 18:31:18 +11:00
|
|
|
|
2024-08-14 15:41:52 +05:00
|
|
|
import bonsai.core.unit as subject
|
2021-10-12 18:31:18 +11:00
|
|
|
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)
|
2023-05-04 21:43:18 +10:00
|
|
|
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")
|
2025-09-16 18:24:20 +02:00
|
|
|
unit.add_mass_and_time_units().should_be_called().will_return(True)
|
2025-09-05 20:22:56 +02:00
|
|
|
unit.get_scene_unit_si_prefix("MASSUNIT").should_be_called().will_return("KILO")
|
|
|
|
|
unit.get_scene_unit_si_prefix("TIMEUNIT").should_be_called().will_return(None)
|
|
|
|
|
|
2024-07-26 12:19:21 +10:00
|
|
|
ifc.run("unit.add_si_unit", unit_type="LENGTHUNIT", prefix="prefix").should_be_called().will_return(
|
|
|
|
|
"lengthunit"
|
|
|
|
|
)
|
2023-01-05 17:16:46 +11:00
|
|
|
ifc.run("unit.add_si_unit", unit_type="AREAUNIT", prefix="prefix").should_be_called().will_return("areaunit")
|
2024-07-26 12:19:21 +10:00
|
|
|
ifc.run("unit.add_si_unit", unit_type="VOLUMEUNIT", prefix="prefix").should_be_called().will_return(
|
|
|
|
|
"volumeunit"
|
|
|
|
|
)
|
2025-09-05 20:22:56 +02:00
|
|
|
ifc.run("unit.add_si_unit", unit_type="MASSUNIT", prefix="KILO").should_be_called().will_return("massunit")
|
|
|
|
|
ifc.run("unit.add_si_unit", unit_type="TIMEUNIT", prefix=None).should_be_called().will_return("timeunit")
|
2025-09-10 23:07:47 +02:00
|
|
|
ifc.run("unit.add_conversion_based_unit", name="degree").should_be_called().will_return("planeangleunit")
|
2025-09-05 20:22:56 +02:00
|
|
|
|
|
|
|
|
ifc.run(
|
2025-09-15 23:38:26 +02:00
|
|
|
"unit.assign_unit", units=["lengthunit", "areaunit", "volumeunit", "planeangleunit", "massunit", "timeunit"]
|
2025-09-05 20:22:56 +02:00
|
|
|
).should_be_called()
|
2021-10-12 18:31:18 +11:00
|
|
|
subject.assign_scene_units(ifc, unit)
|
|
|
|
|
|
2025-09-16 18:24:20 +02:00
|
|
|
def test_creating_and_assigning_metric_units_without_mass_and_time(self, ifc, unit):
|
|
|
|
|
unit.is_scene_unit_metric().should_be_called().will_return(True)
|
|
|
|
|
unit.get_scene_unit_si_prefix("LENGTHUNIT").should_be_called().will_return("CENTI")
|
|
|
|
|
unit.get_scene_unit_si_prefix("AREAUNIT").should_be_called().will_return("CENTI")
|
|
|
|
|
unit.get_scene_unit_si_prefix("VOLUMEUNIT").should_be_called().will_return("CENTI")
|
|
|
|
|
unit.add_mass_and_time_units().should_be_called().will_return(False)
|
|
|
|
|
ifc.run("unit.add_si_unit", unit_type="LENGTHUNIT", prefix="CENTI").should_be_called().will_return("lengthunit")
|
|
|
|
|
ifc.run("unit.add_si_unit", unit_type="AREAUNIT", prefix="CENTI").should_be_called().will_return("areaunit")
|
|
|
|
|
ifc.run("unit.add_si_unit", unit_type="VOLUMEUNIT", prefix="CENTI").should_be_called().will_return("volumeunit")
|
|
|
|
|
ifc.run("unit.add_conversion_based_unit", name="degree").should_be_called().will_return("planeangleunit")
|
|
|
|
|
ifc.run("unit.assign_unit", units=["lengthunit", "areaunit", "volumeunit", "planeangleunit"]).should_be_called()
|
|
|
|
|
subject.assign_scene_units(ifc, unit)
|
|
|
|
|
|
2021-10-12 18:31:18 +11:00
|
|
|
def test_creating_and_assigning_imperial_units(self, ifc, unit):
|
|
|
|
|
unit.is_scene_unit_metric().should_be_called().will_return(False)
|
2025-09-10 23:07:47 +02:00
|
|
|
unit.get_scene_unit_name("LENGTHUNIT").should_be_called().will_return("foot")
|
|
|
|
|
unit.get_scene_unit_name("AREAUNIT").should_be_called().will_return("square foot")
|
|
|
|
|
unit.get_scene_unit_name("VOLUMEUNIT").should_be_called().will_return("cubic foot")
|
2025-09-16 18:24:20 +02:00
|
|
|
unit.add_mass_and_time_units().should_be_called().will_return(True)
|
2025-09-10 23:07:47 +02:00
|
|
|
unit.get_scene_unit_name("MASSUNIT").should_be_called().will_return("pound")
|
|
|
|
|
unit.get_scene_unit_name("TIMEUNIT").should_be_called().will_return("SECOND")
|
2021-10-12 18:31:18 +11:00
|
|
|
|
2025-09-10 23:07:47 +02:00
|
|
|
ifc.run("unit.add_conversion_based_unit", name="foot").should_be_called().will_return("lengthunit")
|
|
|
|
|
ifc.run("unit.add_conversion_based_unit", name="square foot").should_be_called().will_return("areaunit")
|
|
|
|
|
ifc.run("unit.add_conversion_based_unit", name="cubic foot").should_be_called().will_return("volumeunit")
|
|
|
|
|
ifc.run("unit.add_conversion_based_unit", name="pound").should_be_called().will_return("massunit")
|
|
|
|
|
ifc.run("unit.add_si_unit", unit_type="TIMEUNIT", prefix=None).should_be_called().will_return("timeunit")
|
|
|
|
|
ifc.run("unit.add_conversion_based_unit", name="degree").should_be_called().will_return("planeangleunit")
|
2021-10-12 18:31:18 +11:00
|
|
|
|
2025-09-10 23:07:47 +02:00
|
|
|
ifc.run(
|
2025-09-15 23:38:26 +02:00
|
|
|
"unit.assign_unit", units=["lengthunit", "areaunit", "volumeunit", "planeangleunit", "massunit", "timeunit"]
|
2025-09-10 23:07:47 +02:00
|
|
|
).should_be_called()
|
|
|
|
|
subject.assign_scene_units(ifc, unit)
|
2021-10-12 18:31:18 +11:00
|
|
|
|
2025-09-16 18:24:20 +02:00
|
|
|
def test_creating_and_assigning_imperial_units_without_mass_and_time(self, ifc, unit):
|
|
|
|
|
unit.is_scene_unit_metric().should_be_called().will_return(False)
|
|
|
|
|
unit.get_scene_unit_name("LENGTHUNIT").should_be_called().will_return("yard")
|
|
|
|
|
unit.get_scene_unit_name("AREAUNIT").should_be_called().will_return("square yard")
|
|
|
|
|
unit.get_scene_unit_name("VOLUMEUNIT").should_be_called().will_return("cubic yard")
|
|
|
|
|
unit.add_mass_and_time_units().should_be_called().will_return(False)
|
|
|
|
|
ifc.run("unit.add_conversion_based_unit", name="yard").should_be_called().will_return("lengthunit")
|
|
|
|
|
ifc.run("unit.add_conversion_based_unit", name="square yard").should_be_called().will_return("areaunit")
|
|
|
|
|
ifc.run("unit.add_conversion_based_unit", name="cubic yard").should_be_called().will_return("volumeunit")
|
|
|
|
|
ifc.run("unit.add_conversion_based_unit", name="degree").should_be_called().will_return("planeangleunit")
|
|
|
|
|
ifc.run("unit.assign_unit", units=["lengthunit", "areaunit", "volumeunit", "planeangleunit"]).should_be_called()
|
|
|
|
|
subject.assign_scene_units(ifc, unit)
|
|
|
|
|
|
2025-09-10 23:07:47 +02:00
|
|
|
def test_creating_metric_units_with_conversion_based_mass_and_time(self, ifc, unit):
|
|
|
|
|
unit.is_scene_unit_metric().should_be_called().will_return(True)
|
|
|
|
|
unit.get_scene_unit_si_prefix("LENGTHUNIT").should_be_called().will_return("MILLI")
|
|
|
|
|
unit.get_scene_unit_si_prefix("AREAUNIT").should_be_called().will_return(None)
|
|
|
|
|
unit.get_scene_unit_si_prefix("VOLUMEUNIT").should_be_called().will_return(None)
|
2025-09-16 18:24:20 +02:00
|
|
|
unit.add_mass_and_time_units().should_be_called().will_return(True)
|
2025-09-10 23:07:47 +02:00
|
|
|
unit.get_scene_unit_si_prefix("MASSUNIT").should_be_called().will_return("CONVERSION")
|
|
|
|
|
unit.get_scene_unit_name("MASSUNIT").should_be_called().will_return("tonne")
|
|
|
|
|
unit.get_scene_unit_si_prefix("TIMEUNIT").should_be_called().will_return("CONVERSION")
|
|
|
|
|
unit.get_scene_unit_name("TIMEUNIT").should_be_called().will_return("minute")
|
|
|
|
|
|
|
|
|
|
ifc.run("unit.add_si_unit", unit_type="LENGTHUNIT", prefix="MILLI").should_be_called().will_return("lengthunit")
|
|
|
|
|
ifc.run("unit.add_si_unit", unit_type="AREAUNIT", prefix=None).should_be_called().will_return("areaunit")
|
|
|
|
|
ifc.run("unit.add_si_unit", unit_type="VOLUMEUNIT", prefix=None).should_be_called().will_return("volumeunit")
|
|
|
|
|
ifc.run("unit.add_conversion_based_unit", name="tonne").should_be_called().will_return("massunit")
|
|
|
|
|
ifc.run("unit.add_conversion_based_unit", name="minute").should_be_called().will_return("timeunit")
|
2022-03-27 10:38:53 +11:00
|
|
|
ifc.run("unit.add_conversion_based_unit", name="degree").should_be_called().will_return("planeangleunit")
|
|
|
|
|
|
2025-09-10 23:07:47 +02:00
|
|
|
ifc.run(
|
2025-09-15 23:38:26 +02:00
|
|
|
"unit.assign_unit", units=["lengthunit", "areaunit", "volumeunit", "planeangleunit", "massunit", "timeunit"]
|
2025-09-10 23:07:47 +02:00
|
|
|
).should_be_called()
|
|
|
|
|
subject.assign_scene_units(ifc, unit)
|
2025-09-05 20:22:56 +02:00
|
|
|
|
2025-09-10 23:07:47 +02:00
|
|
|
def test_creating_imperial_units_with_conversion_based_units(self, ifc, unit):
|
|
|
|
|
unit.is_scene_unit_metric().should_be_called().will_return(False)
|
|
|
|
|
unit.get_scene_unit_name("LENGTHUNIT").should_be_called().will_return("inch")
|
|
|
|
|
unit.get_scene_unit_name("AREAUNIT").should_be_called().will_return("square inch")
|
|
|
|
|
unit.get_scene_unit_name("VOLUMEUNIT").should_be_called().will_return("cubic inch")
|
2025-09-16 18:24:20 +02:00
|
|
|
unit.add_mass_and_time_units().should_be_called().will_return(True)
|
2025-09-10 23:07:47 +02:00
|
|
|
unit.get_scene_unit_name("MASSUNIT").should_be_called().will_return("ounce")
|
|
|
|
|
unit.get_scene_unit_name("TIMEUNIT").should_be_called().will_return("hour")
|
|
|
|
|
|
|
|
|
|
ifc.run("unit.add_conversion_based_unit", name="inch").should_be_called().will_return("lengthunit")
|
|
|
|
|
ifc.run("unit.add_conversion_based_unit", name="square inch").should_be_called().will_return("areaunit")
|
|
|
|
|
ifc.run("unit.add_conversion_based_unit", name="cubic inch").should_be_called().will_return("volumeunit")
|
|
|
|
|
ifc.run("unit.add_conversion_based_unit", name="ounce").should_be_called().will_return("massunit")
|
|
|
|
|
ifc.run("unit.add_conversion_based_unit", name="hour").should_be_called().will_return("timeunit")
|
|
|
|
|
ifc.run("unit.add_conversion_based_unit", name="degree").should_be_called().will_return("planeangleunit")
|
2025-09-05 20:22:56 +02:00
|
|
|
|
|
|
|
|
ifc.run(
|
2025-09-15 23:38:26 +02:00
|
|
|
"unit.assign_unit", units=["lengthunit", "areaunit", "volumeunit", "planeangleunit", "massunit", "timeunit"]
|
2025-09-05 20:22:56 +02:00
|
|
|
).should_be_called()
|
2021-10-12 18:31:18 +11:00
|
|
|
subject.assign_scene_units(ifc, unit)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestAssignUnit:
|
|
|
|
|
def test_run(self, ifc, unit):
|
|
|
|
|
ifc.run("unit.assign_unit", units=["unit"]).should_be_called()
|
|
|
|
|
unit.import_units().should_be_called()
|
|
|
|
|
subject.assign_unit(ifc, unit, unit="unit")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestUnassignUnit:
|
|
|
|
|
def test_run(self, ifc, unit):
|
|
|
|
|
ifc.run("unit.unassign_unit", units=["unit"]).should_be_called()
|
|
|
|
|
unit.import_units().should_be_called()
|
|
|
|
|
subject.unassign_unit(ifc, unit, unit="unit")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestLoadUnits:
|
|
|
|
|
def test_run(self, unit):
|
|
|
|
|
unit.import_units().should_be_called()
|
|
|
|
|
unit.enable_editing_units().should_be_called()
|
|
|
|
|
subject.load_units(unit)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestDisableUnitEditingUI:
|
|
|
|
|
def test_run(self, unit):
|
|
|
|
|
unit.disable_editing_units().should_be_called()
|
|
|
|
|
subject.disable_unit_editing_ui(unit)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestRemoveUnit:
|
|
|
|
|
def test_run(self, ifc, unit):
|
|
|
|
|
ifc.run("unit.remove_unit", unit="unit").should_be_called()
|
|
|
|
|
unit.import_units().should_be_called()
|
|
|
|
|
subject.remove_unit(ifc, unit, unit="unit")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestAddMonetaryUnit:
|
|
|
|
|
def test_run(self, ifc, unit):
|
|
|
|
|
ifc.run("unit.add_monetary_unit").should_be_called().will_return("unit")
|
|
|
|
|
unit.import_units().should_be_called()
|
|
|
|
|
assert subject.add_monetary_unit(ifc, unit) == "unit"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestAddSIUnit:
|
|
|
|
|
def test_run(self, ifc, unit):
|
2023-01-05 17:16:46 +11:00
|
|
|
ifc.run("unit.add_si_unit", unit_type="unit_type").should_be_called().will_return("unit")
|
2021-10-12 18:31:18 +11:00
|
|
|
unit.import_units().should_be_called()
|
|
|
|
|
assert subject.add_si_unit(ifc, unit, unit_type="unit_type") == "unit"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestAddContextDependentUnit:
|
|
|
|
|
def test_run(self, ifc, unit):
|
|
|
|
|
ifc.run("unit.add_context_dependent_unit", unit_type="unit_type", name="name").should_be_called().will_return(
|
|
|
|
|
"unit"
|
|
|
|
|
)
|
|
|
|
|
unit.import_units().should_be_called()
|
|
|
|
|
assert subject.add_context_dependent_unit(ifc, unit, unit_type="unit_type", name="name") == "unit"
|
|
|
|
|
|
|
|
|
|
|
2022-03-27 10:38:53 +11:00
|
|
|
class TestAddConversionBasedUnit:
|
|
|
|
|
def test_run(self, ifc, unit):
|
|
|
|
|
ifc.run("unit.add_conversion_based_unit", name="name").should_be_called().will_return("unit")
|
|
|
|
|
unit.import_units().should_be_called()
|
|
|
|
|
assert subject.add_conversion_based_unit(ifc, unit, name="name") == "unit"
|
|
|
|
|
|
|
|
|
|
|
2021-10-12 18:31:18 +11:00
|
|
|
class TestEnableEditingUnit:
|
|
|
|
|
def test_run(self, unit):
|
|
|
|
|
unit.set_active_unit("unit").should_be_called()
|
|
|
|
|
unit.import_unit_attributes("unit").should_be_called()
|
|
|
|
|
subject.enable_editing_unit(unit, unit="unit")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestDisableEditingUnit:
|
|
|
|
|
def test_run(self, unit):
|
|
|
|
|
unit.clear_active_unit().should_be_called()
|
|
|
|
|
subject.disable_editing_unit(unit)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestEditUnit:
|
|
|
|
|
def test_editing_monetary_units(self, ifc, unit):
|
|
|
|
|
unit.export_unit_attributes().should_be_called().will_return("attributes")
|
2022-05-29 17:25:28 +10:00
|
|
|
unit.is_unit_class("unit", "IfcMonetaryUnit").should_be_called().will_return(True)
|
2021-10-12 18:31:18 +11:00
|
|
|
ifc.run("unit.edit_monetary_unit", unit="unit", attributes="attributes").should_be_called()
|
|
|
|
|
unit.import_units().should_be_called()
|
|
|
|
|
unit.clear_active_unit().should_be_called()
|
|
|
|
|
subject.edit_unit(ifc, unit, unit="unit")
|
|
|
|
|
|
|
|
|
|
def test_editing_derived_units(self, ifc, unit):
|
|
|
|
|
unit.export_unit_attributes().should_be_called().will_return("attributes")
|
2022-05-29 17:25:28 +10:00
|
|
|
unit.is_unit_class("unit", "IfcMonetaryUnit").should_be_called().will_return(False)
|
|
|
|
|
unit.is_unit_class("unit", "IfcDerivedUnit").should_be_called().will_return(True)
|
2021-10-12 18:31:18 +11:00
|
|
|
ifc.run("unit.edit_derived_unit", unit="unit", attributes="attributes").should_be_called()
|
|
|
|
|
unit.import_units().should_be_called()
|
|
|
|
|
unit.clear_active_unit().should_be_called()
|
|
|
|
|
subject.edit_unit(ifc, unit, unit="unit")
|
|
|
|
|
|
|
|
|
|
def test_editing_named_units(self, ifc, unit):
|
|
|
|
|
unit.export_unit_attributes().should_be_called().will_return("attributes")
|
2022-05-29 17:25:28 +10:00
|
|
|
unit.is_unit_class("unit", "IfcMonetaryUnit").should_be_called().will_return(False)
|
|
|
|
|
unit.is_unit_class("unit", "IfcDerivedUnit").should_be_called().will_return(False)
|
|
|
|
|
unit.is_unit_class("unit", "IfcNamedUnit").should_be_called().will_return(True)
|
2021-10-12 18:31:18 +11:00
|
|
|
ifc.run("unit.edit_named_unit", unit="unit", attributes="attributes").should_be_called()
|
|
|
|
|
unit.import_units().should_be_called()
|
|
|
|
|
unit.clear_active_unit().should_be_called()
|
|
|
|
|
subject.edit_unit(ifc, unit, unit="unit")
|