diff --git a/src/ifcbimtester/bimtester/features/steps/steps.py b/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses.py similarity index 59% rename from src/ifcbimtester/bimtester/features/steps/steps.py rename to src/ifcbimtester/bimtester/features/steps/attributes_eleclasses.py index f63a470fd2..43cee4e9e5 100644 --- a/src/ifcbimtester/bimtester/features/steps/steps.py +++ b/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses.py @@ -18,22 +18,6 @@ def step_impl(context, ifc_class, pattern): assert False -@step("all {ifc_class} elements have a {qto_name}.{quantity_name} quantity") -def step_impl(context, ifc_class, qto_name, quantity_name): - elements = IfcFile.get().by_type(ifc_class) - for element in elements: - is_successful = False - if not element.IsDefinedBy: - assert False - for relationship in element.IsDefinedBy: - if relationship.RelatingPropertyDefinition.Name == qto_name: - for quantity in relationship.RelatingPropertyDefinition.Quantities: - if quantity.Name == quantity_name: - is_successful = True - if not is_successful: - assert False - - @step('there is an {ifc_class} element with a {attribute_name} attribute with a value of "{attribute_value}"') def step_impl(context, ifc_class, attribute_name, attribute_value): elements = IfcFile.get().by_type(ifc_class) @@ -57,33 +41,6 @@ def step_impl(context, ifc_class, attribute): assert False -@step("all (?P.*) elements have an? (?P.*\..*) property") -def step_impl(context, ifc_class, property_path): - pset_name, property_name = property_path.split(".") - elements = IfcFile.get().by_type(ifc_class) - for element in elements: - if not IfcFile.get_property(element, pset_name, property_name): - assert False - - -@step( - 'all (?P.*) elements have an? (?P.*\..*) property value matching the pattern "(?P.*)"' -) -def step_impl(context, ifc_class, property_path, pattern): - import re - - pset_name, property_name = property_path.split(".") - elements = IfcFile.get().by_type(ifc_class) - for element in elements: - prop = IfcFile.get_property(element, pset_name, property_name) - if not prop: - assert False - # For now, we only check single values - if prop.is_a("IfcPropertySingleValue"): - if not (prop.NominalValue and re.search(pattern, prop.NominalValue.wrappedValue)): - assert False - - @step('all (?P.*) elements have an? (?P.*) matching the pattern "(?P.*)"') def step_impl(context, ifc_class, attribute, pattern): import re diff --git a/src/ifcbimtester/bimtester/features/steps/attributes_psets.py b/src/ifcbimtester/bimtester/features/steps/attributes_psets.py new file mode 100644 index 0000000000..9d46a6cc14 --- /dev/null +++ b/src/ifcbimtester/bimtester/features/steps/attributes_psets.py @@ -0,0 +1,36 @@ +from behave import step + +from utils import IfcFile + + +# ------------------------------------------------------------------------ +# STEPS with Regular Expression Matcher ("re") +# ------------------------------------------------------------------------ +use_step_matcher("re") + + +@step("all (?P.*) elements have an? (?P.*\..*) property") +def step_impl(context, ifc_class, property_path): + pset_name, property_name = property_path.split(".") + elements = IfcFile.get().by_type(ifc_class) + for element in elements: + if not IfcFile.get_property(element, pset_name, property_name): + assert False + + +@step( + 'all (?P.*) elements have an? (?P.*\..*) property value matching the pattern "(?P.*)"' +) +def step_impl(context, ifc_class, property_path, pattern): + import re + + pset_name, property_name = property_path.split(".") + elements = IfcFile.get().by_type(ifc_class) + for element in elements: + prop = IfcFile.get_property(element, pset_name, property_name) + if not prop: + assert False + # For now, we only check single values + if prop.is_a("IfcPropertySingleValue"): + if not (prop.NominalValue and re.search(pattern, prop.NominalValue.wrappedValue)): + assert False diff --git a/src/ifcbimtester/bimtester/features/steps/attributes_qsets.py b/src/ifcbimtester/bimtester/features/steps/attributes_qsets.py new file mode 100644 index 0000000000..85a2f3716c --- /dev/null +++ b/src/ifcbimtester/bimtester/features/steps/attributes_qsets.py @@ -0,0 +1,19 @@ +from behave import step + +from utils import IfcFile + + +@step("all {ifc_class} elements have a {qto_name}.{quantity_name} quantity") +def step_impl(context, ifc_class, qto_name, quantity_name): + elements = IfcFile.get().by_type(ifc_class) + for element in elements: + is_successful = False + if not element.IsDefinedBy: + assert False + for relationship in element.IsDefinedBy: + if relationship.RelatingPropertyDefinition.Name == qto_name: + for quantity in relationship.RelatingPropertyDefinition.Quantities: + if quantity.Name == quantity_name: + is_successful = True + if not is_successful: + assert False