From 6902e2e2c633dd0677764659bd3639b6617530fc Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Tue, 7 Dec 2021 15:47:15 +0100 Subject: [PATCH] bimtester: features, move geometric detail tests from examples to implemented steps --- .../bimtester/features/steps/all.py | 4 +- .../features/steps/geometric_detail/de.py | 6 ++ .../features/steps/geometric_detail/en.py | 66 +++++++++++++++++++ .../examples/steps/geometric_detail.py | 19 ------ .../examples/steps/geometric_detail_de.py | 17 ----- .../steps/geometric_detail_methods.py | 58 ---------------- 6 files changed, 74 insertions(+), 96 deletions(-) create mode 100644 src/ifcbimtester/bimtester/features/steps/geometric_detail/de.py delete mode 100644 src/ifcbimtester/examples/steps/geometric_detail.py delete mode 100644 src/ifcbimtester/examples/steps/geometric_detail_de.py delete mode 100644 src/ifcbimtester/examples/steps/geometric_detail_methods.py diff --git a/src/ifcbimtester/bimtester/features/steps/all.py b/src/ifcbimtester/bimtester/features/steps/all.py index d83f59fc09..ee348bf48c 100644 --- a/src/ifcbimtester/bimtester/features/steps/all.py +++ b/src/ifcbimtester/bimtester/features/steps/all.py @@ -5,7 +5,7 @@ use_step_matcher("parse") from bimtester.features.steps.application import en use_step_matcher("parse") -from bimtester.features.steps.attributes_eleclasses import en, de +from bimtester.features.steps.attributes_eleclasses import de, en use_step_matcher("parse") from bimtester.features.steps.attributes_psets import en, de @@ -26,7 +26,7 @@ use_step_matcher("parse") from bimtester.features.steps.geolocation import en use_step_matcher("parse") -from bimtester.features.steps.geometric_detail import en +from bimtester.features.steps.geometric_detail import de, en use_step_matcher("parse") from bimtester.features.steps.model_federation import en diff --git a/src/ifcbimtester/bimtester/features/steps/geometric_detail/de.py b/src/ifcbimtester/bimtester/features/steps/geometric_detail/de.py new file mode 100644 index 0000000000..88977932e7 --- /dev/null +++ b/src/ifcbimtester/bimtester/features/steps/geometric_detail/de.py @@ -0,0 +1,6 @@ +from behave import step + + +@step("Alle {ifc_class} Bauteile müssen eine geometrische Repräsentation der Klasse {representation_class} verwenden") +def step_impl(context, ifc_class, representation_class): + context.execute_steps(f'* All {ifc_class} elements have an "{representation_class}" representation') diff --git a/src/ifcbimtester/bimtester/features/steps/geometric_detail/en.py b/src/ifcbimtester/bimtester/features/steps/geometric_detail/en.py index 3e2e6c948b..141c751411 100644 --- a/src/ifcbimtester/bimtester/features/steps/geometric_detail/en.py +++ b/src/ifcbimtester/bimtester/features/steps/geometric_detail/en.py @@ -28,3 +28,69 @@ def step_impl(context, number): for error in errors: message += "Polygons: {} - {}\n".format(error[0], error[1]) assert False, message + + +@step('All "{ifc_class}" elements have an "{representation_class}" representation') +def step_impl(context, ifc_class, representation_class): + eleclass_has_geometric_representation_of_specific_class( + context, + ifc_class, + representation_class + ) + + +# ************************************************************************************************ +# helper +def eleclass_has_geometric_representation_of_specific_class( + context, + ifc_class, + representation_class +): + + def is_item_a_representation(item, representation): + if "/" in representation: + for cls in representation.split("/"): + if item.is_a(cls): + return True + elif item.is_a(representation): + return True + + context.falseelems = [] + context.falseguids = [] + context.falseprops = {} + rep = None + + elements = IfcStore.file.by_type(ifc_class) + for elem in elements: + if not elem.Representation: + continue + has_representation = False + for representation in elem.Representation.Representations: + for item in representation.Items: + if item.is_a("IfcMappedItem"): + # We only check one more level deep. + for item2 in item.MappingSource.MappedRepresentation.Items: + if is_item_a_representation(item2, representation_class): + has_representation = True + rep = item2 + else: + if is_item_a_representation(item, representation_class): + has_representation = True + rep = item + if not has_representation: + context.falseelems.append(str(elem)) + context.falseguids.append(elem.GlobalId) + context.falseprops[elem.id()] = str(rep) + + context.elemcount = len(elements) + context.falsecount = len(context.falseelems) + util.assert_elements( + ifc_class, + context.elemcount, + context.falsecount, + context.falseelems, + message_all_falseelems=_("All {elemcount} {ifc_class} elements are not a {parameter} representation."), + message_some_falseelems=_("The following {falsecount} of {elemcount} {ifc_class} elements are not a {parameter} representation: {falseelems}"), + message_no_elems=_("There are no {ifc_class} elements in the IFC file."), + parameter=representation_class + ) diff --git a/src/ifcbimtester/examples/steps/geometric_detail.py b/src/ifcbimtester/examples/steps/geometric_detail.py deleted file mode 100644 index b98987d7e3..0000000000 --- a/src/ifcbimtester/examples/steps/geometric_detail.py +++ /dev/null @@ -1,19 +0,0 @@ -from behave import step - -import geometric_detail_methods as gdm -from utils import assert_elements -from utils import IfcFile -from utils import switch_locale - - -the_lang = "en" - - -@step("all {ifc_class} elements have an {representation_class} representation") -def step_impl(context, ifc_class, representation_class): - switch_locale(context.localedir, the_lang) - gdm.eleclass_has_geometric_representation_of_specific_class( - context, - ifc_class, - representation_class - ) diff --git a/src/ifcbimtester/examples/steps/geometric_detail_de.py b/src/ifcbimtester/examples/steps/geometric_detail_de.py deleted file mode 100644 index 92c2f9a94c..0000000000 --- a/src/ifcbimtester/examples/steps/geometric_detail_de.py +++ /dev/null @@ -1,17 +0,0 @@ -from behave import step - -import geometric_detail_methods as gdm -from utils import switch_locale - - -the_lang = "de" - - -@step("Alle {ifc_class} Bauteile müssen eine geometrische Repräsentation der Klasse {representation_class} verwenden") -def step_impl(context, ifc_class, representation_class): - switch_locale(context.localedir, the_lang) - gdm.eleclass_has_geometric_representation_of_specific_class( - context, - ifc_class, - representation_class - ) diff --git a/src/ifcbimtester/examples/steps/geometric_detail_methods.py b/src/ifcbimtester/examples/steps/geometric_detail_methods.py deleted file mode 100644 index c66e179f05..0000000000 --- a/src/ifcbimtester/examples/steps/geometric_detail_methods.py +++ /dev/null @@ -1,58 +0,0 @@ -import gettext # noqa -from utils import assert_elements -from utils import IfcFile - - -def eleclass_has_geometric_representation_of_specific_class( - context, - ifc_class, - representation_class -): - - def is_item_a_representation(item, representation): - if "/" in representation: - for cls in representation.split("/"): - if item.is_a(cls): - return True - elif item.is_a(representation): - return True - - context.falseelems = [] - context.falseguids = [] - context.falseprops = {} - rep = None - - elements = IfcFile.get().by_type(ifc_class) - for elem in elements: - if not elem.Representation: - continue - has_representation = False - for representation in elem.Representation.Representations: - for item in representation.Items: - if item.is_a("IfcMappedItem"): - # We only check one more level deep. - for item2 in item.MappingSource.MappedRepresentation.Items: - if is_item_a_representation(item2, representation_class): - has_representation = True - rep = item2 - else: - if is_item_a_representation(item, representation_class): - has_representation = True - rep = item - if not has_representation: - context.falseelems.append(str(elem)) - context.falseguids.append(elem.GlobalId) - context.falseprops[elem.id()] = str(rep) - - 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 not a {parameter} representation."), - message_some_falseelems=_("The following {falsecount} of {elemcount} {ifc_class} elements are not a {parameter} representation: {falseelems}"), - message_no_elems=_("There are no {ifc_class} elements in the IFC file."), - parameter=representation_class - )