2020-04-02 18:38:42 +11:00
|
|
|
from behave import step
|
2020-11-26 08:08:38 +01:00
|
|
|
|
2020-12-21 17:01:28 +01:00
|
|
|
from attributes_eleclasses_methods import all_element_attribs_have_a_value
|
2020-12-22 14:34:04 +01:00
|
|
|
from attributes_eleclasses_methods import name_has_a_value
|
|
|
|
|
from attributes_eleclasses_methods import description_has_a_value
|
2020-12-21 16:57:38 +01:00
|
|
|
from attributes_eleclasses_methods import no_element_class_ele
|
2020-12-22 14:34:04 +01:00
|
|
|
from utils import assert_elements
|
2020-07-27 18:38:13 +10:00
|
|
|
from utils import IfcFile
|
2020-12-21 17:09:46 +01:00
|
|
|
from utils import switch_locale
|
2020-04-06 11:59:28 +10:00
|
|
|
|
2020-11-01 19:22:49 +07:00
|
|
|
|
2020-04-02 18:38:42 +11:00
|
|
|
@step("there are no {ifc_class} elements because {reason}")
|
2020-03-06 11:35:05 +11:00
|
|
|
def step_impl(context, ifc_class, reason):
|
2020-12-21 16:57:38 +01:00
|
|
|
switch_locale(context.localedir, "en")
|
|
|
|
|
no_element_class_ele(context, ifc_class, reason)
|
2020-03-06 11:35:05 +11:00
|
|
|
|
|
|
|
|
|
2020-12-21 17:01:28 +01:00
|
|
|
@step('all {ifc_class} elements class attributes have a value')
|
|
|
|
|
def step_impl(context, ifc_class):
|
|
|
|
|
switch_locale(context.localedir, "en")
|
|
|
|
|
all_element_attribs_have_a_value(context, ifc_class)
|
|
|
|
|
|
|
|
|
|
|
2020-12-22 14:34:04 +01:00
|
|
|
@step('all {ifc_class} elements have a name given')
|
|
|
|
|
def step_impl(context, ifc_class):
|
|
|
|
|
switch_locale(context.localedir, "en")
|
|
|
|
|
name_has_a_value(context, ifc_class)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@step('all {ifc_class} elements have a description given')
|
|
|
|
|
def step_impl(context, ifc_class):
|
|
|
|
|
switch_locale(context.localedir, "en")
|
|
|
|
|
description_has_a_value(context, ifc_class)
|
|
|
|
|
|
|
|
|
|
|
2020-04-02 18:38:42 +11:00
|
|
|
@step('all {ifc_class} elements have a name matching the pattern "{pattern}"')
|
2020-01-02 13:01:17 +11:00
|
|
|
def step_impl(context, ifc_class, pattern):
|
|
|
|
|
import re
|
2020-11-01 19:22:49 +07:00
|
|
|
|
2020-01-02 13:01:17 +11:00
|
|
|
elements = IfcFile.get().by_type(ifc_class)
|
|
|
|
|
for element in elements:
|
|
|
|
|
if not re.search(pattern, element.Name):
|
|
|
|
|
assert False
|
|
|
|
|
|
|
|
|
|
|
2020-12-21 16:07:08 +01:00
|
|
|
@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)
|
|
|
|
|
for element in elements:
|
|
|
|
|
if hasattr(element, attribute_name) and getattr(element, attribute_name) == attribute_value:
|
|
|
|
|
return
|
|
|
|
|
assert False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------
|
|
|
|
|
# STEPS with Regular Expression Matcher ("re")
|
|
|
|
|
# ------------------------------------------------------------------------
|
2020-01-02 13:01:17 +11:00
|
|
|
use_step_matcher("re")
|
2020-11-01 19:22:49 +07:00
|
|
|
|
|
|
|
|
|
2020-04-02 18:38:42 +11:00
|
|
|
@step("all (?P<ifc_class>.*) elements have an? (?P<attribute>.*) attribute")
|
2020-01-02 13:01:17 +11:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2020-04-02 18:38:42 +11:00
|
|
|
@step('all (?P<ifc_class>.*) elements have an? (?P<attribute>.*) matching the pattern "(?P<pattern>.*)"')
|
2020-01-16 17:55:37 +11:00
|
|
|
def step_impl(context, ifc_class, attribute, pattern):
|
|
|
|
|
import re
|
2020-11-01 19:22:49 +07:00
|
|
|
|
2020-01-16 17:55:37 +11: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)
|
2020-01-02 13:01:17 +11:00
|
|
|
|
|
|
|
|
|
2020-04-02 18:38:42 +11:00
|
|
|
@step('all (?P<ifc_class>.*) elements have an? (?P<attributes>.*) taken from the list in "(?P<list_file>.*)"')
|
2020-02-18 14:03:32 +11:00
|
|
|
def step_impl(context, ifc_class, attributes, list_file):
|
|
|
|
|
import csv
|
2020-11-01 19:22:49 +07:00
|
|
|
|
2020-02-18 14:03:32 +11: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}"
|