1- # BIMTester - OpenBIM Auditing Tool
2- # Copyright (C) 2021 Dion Moult <[email protected] > 3- #
4- # This file is part of BIMTester.
5- #
6- # BIMTester is free software: you can redistribute it and/or modify
7- # it under the terms of the GNU Lesser General Public License as published by
8- # the Free Software Foundation, either version 3 of the License, or
9- # (at your option) any later version.
10- #
11- # BIMTester is distributed in the hope that it will be useful,
12- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- # GNU Lesser General Public License for more details.
15- #
16- # You should have received a copy of the GNU Lesser General Public License
17- # along with BIMTester. If not, see <http://www.gnu.org/licenses/>.
18-
191import os
202from behave .model import Scenario
213
@@ -38,26 +20,55 @@ def before_all(context):
3820 if context .config .lang :
3921 switch_locale (context .locale_dir , context .config .lang )
4022
41- continue_after_failed = userdata .getbool ("runner.continue_after_failed_step" , True )
42- Scenario .continue_after_failed_step = continue_after_failed
23+ # continue_after_failed = userdata.getbool("runner.continue_after_failed_step", True)
24+ Scenario .continue_after_failed_step = False
25+ # for some Scenarios True would be better, may be dependend on the Scenario name as a workaround
4326
4427 # context.ifc_path = userdata.get("ifc", "")
45- context .ifcfile_basename = os .path .basename (os .path .splitext (userdata ["ifc" ])[0 ])
28+ context .ifcfile_basename = os .path .basename (
29+ os .path .splitext (userdata ["ifc" ])[0 ]
30+ )
4631 context .outpath = os .path .join (this_path , ".." )
47- context .create_log = False
48- context .create_smartview = False
32+ context .create_log = True
33+ context .create_smartview = True
4934
5035 if context .create_log is True :
5136 # set up log file
52- context .thelogfile = os .path .join (context .outpath , context .ifcfile_basename + ".log" )
37+ context .thelogfile = os .path .join (
38+ context .outpath ,
39+ context .ifcfile_basename + ".log"
40+ )
5341 create_logfile (
5442 context .thelogfile ,
5543 context .ifcfile_basename ,
5644 )
5745
46+ # we have to use a dict to preserve the contents
47+ # https://stackoverflow.com/a/67606164
48+ context .skip_all_other_features = {"skip" : False }
49+
50+ # elements count container
51+ context .elecount_data = []
52+
53+
54+ def after_all (context ):
55+ import json
56+ # print(json.dumps(context.elecount_data, indent=4, ensure_ascii=False))
57+ import yaml
58+ yf = open (os .path .join (context .outpath , "elecount.yaml" ), "w" , encoding = "utf-8" )
59+ # yaml schreibt strings ohne quotes, heisst 1.0.0 wird dann als float wieder eingelesen
60+ # daher alle werte mit quote schreiben ... default_style='"'
61+ # https://stackoverflow.com/a/69850618
62+ yaml .safe_dump (context .elecount_data , yf , default_flow_style = False , allow_unicode = True , default_style = '"' )
63+ yaml .safe_dump (context .elecount_data , yf , default_flow_style = False , allow_unicode = True )
64+ yf .close ()
65+ print ("---E N D E---" )
66+
5867
5968def before_feature (context , feature ):
6069
70+ print ("Start feature: {}" .format (feature .name ))
71+
6172 # https://github.com/IfcOpenShell/IfcOpenShell/issues/1910#issuecomment-989732600
6273 # messages language, parsed by behaves lang argument
6374 print ("Messages language: {}" .format (context .config .lang ))
@@ -74,19 +85,109 @@ def before_feature(context, feature):
7485 # TODO: refactor zoom smart view support into a decoupled module
7586 if context .create_smartview is True :
7687 smartview_name = context .ifcfile_basename + "_" + feature .name
77- context .smview_file = os .path .join (context .outpath , smartview_name + ".bcsv" )
88+ context .smview_file = os .path .join (
89+ context .outpath ,
90+ smartview_name + ".bcsv"
91+ )
7892 # print("SmartView file: {}".format(context.smview_file))
7993 create_zoom_set_of_smartviews (
8094 context .smview_file ,
8195 smartview_name ,
8296 )
8397
98+ # print(context.skip_all_other_features)
99+ if context .skip_all_other_features ["skip" ] is True :
100+ feature .skip ("Due to a failing feature all other features are skipped." )
101+ return
102+ # https://stackoverflow.com/a/42721605
103+
104+
105+ def after_feature (context , feature ):
106+ print ("After feature: {} --> {}" .format (feature .name , feature .status ))
107+ # print(str(feature.status))
108+ # print(context.skip_all_other_features)
109+ # TODO: mit userdata bei start bimtester uebergeben
110+ #
111+ # Wenn allplan feature nicht erfuellt ist, sofort abbruch
112+ #
113+ features_to_continue = [
114+ "681_Weitere" ,
115+ # "682_Modellpruefungen_FBJ_Weitere_allplan",
116+ "683_Modellpruefungen_FBJ_Weitere_bimtester" ,
117+ "684_Modellpruefungen_FBJ_Geomqualitaet_bimtester" ,
118+ "686_Modellpruefungen_TRW_Weitere_bimtester" ,
119+ "891_Projektpruefungen_Allg" ,
120+ # "892_Projektpruefungen_TRW_allplan",
121+ "893_Projektpruefungen_TRW_bimtester" ,
122+ # "899_Projektpruefungen_Name",
123+ ]
124+ if str (feature .status ) == "Status.failed" and feature .name not in features_to_continue :
125+ # print("set to skip all other features")
126+ context .skip_all_other_features ["skip" ] = True
127+ # print(context.skip_all_other_features)
128+
129+
130+ # workaround to finish specific scenarios
131+ finish_scenario = [
132+ "Geometrieabmessungen Mauerwerk" ,
133+ "Geometriefehler" ,
134+ "Geometriequalität" ,
135+ "Regextests" ,
136+ ]
137+ def before_scenario (context , scenario ):
138+ # print(scenario.name)
139+ if scenario .name in finish_scenario :
140+ Scenario .continue_after_failed_step = True
141+ context .open_step_counter = 0
142+
143+
144+ def after_scenario (context , scenario ):
145+ # print(scenario.name)
146+ if scenario .name in finish_scenario :
147+ Scenario .continue_after_failed_step = False
148+ context .open_step_counter = 0
149+
150+
151+ def before_step (context , step ):
152+ # print("{}".format(step.name))
153+ context .open_step_counter += 1
84154
85155def after_step (context , step ):
86156
87157 if step .status == "failed" and context .create_log is True :
88158 append_logfile (context , step )
89159
90- if step .status == "failed" and context .create_smartview is True and hasattr (context , "falseguids" ):
160+ # Workaround: introduce a open_step_counter
161+ # only if the counter of not finished steps is 1 create a smart view
162+ # see https://github.com/behave/behave/issues/992
163+ # the German step starts, calls the english step
164+ # the English starts, fails, closes,
165+ # than the German fails and closes
166+ # thus both steps fail, thus both are in the smart view file
167+ if (
168+ step .status == "failed"
169+ and context .create_smartview is True
170+ and hasattr (context , "falseguids" )
171+ and context .open_step_counter == 1
172+ ):
173+ # print("\nDBG: {}, {}\n".format(step.name, context.open_step_counter))
91174 # print(context.falseguids)
92- add_smartview (context .smview_file , step .name , context .falseguids )
175+ add_smartview (
176+ context .smview_file ,
177+ step .name ,
178+ context .falseguids
179+ )
180+
181+ # elecount
182+ if hasattr (context , "elemcount" ):
183+ count = context .elemcount
184+ else :
185+ count = None
186+ context .elecount_data .append ([step .name , count ])
187+ # zuordnung step json und step elecount anstatt ueber name auch mit location moeglich
188+ # siehe json und dort den location string
189+ # damit keine umlaute etc ...
190+ # print(step.location)
191+
192+ context .open_step_counter -= 1
193+ print ("Finished step: {}" .format (step .name ))
0 commit comments