from behave import step from utils import IfcFile use_step_matcher("re") @step("all (?P.*) elements have an? (?P.*) attribute") def step_impl(context, ifc_class, attribute): elements = IfcFile.get().by_type(ifc_class) for element in elements: if not getattr(element, attribute): assert False @step('all (?P.*) elements have an? (?P.*) matching the pattern "(?P.*)"') def step_impl(context, ifc_class, attribute, pattern): import re elements = IfcFile.get().by_type(ifc_class) for element in elements: value = getattr(element, attribute) print(f'Checking value "{value}" for {element}') assert re.search(pattern, value) @step('all (?P.*) elements have an? (?P.*) taken from the list in "(?P.*)"') def step_impl(context, ifc_class, attributes, list_file): import csv values = [] with open(list_file) as csvfile: reader = csv.reader(csvfile) for row in reader: values.append(row) elements = IfcFile.get().by_type(ifc_class) for element in elements: attribute_values = [] for attribute in attributes.split(","): if not hasattr(element, attribute): assert False, f"Failed at element {element.GlobalId}" attribute_values.append(getattr(element, attribute)) if attribute_values not in values: assert False, f"Failed at element {element.GlobalId}"