@@ -30,7 +30,12 @@ def run_tests(args):
3030 if args ["advanced_arguments" ]:
3131 behave_args .extend (args ["advanced_arguments" ].split ())
3232 elif not args ["console" ]:
33- behave_args .extend (["--format" , "json.pretty" , "--outfile" , "report/report.json" ])
33+ behave_args .extend ([
34+ "--format" ,
35+ "json.pretty" ,
36+ "--outfile" ,
37+ "report/report.json"
38+ ])
3439 behave_main (behave_args )
3540 print ("# All tests are finished." )
3641 return True
@@ -43,7 +48,13 @@ def get_features(args):
4348 if f .endswith (".feature" ):
4449 os .remove (os .path .join (features_dir , f ))
4550 if args ["feature" ]:
46- shutil .copyfile (args ["feature" ], os .path .join (get_resource_path ("features" ), os .path .basename (args ["feature" ])))
51+ shutil .copyfile (
52+ args ["feature" ],
53+ os .path .join (
54+ get_resource_path ("features" ),
55+ os .path .basename (args ["feature" ])
56+ )
57+ )
4758 return True
4859 if os .path .exists ("features" ):
4960 shutil .copytree ("features" , get_resource_path ("features" ))
@@ -55,7 +66,10 @@ def get_features(args):
5566 if args ["feature" ] and args ["feature" ] != f :
5667 continue
5768 has_features = True
58- shutil .copyfile (f , os .path .join (get_resource_path ("features" ), os .path .basename (f )))
69+ shutil .copyfile (
70+ f ,
71+ os .path .join (get_resource_path ("features" ), os .path .basename (f ))
72+ )
5973 return has_features
6074
6175
@@ -111,16 +125,23 @@ def run_intmp_tests(args={}):
111125 """
112126
113127 from behave import __version__ as behave_version
114-
115128 # https://github.com/behave/behave/issues/871
116129 if behave_version == "1.2.5" :
117- print ("At least behave version 1.2.6 is needed, but version {} found." .format (behave_version ))
130+ print (
131+ "At least behave version 1.2.6 is needed, but version {} found."
132+ .format (behave_version )
133+ )
118134 return False
119135
120136 # get the features_path, the feature files where the tests are in
121137 if "features" in args and args ["features" ] != "" :
122- # TODO check if path exists, and if features dir is inside
123138 features_path = os .path .join (args ["features" ], "features" )
139+ if not os .path .isdir (features_path ):
140+ print (
141+ "The features directory does not exist: {}"
142+ .format (features_path )
143+ )
144+ return False
124145 else :
125146 # TODO assume features beside ifc thus use ifc path
126147 print ("No features path was given." )
@@ -152,7 +173,6 @@ def run_intmp_tests(args={}):
152173 run_path = os .path .join (tempfile .gettempdir (), "bimtesterfc" )
153174 if os .path .isdir (run_path ):
154175 from shutil import rmtree
155-
156176 rmtree (run_path ) # fails on read only files
157177 if os .path .isdir (run_path ):
158178 print ("Delete former beimtester run dir {} failed" .format (run_path ))
@@ -185,7 +205,10 @@ def run_intmp_tests(args={}):
185205 theline = line
186206 if ifc_filename is None :
187207 ifc_filename = os .path .basename (theline .split ('"' )[1 ])
188- newifcline = ' * The IFC file "{}" must be provided\n ' .format (os .path .join (ifc_path , ifc_filename ))
208+ newifcline = (
209+ ' * The IFC file "{}" must be provided\n '
210+ .format (os .path .join (ifc_path , ifc_filename ))
211+ )
189212 # print(newifcline)
190213 break
191214 else :
@@ -199,15 +222,26 @@ def run_intmp_tests(args={}):
199222 print (line .replace (theline , newifcline ), end = "" )
200223
201224 # copy step files and environment file
202- steps_path = os .path .join (bimtester_path , "features" , "steps" )
225+ steps_path = os .path .join (
226+ bimtester_path ,
227+ "features" ,
228+ "steps"
229+ )
203230 # print(steps_path)
204231 # print(copy_steps_path)
205232 if os .path .exists (steps_path ):
206233 shutil .copytree (steps_path , copy_steps_path )
207234
208- environment_file = os .path .join (bimtester_path , "features" , "environment.py" )
235+ environment_file = os .path .join (
236+ bimtester_path ,
237+ "features" ,
238+ "environment.py"
239+ )
209240 if os .path .isfile (environment_file ):
210- shutil .copyfile (environment_file , os .path .join (copy_features_path , "environment.py" ))
241+ shutil .copyfile (
242+ environment_file ,
243+ os .path .join (copy_features_path , "environment.py" )
244+ )
211245
212246 # get advanced args
213247 # print to console from inside step files, add "--no-capture" flag
@@ -216,27 +250,24 @@ def run_intmp_tests(args={}):
216250 if "advanced_arguments" in args :
217251 behave_args .extend (args ["advanced_arguments" ].split ())
218252 elif "console" not in args :
219- behave_args .extend (
220- [
221- # redirect prints in step methods
222- # if step fails some output is catched, thus might not be printed
223- "--no-capture" ,
224- # next two lines are one arg
225- "--format" ,
226- "json.pretty" ,
227- # next two lines are one arg
228- "--outfile" ,
229- os .path .join (report_path , "report.json" ),
230- # next two lines are one arg
231- "--define" ,
232- "ifcbasename={}" .format (os .path .splitext (ifc_filename )[0 ]),
233- ]
234- )
253+ behave_args .extend ([
254+ # redirect prints in step methods
255+ # if step fails some output is catched, thus might not be printed
256+ "--no-capture" ,
257+ # next two lines are one arg
258+ "--format" ,
259+ "json.pretty" ,
260+ # next two lines are one arg
261+ "--outfile" ,
262+ os .path .join (report_path , "report.json" ),
263+ # next two lines are one arg
264+ "--define" ,
265+ "ifcbasename={}" .format (os .path .splitext (ifc_filename )[0 ])
266+ ])
235267 print (behave_args )
236268
237269 # run tests
238270 from behave .__main__ import main as behave_main
239-
240271 behave_main (behave_args )
241272 print ("All tests are finished." )
242273
@@ -249,7 +280,10 @@ def run_intmp_tests(args={}):
249280def run_all (the_features_path , the_ifcfile ):
250281
251282 # run bimtester
252- runpath = run_intmp_tests ({"features" : the_features_path , "ifcfile" : the_ifcfile })
283+ runpath = run_intmp_tests ({
284+ "features" : the_features_path ,
285+ "ifcfile" : the_ifcfile
286+ })
253287 print (runpath )
254288
255289 # check if it worked out well
@@ -263,12 +297,17 @@ def run_all(the_features_path, the_ifcfile):
263297
264298 # create html report and open in webbrowser
265299 from .reports import generate_report
266-
267300 generate_report (runpath )
268301 # get the feature files
269- feature_files = os .listdir (os .path .join (the_features_path , "features" ))
302+ feature_files = os .listdir (
303+ os .path .join (the_features_path , "features" )
304+ )
270305 # print(feature_files)
271306 for ff in feature_files :
272- webbrowser .open (os .path .join (runpath , "report" , ff + ".html" ))
307+ webbrowser .open (os .path .join (
308+ runpath ,
309+ "report" ,
310+ ff + ".html"
311+ ))
273312
274313 return True
0 commit comments