From 103e8a545b45e30bb8a27e48958ee907d1ebc15a Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 21 Jun 2023 12:04:33 +0500 Subject: [PATCH] Fixed test after c8c0c9a Taking into account that now we have error messages if user will try to remove the last material layer which would make layer set invalid ifc. FAILED test/bim/test_feature.py::test_remove_material_set_layer - AssertionError: Failed to run operator bpy.ops.bim.remove_layer(layer=IfcStore.get_file().by_id(93).MaterialLayers[... --- src/blenderbim/test/bim/feature/material.feature | 9 ++++++--- src/blenderbim/test/bim/test_feature.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/blenderbim/test/bim/feature/material.feature b/src/blenderbim/test/bim/feature/material.feature index 3e850021bb..87ce5b82d6 100644 --- a/src/blenderbim/test/bim/feature/material.feature +++ b/src/blenderbim/test/bim/feature/material.feature @@ -435,17 +435,20 @@ Scenario: Remove material set layer And the object "Cube" is selected And I set "scene.BIMRootProperties.ifc_class" to "IfcWall" And I press "bim.assign_class" + And I add an empty And the object "Empty" is selected And I set "scene.BIMRootProperties.ifc_product" to "IfcElementType" And I set "scene.BIMRootProperties.ifc_class" to "IfcWallType" And I press "bim.assign_class" + And I press "bim.add_material(obj='')" And I set "active_object.BIMObjectMaterialProperties.material_type" to "IfcMaterialLayerSet" And I press "bim.assign_material" + And I press "bim.enable_editing_assigned_material" And the variable "material_set" is "{ifc}.by_type('IfcMaterialLayerSet')[0].id()" - And I press "bim.remove_layer(layer={ifc}.by_id({material_set}).MaterialLayers[0].id())" + And I press "bim.add_layer(layer_set={material_set})" - When I press "bim.remove_layer(layer={ifc}.by_id({material_set}).MaterialLayers[0].id())" - Then nothing happens + And I press "bim.remove_layer(layer={ifc}.by_id({material_set}).MaterialLayers[0].id())" + Then I press "bim.remove_layer(layer={ifc}.by_id({material_set}).MaterialLayers[0].id())" and expect error "Error: At least one layer must exist" diff --git a/src/blenderbim/test/bim/test_feature.py b/src/blenderbim/test/bim/test_feature.py index 821d2d484d..5cbdf39897 100644 --- a/src/blenderbim/test/bim/test_feature.py +++ b/src/blenderbim/test/bim/test_feature.py @@ -159,6 +159,21 @@ def i_add_a_plane_of_size_size_at_location(size, location): bpy.ops.mesh.primitive_plane_add(size=float(size), location=[float(co) for co in location.split(",")]) +@then(parsers.parse('I press "{operator}" and expect error "{error_msg}"')) +def i_press_operator_and_expect_error(operator, error_msg): + operator = replace_variables(operator) + try: + if "(" in operator: + exec(f"bpy.ops.{operator}") + else: + exec(f"bpy.ops.{operator}()") + assert False, f"Operator bpy.ops.{operator} ran without exception '{error_msg}'" + except Exception as e: + actual_error_msg = str(e).strip() + if str(e).strip() != error_msg: + traceback.print_exc() + assert False, f"Got different exception running bpy.ops.{operator} - '{actual_error_msg}' instead of '{error_msg}'" + @given(parsers.parse('I press "{operator}"')) @when(parsers.parse('I press "{operator}"')) def i_press_operator(operator):