From d0b5e0a92f7c6a0e1092d56273437644522fde58 Mon Sep 17 00:00:00 2001 From: Bruno Postle Date: Fri, 10 Apr 2026 00:29:45 +0100 Subject: [PATCH] bonsai: fix failing test_copy_with_new_geometry_copied_from_the_old Move has_material_styles into the Root tool so it can be mocked in core unit tests; the private function was calling ifcopenshell.util.element directly, bypassing the tool layer and crashing the test. Generated with the assistance of an AI coding tool. --- src/bonsai/bonsai/core/tool.py | 1 + src/bonsai/bonsai/tool/root.py | 6 ++++++ src/bonsai/test/core/test_root.py | 3 +-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bonsai/bonsai/core/tool.py b/src/bonsai/bonsai/core/tool.py index 91003174ad..889ca774ee 100644 --- a/src/bonsai/bonsai/core/tool.py +++ b/src/bonsai/bonsai/core/tool.py @@ -894,6 +894,7 @@ class Root: def get_default_container(cls): pass def get_element_representation(cls, element, context): pass def get_element_type(cls, element): pass + def has_material_styles(cls, element): pass def get_object_name(cls, obj): pass def get_object_representation(cls, obj): pass def get_representation_context(cls, representation): pass diff --git a/src/bonsai/bonsai/tool/root.py b/src/bonsai/bonsai/tool/root.py index ccc76b9526..9daef1798c 100644 --- a/src/bonsai/bonsai/tool/root.py +++ b/src/bonsai/bonsai/tool/root.py @@ -54,6 +54,12 @@ class Root(bonsai.core.tool.Root): new.obj = obj new.name = opening_type + @classmethod + def has_material_styles(cls, element: ifcopenshell.entity_instance) -> bool: + """Return True if any constituent material of element has a style representation.""" + materials = ifcopenshell.util.element.get_materials(element) + return any(getattr(m, "HasRepresentation", None) for m in materials) + @classmethod def assign_body_styles(cls, element: ifcopenshell.entity_instance, obj: bpy.types.Object) -> None: # Should this even be here? Should it be in the geometry tool? diff --git a/src/bonsai/test/core/test_root.py b/src/bonsai/test/core/test_root.py index 96bd389d1d..4fcafe6947 100644 --- a/src/bonsai/test/core/test_root.py +++ b/src/bonsai/test/core/test_root.py @@ -40,8 +40,7 @@ class TestCopyClass: collector.assign("obj").should_be_called() subject.copy_class(ifc, collector, geometry, root, obj="obj") - # def test_copy_with_new_geometry_copied_from_the_old(self, ifc, collector, geometry, root): - def test_AAAAAAAAAAAA(self, ifc, collector, geometry, root): + def test_copy_with_new_geometry_copied_from_the_old(self, ifc, collector, geometry, root): ifc.get_entity("obj").should_be_called().will_return("original_element") root.is_element_a("original_element", "IfcRelSpaceBoundary").should_be_called().will_return(False) root.get_object_representation("obj").should_be_called().will_return("representation")