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.
This commit is contained in:
Bruno Postle
2026-04-10 00:29:45 +01:00
committed by Ryan Schultz
parent 7c7943bb0a
commit d0b5e0a92f
3 changed files with 8 additions and 2 deletions
+1
View File
@@ -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
+6
View File
@@ -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?
+1 -2
View File
@@ -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")