Files
IfcOpenShell/src/ifcbimtester/examples/steps/attributes_eleclasses.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
1.5 KiB
Python
Raw Normal View History

from behave import step
2020-11-26 08:08:38 +01:00
from utils import IfcFile
2021-01-07 18:02:09 +01:00
use_step_matcher("re")
2020-11-01 19:22:49 +07:00
@step("all (?P<ifc_class>.*) elements have an? (?P<attribute>.*) 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<ifc_class>.*) elements have an? (?P<attribute>.*) matching the pattern "(?P<pattern>.*)"')
def step_impl(context, ifc_class, attribute, pattern):
import re
2020-11-01 19:22:49 +07:00
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<ifc_class>.*) elements have an? (?P<attributes>.*) taken from the list in "(?P<list_file>.*)"')
def step_impl(context, ifc_class, attributes, list_file):
import csv
2020-11-01 19:22:49 +07:00
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}"