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

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

54 lines
1.7 KiB
Python
Raw Normal View History

2020-12-21 16:32:36 +01:00
from behave import step
2021-01-07 17:54:39 +01:00
import attributes_psets_methods as apm
2020-12-22 14:34:04 +01:00
from utils import assert_elements
2020-12-21 16:32:36 +01:00
from utils import IfcFile
2020-12-22 14:34:04 +01:00
from utils import switch_locale
2021-01-07 18:02:09 +01:00
the_lang = "en"
2020-12-22 14:34:04 +01:00
@step("all {ifc_class} elements have an {aproperty} property in the {pset} pset")
def step_impl(context, ifc_class, aproperty, pset):
2021-01-07 18:02:09 +01:00
switch_locale(context.localedir, the_lang)
2021-01-07 17:54:39 +01:00
apm.eleclass_has_property_in_pset(
context,
ifc_class,
aproperty,
pset
)
2020-12-21 16:32:36 +01:00
# ------------------------------------------------------------------------
# STEPS with Regular Expression Matcher ("re")
# ------------------------------------------------------------------------
use_step_matcher("re")
@step("all (?P<ifc_class>.*) elements have an? (?P<property_path>.*\..*) 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<ifc_class>.*) elements have an? (?P<property_path>.*\..*) property value matching the pattern "(?P<pattern>.*)"'
)
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