From 43f8d8547d6395e6bc2f57c08016d16ab453b6ce Mon Sep 17 00:00:00 2001 From: Alexander Nitsch Date: Sun, 25 Jul 2021 01:57:59 +0200 Subject: [PATCH] Bimtester: Fixed attributes_psets step files (#1580) Co-authored-by: Nitsch Alexander --- .../bimtester/features/steps/all.py | 5 +- .../features/steps/attributes_psets/de.py | 8 ++ .../features/steps/attributes_psets/en.py | 80 +++++++++++++++++++ .../examples/steps/attributes_psets.py | 53 ------------ .../examples/steps/attributes_psets_de.py | 18 ----- .../examples/steps/attributes_psets_fr.py | 21 ----- .../steps/attributes_psets_methods.py | 36 --------- 7 files changed, 92 insertions(+), 129 deletions(-) create mode 100644 src/ifcbimtester/bimtester/features/steps/attributes_psets/de.py create mode 100644 src/ifcbimtester/bimtester/features/steps/attributes_psets/en.py delete mode 100644 src/ifcbimtester/examples/steps/attributes_psets.py delete mode 100644 src/ifcbimtester/examples/steps/attributes_psets_de.py delete mode 100644 src/ifcbimtester/examples/steps/attributes_psets_fr.py delete mode 100644 src/ifcbimtester/examples/steps/attributes_psets_methods.py diff --git a/src/ifcbimtester/bimtester/features/steps/all.py b/src/ifcbimtester/bimtester/features/steps/all.py index 7270814868..6fcb45d576 100644 --- a/src/ifcbimtester/bimtester/features/steps/all.py +++ b/src/ifcbimtester/bimtester/features/steps/all.py @@ -20,4 +20,7 @@ use_step_matcher("parse") from bimtester.features.steps.project_setup import de, en, fr, it, nl use_step_matcher("parse") -from bimtester.features.steps.aggregation import en \ No newline at end of file +from bimtester.features.steps.aggregation import en + +use_step_matcher("parse") +from bimtester.features.steps.attributes_psets import en, de diff --git a/src/ifcbimtester/bimtester/features/steps/attributes_psets/de.py b/src/ifcbimtester/bimtester/features/steps/attributes_psets/de.py new file mode 100644 index 0000000000..b9080143e8 --- /dev/null +++ b/src/ifcbimtester/bimtester/features/steps/attributes_psets/de.py @@ -0,0 +1,8 @@ +from behave import step, use_step_matcher + +use_step_matcher("parse") + + +@step("An alle {ifc_class} Bauteile ist im PSet {pset} das Attribut {aproperty} angehängt") +def step_impl(context, ifc_class, aproperty, pset): + context.execute_steps(f"all {ifc_class} elements have an {aproperty} property in the {pset} pset") diff --git a/src/ifcbimtester/bimtester/features/steps/attributes_psets/en.py b/src/ifcbimtester/bimtester/features/steps/attributes_psets/en.py new file mode 100644 index 0000000000..c8cdf7aa02 --- /dev/null +++ b/src/ifcbimtester/bimtester/features/steps/attributes_psets/en.py @@ -0,0 +1,80 @@ +from behave import step, use_step_matcher + +from bimtester.ifc import IfcStore +from bimtester.util import assert_elements +from bimtester.lang import _ + + +@step("all {ifc_class} elements have an {aproperty} property in the {pset} pset") +def step_impl(context, ifc_class, aproperty, pset): + eleclass_has_property_in_pset( + context, + ifc_class, + aproperty, + pset + ) + + +# ------------------------------------------------------------------------ +# STEPS with Regular Expression Matcher ("re") +# ------------------------------------------------------------------------ +use_step_matcher("re") + + +@step(r"all (?P.*) elements have an? (?P.*\..*) property") +def step_impl(context, ifc_class, property_path): + pset_name, property_name = property_path.split(".") + elements = IfcStore.file.by_type(ifc_class) + for element in elements: + if not IfcStore.file.get_property(element, pset_name, property_name): + assert False + + +@step( + r'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 = IfcStore.file.by_type(ifc_class) + for element in elements: + prop = IfcStore.file.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 + + +def eleclass_has_property_in_pset( + context, ifc_class, aproperty, pset +): + context.falseelems = [] + context.falseguids = [] + context.falseprops = {} + from ifcopenshell.util.element import get_psets + + elements = IfcStore.file.by_type(ifc_class) + for elem in elements: + psets = get_psets(elem) + if not (pset in psets and aproperty in psets[pset]): + context.falseelems.append(str(elem)) + context.falseguids.append(elem.GlobalId) + context.falseprops[elem.id()] = str(psets) + + context.elemcount = len(elements) + context.falsecount = len(context.falseelems) + assert_elements( + ifc_class, + context.elemcount, + context.falsecount, + context.falseelems, + # TODO: Translate these messages into other languages + message_all_falseelems=_("All {elemcount} {ifc_class} elements are missing the property {parameter} in the pset."), + message_some_falseelems=_("The following {falsecount} of {elemcount} {ifc_class} elements are missing the property {parameter} in the pset: {falseelems}"), + message_no_elems=_("There are no {ifc_class} elements in the IFC file."), + parameter=aproperty + ) + # the pset name is missing in the failing message, but it is in the step test name diff --git a/src/ifcbimtester/examples/steps/attributes_psets.py b/src/ifcbimtester/examples/steps/attributes_psets.py deleted file mode 100644 index 7eaa4cc596..0000000000 --- a/src/ifcbimtester/examples/steps/attributes_psets.py +++ /dev/null @@ -1,53 +0,0 @@ -from behave import step - -import attributes_psets_methods as apm -from utils import assert_elements -from utils import IfcFile -from utils import switch_locale - - -the_lang = "en" - - -@step("all {ifc_class} elements have an {aproperty} property in the {pset} pset") -def step_impl(context, ifc_class, aproperty, pset): - switch_locale(context.localedir, the_lang) - apm.eleclass_has_property_in_pset( - context, - ifc_class, - aproperty, - pset - ) - - -# ------------------------------------------------------------------------ -# 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/examples/steps/attributes_psets_de.py b/src/ifcbimtester/examples/steps/attributes_psets_de.py deleted file mode 100644 index 941350becd..0000000000 --- a/src/ifcbimtester/examples/steps/attributes_psets_de.py +++ /dev/null @@ -1,18 +0,0 @@ -from behave import step - -import attributes_psets_methods as apm -from utils import switch_locale - - -the_lang = "de" - - -@step("An alle {ifc_class} Bauteile ist im PSet {pset} das Attribut {aproperty} angehängt") -def step_impl(context, ifc_class, aproperty, pset): - switch_locale(context.localedir, the_lang) - apm.eleclass_has_property_in_pset( - context, - ifc_class, - aproperty, - pset - ) diff --git a/src/ifcbimtester/examples/steps/attributes_psets_fr.py b/src/ifcbimtester/examples/steps/attributes_psets_fr.py deleted file mode 100644 index 29030d583e..0000000000 --- a/src/ifcbimtester/examples/steps/attributes_psets_fr.py +++ /dev/null @@ -1,21 +0,0 @@ -from behave import step - -import attributes_psets_methods as apm -from utils import switch_locale - - -the_lang = "fr" - - -""" -# TODO the next line needs translation -@step("All {ifc_class} elements have an {aproperty} property in the {pset} pset") -def step_impl(context, ifc_class, aproperty, pset): - switch_locale(context.localedir, the_lang) - apm.eleclass_has_property_in_pset( - context, - ifc_class, - aproperty, - pset - ) -""" diff --git a/src/ifcbimtester/examples/steps/attributes_psets_methods.py b/src/ifcbimtester/examples/steps/attributes_psets_methods.py deleted file mode 100644 index 5e5fbfa08e..0000000000 --- a/src/ifcbimtester/examples/steps/attributes_psets_methods.py +++ /dev/null @@ -1,36 +0,0 @@ -import gettext # noqa - -from utils import assert_elements -from utils import IfcFile - - -def eleclass_has_property_in_pset( - context, ifc_class, aproperty, pset -): - - context.falseelems = [] - context.falseguids = [] - context.falseprops = {} - from ifcopenshell.util.element import get_psets - - elements = IfcFile.get().by_type(ifc_class) - for elem in elements: - psets = get_psets(elem) - if not (pset in psets and aproperty in psets[pset]): - context.falseelems.append(str(elem)) - context.falseguids.append(elem.GlobalId) - context.falseprops[elem.id()] = str(psets) - - context.elemcount = len(elements) - context.falsecount = len(context.falseelems) - assert_elements( - ifc_class, - context.elemcount, - context.falsecount, - context.falseelems, - message_all_falseelems=_("All {elemcount} {ifc_class} elements are missing the property {parameter} in the pset."), - message_some_falseelems=_("The following {falsecount} of {elemcount} {ifc_class} elements are missing the property {parameter} in the pset: {falseelems}"), - message_no_elems=_("There are no {ifc_class} elements in the IFC file."), - parameter=aproperty - ) - # the pset name is missing in the failing message, but it is in the step test name