From 6d47cf3a518a6ab9ff54ff657e1afe5a99e648ed Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Tue, 7 Dec 2021 18:01:10 +0100 Subject: [PATCH] bimtester, attributes ele class steps, use generic assert methond --- .../steps/attributes_eleclasses/en.py | 75 +++++-------------- src/ifcbimtester/bimtester/util.py | 6 +- 2 files changed, 22 insertions(+), 59 deletions(-) diff --git a/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses/en.py b/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses/en.py index 5b183689e5..5c913184cd 100644 --- a/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses/en.py +++ b/src/ifcbimtester/bimtester/features/steps/attributes_eleclasses/en.py @@ -95,36 +95,18 @@ def only_eleclasses( if elem.is_a() not in target_ifc_classes: context.falseelems.append(str(elem)) context.falseguids.append(elem.GlobalId) - - out_falseelems = "\n" - for e in context.falseelems: - out_falseelems += e + "\n" context.falsecount = len(context.falseelems) - # print(context.falsecount) - # print(context.elemcount) - if context.falsecount == 0: - return # Test OK, thus we can not use the assert_elements method ... really ? - elif context.falsecount == context.elemcount: - assert False, ( - _("All {elemcount} false elements in the file are {ifc_classes}.") - .format( - elemcount=context.elemcount, - ifc_classes=ifc_classes - ) - ) - elif context.falsecount > 0 and context.falsecount < context.elemcount: - assert False, ( - _("{falsecount} of {elemcount} false_elements are {ifc_classes} false_elements: {falseelems}") - .format( - falsecount=context.falsecount, - elemcount=context.elemcount, - ifc_classes=ifc_classes, - falseelems=out_falseelems, - ) - ) - else: - assert False, _("Error in falsecount, something went wrong.") + # use ifc_classes in method parameter but ifc_class in string parameter + # be careful somehow the opposite of most other tests is tested + util.assert_elements( + ifc_classes, + context.elemcount, + context.falsecount, + context.falseelems, + message_all_falseelems=_("All {elemcount} elements in the file are not {ifc_class} elements."), + message_some_falseelems=_("{falsecount} of {elemcount} false_elements are not {ifc_class} elements: {falseelems}"), + ) def no_eleclass( @@ -139,36 +121,17 @@ def no_eleclass( for elem in elements: context.falseelems.append(str(elem)) context.falseguids.append(elem.GlobalId) - - out_falseelems = "\n" - for e in context.falseelems: - out_falseelems += e + "\n" context.falsecount = len(context.falseelems) - # print(context.falsecount) - # print(context.elemcount) - if context.falsecount == 0: - return # Test OK, thus we can not use the assert_elements method ... really ? - elif context.falsecount == context.elemcount: - assert False, ( - _("All {elemcount} elements in the file are {ifc_class}.") - .format( - elemcount=context.elemcount, - ifc_class=ifc_class - ) - ) - elif context.falsecount > 0 and context.falsecount < context.elemcount: - assert False, ( - _("{falsecount} of {elemcount} elements are {ifc_class} elements: {falseelems}") - .format( - falsecount=context.falsecount, - elemcount=context.elemcount, - ifc_class=ifc_class, - falseelems=out_falseelems, - ) - ) - else: - assert False, _("Error in falsecount, something went wrong.") + # be careful somehow the opposite of most other tests is tested + util.assert_elements( + ifc_class, + context.elemcount, + context.falsecount, + context.falseelems, + message_all_falseelems=_("All {elemcount} elements in the file are {ifc_class} elements."), + message_some_falseelems=_("{falsecount} of {elemcount} false_elements are {ifc_class} elements: {falseelems}"), + ) def eleclass_have_class_attributes_with_a_value( diff --git a/src/ifcbimtester/bimtester/util.py b/src/ifcbimtester/bimtester/util.py index 248b344413..bc75a2117a 100644 --- a/src/ifcbimtester/bimtester/util.py +++ b/src/ifcbimtester/bimtester/util.py @@ -94,7 +94,7 @@ def assert_elements( falseelems, message_all_falseelems, message_some_falseelems, - message_no_elems, + message_no_elems="", parameter=None ): out_falseelems = "\n" @@ -112,7 +112,7 @@ def assert_elements( # ) # ) if falsecount == 0: - return # test ok for elemcount == 0 !!! + return # test ok for elemcount == 0 and elemcount > 0 elif falsecount == elemcount: if parameter is None: assert False, ( @@ -150,4 +150,4 @@ def assert_elements( ) ) else: - assert False, _("Error in falsecount, something went wrong.") + assert False, _("Error in falsecount calculation, something went wrong.")