From edd6e74813c2259d1b1c77fa01e814485ae29fd6 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Mon, 21 Dec 2020 17:01:28 +0100 Subject: [PATCH] bimtester: steps, add element class attributes test --- .../features/steps/attributes_eleclasses.py | 7 +++ .../steps/attributes_eleclasses_methods.py | 44 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses.py b/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses.py index c39467568f..0112e170a9 100644 --- a/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses.py +++ b/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses.py @@ -1,5 +1,6 @@ from behave import step +from attributes_eleclasses_methods import all_element_attribs_have_a_value from attributes_eleclasses_methods import no_element_class_ele from utils import IfcFile @@ -10,6 +11,12 @@ def step_impl(context, ifc_class, reason): no_element_class_ele(context, ifc_class, reason) +@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) + + @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 ddd1238d9f..b48ab29438 100644 --- a/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses_methods.py +++ b/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses_methods.py @@ -1,4 +1,5 @@ import gettext # noqa + from utils import assert_elements from utils import IfcFile @@ -39,3 +40,46 @@ def no_element_class_ele(context, ifc_class, reason): ) else: assert False, _("Error in falsecount, something went wrong.") + + +def all_element_attribs_have_a_value(context, ifc_class): + + from ifcopenshell.ifcopenshell_wrapper import schema_by_name + # schema = schema_by_name("IFC2X3") + schema = schema_by_name(IfcFile.get().schema) + class_attributes = [] + for cl_attrib in schema.declaration_by_name(ifc_class).all_attributes(): + class_attributes.append(cl_attrib.name()) + # print(class_attributes) + + context.falseelems = [] + context.falseguids = [] + context.falseprops = {} + + elements = IfcFile.get().by_type(ifc_class) + for elem in elements: + failed_attribs = [] + elem_failed = False + for cl_attrib in class_attributes: + attrib_value = getattr(elem, cl_attrib) + if not attrib_value: + elem_failed = True + failed_attribs.append(cl_attrib) + # print(attrib_value) + if elem_failed is True: + context.falseelems.append(str(elem)) + context.falseguids.append(elem.GlobalId) + context.falseprops[elem.id()] = failed_attribs + + context.elemcount = len(elements) + context.falsecount = len(context.falseelems) + assert_elements( + ifc_class, + context.elemcount, + context.falsecount, + context.falseelems, + message_all_falseelems=_("For all {elemcount} {ifc_class} elements at least one of these class attributes {parameter} has no value."), + message_some_falseelems=_("For the following {falsecount} out of {elemcount} {ifc_class} elements at least one of these class attributes {parameter} has no value: {falseelems}"), + message_no_elems=_("There are no {ifc_class} elements in the IFC file."), + parameter=failed_attribs + )