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):