From 0d3245102f04143263ef119826c7b24c170a653c Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Fri, 7 Feb 2025 13:12:02 +1100 Subject: [PATCH] Fix remaining failing tool tests --- src/bonsai/bonsai/core/tool.py | 1 - src/bonsai/bonsai/tool/loader.py | 2 +- src/bonsai/test/tool/test_polyline.py | 10 ++++++++-- src/bonsai/test/tool/test_qto.py | 1 - src/bonsai/test/tool/test_spatial.py | 6 +++--- src/bonsai/test/tool/test_style.py | 17 ----------------- 6 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/bonsai/bonsai/core/tool.py b/src/bonsai/bonsai/core/tool.py index 7c5745d093..b84e931871 100644 --- a/src/bonsai/bonsai/core/tool.py +++ b/src/bonsai/bonsai/core/tool.py @@ -1015,7 +1015,6 @@ class Style: def get_elements_by_style(cls, style): pass def get_currently_edited_material(cls): pass def get_name(cls, obj): pass - def get_style(cls, obj): pass def get_style_elements(cls, blender_material): pass def get_surface_rendering_attributes(cls, obj, verbose=True): pass def get_surface_rendering_style(cls, obj): pass diff --git a/src/bonsai/bonsai/tool/loader.py b/src/bonsai/bonsai/tool/loader.py index 79c2e785a1..6746fac199 100644 --- a/src/bonsai/bonsai/tool/loader.py +++ b/src/bonsai/bonsai/tool/loader.py @@ -95,7 +95,7 @@ class Loader(bonsai.core.tool.Loader): def get_name(cls, element: ifcopenshell.entity_instance) -> str: if element.is_a("IfcGridAxis"): return "{}/{}".format(element.is_a(), element.AxisTag) - return "{}/{}".format(element.is_a(), getattr(element, "Name", "None")) + return "{}/{}".format(element.is_a(), getattr(element, "Name", "Unnamed") or "Unnamed") @classmethod def link_mesh( diff --git a/src/bonsai/test/tool/test_polyline.py b/src/bonsai/test/tool/test_polyline.py index ecaad033eb..b7d4303b0d 100644 --- a/src/bonsai/test/tool/test_polyline.py +++ b/src/bonsai/test/tool/test_polyline.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with Bonsai. If not, see . -import os import bpy import ifcopenshell import bonsai.core.tool @@ -32,14 +31,21 @@ class TestImplementsTool(NewFile): class TestValidateInput(NewFile): def test_simple_units(self): + ifc = ifcopenshell.api.project.create_file() + tool.Ifc.set(ifc) + ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject") + unit = ifcopenshell.api.unit.add_si_unit(ifc, unit_type="LENGTHUNIT", prefix=None) + ifcopenshell.api.unit.assign_unit(ifc, [unit]) unit_settings = bpy.context.scene.unit_settings unit_settings.system = "METRIC" - unit_settings.length_unit = "METERS" assert subject.validate_input("25", "D") == (True, "25.0") + unit.Prefix = "MILLI" unit_settings.length_unit = "MILLIMETERS" assert subject.validate_input("25", "D") == (True, "0.025") unit_settings.system = "IMPERIAL" + unit = ifcopenshell.api.unit.add_conversion_based_unit(ifc, name="foot") + ifcopenshell.api.unit.assign_unit(ifc, [unit]) assert subject.validate_input("25", "D") == (True, "7.62") assert subject.validate_input("25'", "D") == (True, "7.62") assert subject.validate_input('25"', "D") == (True, "0.635") diff --git a/src/bonsai/test/tool/test_qto.py b/src/bonsai/test/tool/test_qto.py index 9ed5c1e024..b9e3926f65 100644 --- a/src/bonsai/test/tool/test_qto.py +++ b/src/bonsai/test/tool/test_qto.py @@ -201,7 +201,6 @@ class TestGetRelatedCostItemQuantities(test.bim.bootstrap.NewFile): ifc = ifcopenshell.file() tool.Ifc.set(ifc) wall = ifc.createIfcWall() - product = tool.Ifc.get_entity(wall) schedule = ifcopenshell.api.run("cost.add_cost_schedule", ifc) item = ifcopenshell.api.run("cost.add_cost_item", ifc, cost_schedule=schedule) ifcopenshell.api.run("cost.edit_cost_item", ifc, cost_item=item, attributes={"Name": "Foo"}) diff --git a/src/bonsai/test/tool/test_spatial.py b/src/bonsai/test/tool/test_spatial.py index 883ca27ba7..cf16dfeb2b 100644 --- a/src/bonsai/test/tool/test_spatial.py +++ b/src/bonsai/test/tool/test_spatial.py @@ -250,7 +250,7 @@ class TestGenerateSpace(NewFile): mesh = space.data assert isinstance(mesh, bpy.types.Mesh) assert len(mesh.vertices) == 8 - TEST_VERTS = ( + TEST_VERTS = sorted(( ((5.0, 5.0, 10.0)), ((-5.0, 5.0, 10.0)), ((-5.0, -5.0, 10.0)), @@ -259,5 +259,5 @@ class TestGenerateSpace(NewFile): ((-5.0, -5.0, 0.0)), ((5.0, 5.0, 0.0)), ((5.0, -5.0, 0.0)), - ) - assert np.allclose(TEST_VERTS, [tuple(v.co) for v in mesh.vertices]) + )) + assert np.allclose(TEST_VERTS, sorted([tuple(v.co) for v in mesh.vertices])) diff --git a/src/bonsai/test/tool/test_style.py b/src/bonsai/test/tool/test_style.py index 7bcba63465..cf46d8fab7 100644 --- a/src/bonsai/test/tool/test_style.py +++ b/src/bonsai/test/tool/test_style.py @@ -117,23 +117,6 @@ class TestGetName(NewFile): assert subject.get_name(bpy.data.materials.new("Material")) == "Material" -class TestGetStyle(NewFile): - def test_getting_no_style(self): - assert subject.get_style(bpy.data.materials.new("Material")) is None - - def test_getting_a_linked_style(self): - tool.Ifc.set(ifcopenshell.file()) - style = tool.Ifc.get().createIfcSurfaceStyle() - obj = bpy.data.materials.new("Material") - obj.BIMStyleProperties.ifc_definition_id = style.id() - assert subject.get_style(obj) == style - - def test_getting_nothing_for_a_broken_link_style(self): - obj = bpy.data.materials.new("Material") - obj.BIMStyleProperties.ifc_definition_id = 1 - assert subject.get_style(obj) == None - - class TestGetSurfaceRenderingAttributes(NewFile): def test_get_different_surface_and_diffuse_colours_from_a_principled_bsdf(self): obj = bpy.data.materials.new("Material")