From f11d79f8c1c06b9672b1cdccb3c2fb741608bbc5 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Fri, 7 Feb 2025 22:40:17 +1100 Subject: [PATCH] Fix cost and drawing feature tests --- src/bonsai/bonsai/tool/cost.py | 4 +- src/bonsai/test/bim/feature/drawing.feature | 95 ++++++++++++--------- src/bonsai/test/bim/test_feature.py | 6 +- 3 files changed, 60 insertions(+), 45 deletions(-) diff --git a/src/bonsai/bonsai/tool/cost.py b/src/bonsai/bonsai/tool/cost.py index 164edfe02e..251c03c61b 100644 --- a/src/bonsai/bonsai/tool/cost.py +++ b/src/bonsai/bonsai/tool/cost.py @@ -248,9 +248,7 @@ class Cost(bonsai.core.tool.Cost): cls, cost_item: ifcopenshell.entity_instance, related_object_type: RELATED_OBJECT_TYPE ) -> None: def create_list_items( - collection: bpy.types.bpy_prop_collection_idprop[bonsai.bim.helper.Attribute], - cost_item: ifcopenshell.entity_instance, - is_deep: bool, + collection: bpy.types.CollectionProperty, cost_item: ifcopenshell.entity_instance, is_deep: bool ) -> None: products = cls.get_cost_item_assignments(cost_item, filter_by_type=related_object_type, is_deep=False) for product in products: diff --git a/src/bonsai/test/bim/feature/drawing.feature b/src/bonsai/test/bim/feature/drawing.feature index f5839dfe8e..ea2acdbe44 100644 --- a/src/bonsai/test/bim/feature/drawing.feature +++ b/src/bonsai/test/bim/feature/drawing.feature @@ -8,8 +8,12 @@ Scenario: Duplicate drawing And I set "scene.BIMRootProperties.ifc_product" to "IfcElement" And I set "scene.BIMRootProperties.ifc_class" to "IfcWall" And I press "bim.assign_class" - And the variable "wall1" is "IfcStore.get_file().by_type('IfcWall')[-1].id()" - And I press "bim.add_drawing" + And I save sample test files + And I look at the "Drawings" panel + And I click "IMPORT" + And I click "ADD" + And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + When I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list And the variable "drawing" is "IfcStore.get_file().by_type('IfcAnnotation')[0].id()" When I press "bim.duplicate_drawing(drawing={drawing})" Then nothing happens @@ -21,12 +25,14 @@ Scenario: Create drawing And I set "scene.BIMRootProperties.ifc_product" to "IfcElement" And I set "scene.BIMRootProperties.ifc_class" to "IfcWall" And I press "bim.assign_class" - And the variable "wall1" is "IfcStore.get_file().by_type('IfcWall')[-1].id()" - And I press "bim.add_drawing" - And the variable "drawing" is "IfcStore.get_file().by_type('IfcAnnotation')[0].id()" - And I set "scene.DocProperties.active_drawing_index" to "0" - And I press "bim.activate_drawing(drawing={drawing})" - When I press "bim.create_drawing" + And I save sample test files + And I look at the "Drawings" panel + And I click "IMPORT" + And I click "ADD" + And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + When I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list + And I click "OUTLINER_OB_CAMERA" + And I click "OUTPUT" Then nothing happens Scenario: Create drawing after deleting a duplicated object @@ -36,19 +42,18 @@ Scenario: Create drawing after deleting a duplicated object And I set "scene.BIMRootProperties.ifc_product" to "IfcElement" And I set "scene.BIMRootProperties.ifc_class" to "IfcWall" And I press "bim.assign_class" - And the variable "wall1" is "IfcStore.get_file().by_type('IfcWall')[-1].id()" - And I press "bim.copy_class(obj='IfcWall/Cube')" - And the variable "wall2" is "IfcStore.get_file().by_type('IfcWall')[-1].id()" - And I press "bim.load_drawings" - # And I set "scene.DocProperties.location_hint" to "('My Storey', 'My Storey', '')" - And I press "bim.add_drawing" - And the variable "drawing" is "IfcStore.get_file().by_type('IfcAnnotation')[0].id()" - And I set "scene.DocProperties.active_drawing_index" to "0" - And I press "bim.activate_drawing(drawing={drawing})" - And I press "bim.create_drawing" + And I duplicate the selected objects + And I save sample test files + And I look at the "Drawings" panel + And I click "IMPORT" + And I click "ADD" + And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + And I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list + And I click "OUTLINER_OB_CAMERA" + And I click "OUTPUT" And the object "IfcWall/Cube" is selected - And I press "object.delete(use_global=False)" - When I press "bim.create_drawing" + And I delete the selected objects + When I click "OUTPUT" Then nothing happens Scenario: Activate drawing preserves visibility for non-ifc objects @@ -57,10 +62,13 @@ Scenario: Activate drawing preserves visibility for non-ifc objects And I add a cube And the object "Cube" is visible And the object "Cube.001" is not visible - And I press "bim.add_drawing" - And the variable "drawing" is "IfcStore.get_file().by_type('IfcAnnotation')[0].id()" - And I set "scene.DocProperties.active_drawing_index" to "0" - When I press "bim.activate_drawing(drawing={drawing})" + And I save sample test files + And I look at the "Drawings" panel + And I click "IMPORT" + And I click "ADD" + And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + And I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list + And I click "OUTLINER_OB_CAMERA" Then the object "Cube" is visible And the object "Cube.001" is not visible @@ -68,10 +76,13 @@ Scenario: Activate drawing preserves selection Given an empty IFC project And I add a cube And the object "Cube" is selected - And I press "bim.add_drawing" - And the variable "drawing" is "IfcStore.get_file().by_type('IfcAnnotation')[0].id()" - And I set "scene.DocProperties.active_drawing_index" to "0" - When I press "bim.activate_drawing(drawing={drawing})" + And I save sample test files + And I look at the "Drawings" panel + And I click "IMPORT" + And I click "ADD" + And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + And I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list + When I click "OUTLINER_OB_CAMERA" Then the object "Cube" is selected Scenario: Remove drawing @@ -81,10 +92,14 @@ Scenario: Remove drawing And I set "scene.BIMRootProperties.ifc_product" to "IfcElement" And I set "scene.BIMRootProperties.ifc_class" to "IfcWall" And I press "bim.assign_class" - And the variable "wall1" is "IfcStore.get_file().by_type('IfcWall')[-1].id()" - And I press "bim.add_drawing" - And the variable "drawing" is "IfcStore.get_file().by_type('IfcAnnotation')[0].id()" - And the collection "IfcAnnotation/PLAN_VIEW" exists + And I save sample test files + And I look at the "Drawings" panel + And I click "IMPORT" + And I click "ADD" + And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + And I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list + When I click "OUTLINER_OB_CAMERA" + Then the collection "IfcAnnotation/PLAN_VIEW" exists When I press "bim.remove_drawing(drawing={drawing})" Then the collection "IfcAnnotation/PLAN_VIEW" does not exist @@ -95,7 +110,6 @@ Scenario: Remove drawing - via object deletion And I set "scene.BIMRootProperties.ifc_product" to "IfcElement" And I set "scene.BIMRootProperties.ifc_class" to "IfcWall" And I press "bim.assign_class" - And the variable "wall1" is "IfcStore.get_file().by_type('IfcWall')[-1].id()" And I press "bim.add_drawing" And the variable "drawing" is "IfcStore.get_file().by_type('IfcAnnotation')[0].id()" And the collection "IfcAnnotation/PLAN_VIEW" exists @@ -110,12 +124,13 @@ Scenario: Remove drawing - deleting active drawing And I set "scene.BIMRootProperties.ifc_product" to "IfcElement" And I set "scene.BIMRootProperties.ifc_class" to "IfcWall" And I press "bim.assign_class" - And the variable "wall1" is "IfcStore.get_file().by_type('IfcWall')[-1].id()" - And I press "bim.add_drawing" - And the variable "drawing" is "IfcStore.get_file().by_type('IfcAnnotation')[0].id()" - And the collection "IfcAnnotation/PLAN_VIEW" exists - And I set "scene.DocProperties.active_drawing_index" to "0" - And I press "bim.activate_drawing(drawing={drawing})" + And I save sample test files + And I look at the "Drawings" panel + And I click "IMPORT" + And I click "ADD" + And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + And I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list + And I click "OUTLINER_OB_CAMERA" When the object "IfcAnnotation/PLAN_VIEW" is selected - And I press "bim.override_object_delete" + And I delete the selected objects Then the collection "IfcAnnotation/PLAN_VIEW" does not exist diff --git a/src/bonsai/test/bim/test_feature.py b/src/bonsai/test/bim/test_feature.py index 17bfaf7824..675fb3b278 100644 --- a/src/bonsai/test/bim/test_feature.py +++ b/src/bonsai/test/bim/test_feature.py @@ -70,7 +70,7 @@ class PanelSpy: return self def __call__(self, *args, **kwargs): - if self.spied_attr in ("row", "column", "box"): + if self.spied_attr in ("row", "column", "box", "separator"): return self elif self.spied_attr == "template_list": listtype_name, list_id, dataptr, propname, active_dataptr, active_propname = args @@ -334,6 +334,7 @@ def the_name_list_has_total_items(name, total): assert False, f"List {name} not found in {panel_spy.spied_lists}" +@given(parsers.parse('I select the "{item_name}" item in the "{list_name}" list')) @when(parsers.parse('I select the "{item_name}" item in the "{list_name}" list')) def i_select_the_item_name_item_in_the_list_name_list(item_name, list_name): panel_spy.refresh_spy() @@ -511,6 +512,7 @@ def i_evaluate_expression(expression): exec(expression) +@given("I duplicate the selected objects") @when("I duplicate the selected objects") def i_duplicate_the_selected_objects(): bpy.ops.bim.override_object_duplicate_move() @@ -635,6 +637,7 @@ def i_am_on_frame_number(number): bpy.context.scene.frame_set(int(number)) +@given("I delete the selected objects") @when("I delete the selected objects") def i_delete_the_selected_objects(): bpy.ops.bim.override_object_delete() @@ -1349,7 +1352,6 @@ def run_test_code(): @then(parsers.parse("I save sample test files")) def saving_sample_test_files(and_open_in_blender=None): filepath = f"{variables['cwd']}/test/files/temp/sample_test_file" - blend_filepath = f"{filepath}.blend" bpy.ops.bim.save_project(filepath=f"{filepath}.ifc", should_save_as=True) bpy.ops.wm.save_as_mainfile(filepath=f"{filepath}.blend")