From 4df8418e72c83da3548c343c1d554f47370d4545 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Tue, 22 Dec 2020 14:34:04 +0100 Subject: [PATCH] bimtester: steps, add more attributes tests --- .../features/steps/attributes_eleclasses.py | 15 ++++++ .../steps/attributes_eleclasses_methods.py | 50 +++++++++++++++++++ .../features/steps/attributes_psets.py | 9 ++++ .../steps/attributes_psets_methods.py | 34 +++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 src/ifcbimtester/bimtester/features/steps/attributes_psets_methods.py diff --git a/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses.py b/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses.py index d63ca60d2f..b3b6b7d236 100644 --- a/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses.py +++ b/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses.py @@ -1,7 +1,10 @@ from behave import step from attributes_eleclasses_methods import all_element_attribs_have_a_value +from attributes_eleclasses_methods import name_has_a_value +from attributes_eleclasses_methods import description_has_a_value from attributes_eleclasses_methods import no_element_class_ele +from utils import assert_elements from utils import IfcFile from utils import switch_locale @@ -18,6 +21,18 @@ def step_impl(context, ifc_class): all_element_attribs_have_a_value(context, ifc_class) +@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) + + @step('all {ifc_class} elements have a name matching the pattern "{pattern}"') def step_impl(context, ifc_class, pattern): import re diff --git a/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses_methods.py b/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses_methods.py index 03cfd5f437..0588bd3d2f 100644 --- a/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses_methods.py +++ b/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses_methods.py @@ -82,3 +82,53 @@ def all_element_attribs_have_a_value(context, ifc_class): message_no_elems=_("There are no {ifc_class} elements in the IFC file."), parameter=failed_attribs ) + + +def name_has_a_value(context, ifc_class): + + context.falseelems = [] + context.falseguids = [] + + elements = IfcFile.get().by_type(ifc_class) + for elem in elements: + # print(elem.Name) + if not elem.Name: + context.falseelems.append(str(elem)) + context.falseguids.append(elem.GlobalId) + + context.elemcount = len(elements) + context.falsecount = len(context.falseelems) + assert_elements( + ifc_class, + context.elemcount, + context.falsecount, + context.falseelems, + message_all_falseelems=_("The name of all {elemcount} {elemcount} elements is not set."), + message_some_falseelems=_("The name of {falsecount} out of {elemcount} {ifc_class} elements is not set: {falseelems}"), + message_no_elems=_("There are no {ifc_class} elements in the IFC file."), + ) + + +def description_has_a_value(context, ifc_class): + + context.falseelems = [] + context.falseguids = [] + + elements = IfcFile.get().by_type(ifc_class) + for elem in elements: + # print(elem.Description) + if not elem.Description: + context.falseelems.append(str(elem)) + context.falseguids.append(elem.GlobalId) + + context.elemcount = len(elements) + context.falsecount = len(context.falseelems) + assert_elements( + ifc_class, + context.elemcount, + context.falsecount, + context.falseelems, + message_all_falseelems=_("The description of all {elemcount} {elemcount} elements is not set."), + message_some_falseelems=_("The description of {falsecount} out of {elemcount} {ifc_class} elements is not set: {falseelems}"), + message_no_elems=_("There are no {ifc_class} elements in the IFC file."), + ) diff --git a/src/ifcbimtester/bimtester/features/steps/attributes_psets.py b/src/ifcbimtester/bimtester/features/steps/attributes_psets.py index 9d46a6cc14..124c54467a 100644 --- a/src/ifcbimtester/bimtester/features/steps/attributes_psets.py +++ b/src/ifcbimtester/bimtester/features/steps/attributes_psets.py @@ -1,6 +1,15 @@ from behave import step +from attributes_psets_methods import all_eleclass_elements_have_prop_in_pset +from utils import assert_elements from utils import IfcFile +from utils import switch_locale + + +@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, "en") + all_eleclass_elements_have_prop_in_pset(context, ifc_class, aproperty, pset) # ------------------------------------------------------------------------ diff --git a/src/ifcbimtester/bimtester/features/steps/attributes_psets_methods.py b/src/ifcbimtester/bimtester/features/steps/attributes_psets_methods.py new file mode 100644 index 0000000000..61c707b6da --- /dev/null +++ b/src/ifcbimtester/bimtester/features/steps/attributes_psets_methods.py @@ -0,0 +1,34 @@ +import gettext # noqa + +from utils import assert_elements +from utils import IfcFile + + +def all_eleclass_elements_have_prop_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