mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-24 10:27:00 +00:00
bimtester: code formating
This commit is contained in:
committed by
Dion Moult
parent
7dd40149aa
commit
3ae20637d7
@@ -30,7 +30,12 @@ def run_tests(args):
|
|||||||
if args["advanced_arguments"]:
|
if args["advanced_arguments"]:
|
||||||
behave_args.extend(args["advanced_arguments"].split())
|
behave_args.extend(args["advanced_arguments"].split())
|
||||||
elif not args["console"]:
|
elif not args["console"]:
|
||||||
behave_args.extend(["--format", "json.pretty", "--outfile", "report/report.json"])
|
behave_args.extend([
|
||||||
|
"--format",
|
||||||
|
"json.pretty",
|
||||||
|
"--outfile",
|
||||||
|
"report/report.json"
|
||||||
|
])
|
||||||
behave_main(behave_args)
|
behave_main(behave_args)
|
||||||
print("# All tests are finished.")
|
print("# All tests are finished.")
|
||||||
return True
|
return True
|
||||||
@@ -43,7 +48,13 @@ def get_features(args):
|
|||||||
if f.endswith(".feature"):
|
if f.endswith(".feature"):
|
||||||
os.remove(os.path.join(features_dir, f))
|
os.remove(os.path.join(features_dir, f))
|
||||||
if args["feature"]:
|
if args["feature"]:
|
||||||
shutil.copyfile(args["feature"], os.path.join(get_resource_path("features"), os.path.basename(args["feature"])))
|
shutil.copyfile(
|
||||||
|
args["feature"],
|
||||||
|
os.path.join(
|
||||||
|
get_resource_path("features"),
|
||||||
|
os.path.basename(args["feature"])
|
||||||
|
)
|
||||||
|
)
|
||||||
return True
|
return True
|
||||||
if os.path.exists("features"):
|
if os.path.exists("features"):
|
||||||
shutil.copytree("features", get_resource_path("features"))
|
shutil.copytree("features", get_resource_path("features"))
|
||||||
@@ -55,7 +66,10 @@ def get_features(args):
|
|||||||
if args["feature"] and args["feature"] != f:
|
if args["feature"] and args["feature"] != f:
|
||||||
continue
|
continue
|
||||||
has_features = True
|
has_features = True
|
||||||
shutil.copyfile(f, os.path.join(get_resource_path("features"), os.path.basename(f)))
|
shutil.copyfile(
|
||||||
|
f,
|
||||||
|
os.path.join(get_resource_path("features"), os.path.basename(f))
|
||||||
|
)
|
||||||
return has_features
|
return has_features
|
||||||
|
|
||||||
|
|
||||||
@@ -111,16 +125,23 @@ def run_intmp_tests(args={}):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from behave import __version__ as behave_version
|
from behave import __version__ as behave_version
|
||||||
|
|
||||||
# https://github.com/behave/behave/issues/871
|
# https://github.com/behave/behave/issues/871
|
||||||
if behave_version == "1.2.5":
|
if behave_version == "1.2.5":
|
||||||
print("At least behave version 1.2.6 is needed, but version {} found.".format(behave_version))
|
print(
|
||||||
|
"At least behave version 1.2.6 is needed, but version {} found."
|
||||||
|
.format(behave_version)
|
||||||
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# get the features_path, the feature files where the tests are in
|
# get the features_path, the feature files where the tests are in
|
||||||
if "features" in args and args["features"] != "":
|
if "features" in args and args["features"] != "":
|
||||||
# TODO check if path exists, and if features dir is inside
|
|
||||||
features_path = os.path.join(args["features"], "features")
|
features_path = os.path.join(args["features"], "features")
|
||||||
|
if not os.path.isdir(features_path):
|
||||||
|
print(
|
||||||
|
"The features directory does not exist: {}"
|
||||||
|
.format(features_path)
|
||||||
|
)
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
# TODO assume features beside ifc thus use ifc path
|
# TODO assume features beside ifc thus use ifc path
|
||||||
print("No features path was given.")
|
print("No features path was given.")
|
||||||
@@ -152,7 +173,6 @@ def run_intmp_tests(args={}):
|
|||||||
run_path = os.path.join(tempfile.gettempdir(), "bimtesterfc")
|
run_path = os.path.join(tempfile.gettempdir(), "bimtesterfc")
|
||||||
if os.path.isdir(run_path):
|
if os.path.isdir(run_path):
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
|
|
||||||
rmtree(run_path) # fails on read only files
|
rmtree(run_path) # fails on read only files
|
||||||
if os.path.isdir(run_path):
|
if os.path.isdir(run_path):
|
||||||
print("Delete former beimtester run dir {} failed".format(run_path))
|
print("Delete former beimtester run dir {} failed".format(run_path))
|
||||||
@@ -185,7 +205,10 @@ def run_intmp_tests(args={}):
|
|||||||
theline = line
|
theline = line
|
||||||
if ifc_filename is None:
|
if ifc_filename is None:
|
||||||
ifc_filename = os.path.basename(theline.split('"')[1])
|
ifc_filename = os.path.basename(theline.split('"')[1])
|
||||||
newifcline = ' * The IFC file "{}" must be provided\n'.format(os.path.join(ifc_path, ifc_filename))
|
newifcline = (
|
||||||
|
' * The IFC file "{}" must be provided\n'
|
||||||
|
.format(os.path.join(ifc_path, ifc_filename))
|
||||||
|
)
|
||||||
# print(newifcline)
|
# print(newifcline)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@@ -199,15 +222,26 @@ def run_intmp_tests(args={}):
|
|||||||
print(line.replace(theline, newifcline), end="")
|
print(line.replace(theline, newifcline), end="")
|
||||||
|
|
||||||
# copy step files and environment file
|
# copy step files and environment file
|
||||||
steps_path = os.path.join(bimtester_path, "features", "steps")
|
steps_path = os.path.join(
|
||||||
|
bimtester_path,
|
||||||
|
"features",
|
||||||
|
"steps"
|
||||||
|
)
|
||||||
# print(steps_path)
|
# print(steps_path)
|
||||||
# print(copy_steps_path)
|
# print(copy_steps_path)
|
||||||
if os.path.exists(steps_path):
|
if os.path.exists(steps_path):
|
||||||
shutil.copytree(steps_path, copy_steps_path)
|
shutil.copytree(steps_path, copy_steps_path)
|
||||||
|
|
||||||
environment_file = os.path.join(bimtester_path, "features", "environment.py")
|
environment_file = os.path.join(
|
||||||
|
bimtester_path,
|
||||||
|
"features",
|
||||||
|
"environment.py"
|
||||||
|
)
|
||||||
if os.path.isfile(environment_file):
|
if os.path.isfile(environment_file):
|
||||||
shutil.copyfile(environment_file, os.path.join(copy_features_path, "environment.py"))
|
shutil.copyfile(
|
||||||
|
environment_file,
|
||||||
|
os.path.join(copy_features_path, "environment.py")
|
||||||
|
)
|
||||||
|
|
||||||
# get advanced args
|
# get advanced args
|
||||||
# print to console from inside step files, add "--no-capture" flag
|
# print to console from inside step files, add "--no-capture" flag
|
||||||
@@ -216,27 +250,24 @@ def run_intmp_tests(args={}):
|
|||||||
if "advanced_arguments" in args:
|
if "advanced_arguments" in args:
|
||||||
behave_args.extend(args["advanced_arguments"].split())
|
behave_args.extend(args["advanced_arguments"].split())
|
||||||
elif "console" not in args:
|
elif "console" not in args:
|
||||||
behave_args.extend(
|
behave_args.extend([
|
||||||
[
|
# redirect prints in step methods
|
||||||
# redirect prints in step methods
|
# if step fails some output is catched, thus might not be printed
|
||||||
# if step fails some output is catched, thus might not be printed
|
"--no-capture",
|
||||||
"--no-capture",
|
# next two lines are one arg
|
||||||
# next two lines are one arg
|
"--format",
|
||||||
"--format",
|
"json.pretty",
|
||||||
"json.pretty",
|
# next two lines are one arg
|
||||||
# next two lines are one arg
|
"--outfile",
|
||||||
"--outfile",
|
os.path.join(report_path, "report.json"),
|
||||||
os.path.join(report_path, "report.json"),
|
# next two lines are one arg
|
||||||
# next two lines are one arg
|
"--define",
|
||||||
"--define",
|
"ifcbasename={}".format(os.path.splitext(ifc_filename)[0])
|
||||||
"ifcbasename={}".format(os.path.splitext(ifc_filename)[0]),
|
])
|
||||||
]
|
|
||||||
)
|
|
||||||
print(behave_args)
|
print(behave_args)
|
||||||
|
|
||||||
# run tests
|
# run tests
|
||||||
from behave.__main__ import main as behave_main
|
from behave.__main__ import main as behave_main
|
||||||
|
|
||||||
behave_main(behave_args)
|
behave_main(behave_args)
|
||||||
print("All tests are finished.")
|
print("All tests are finished.")
|
||||||
|
|
||||||
@@ -249,7 +280,10 @@ def run_intmp_tests(args={}):
|
|||||||
def run_all(the_features_path, the_ifcfile):
|
def run_all(the_features_path, the_ifcfile):
|
||||||
|
|
||||||
# run bimtester
|
# run bimtester
|
||||||
runpath = run_intmp_tests({"features": the_features_path, "ifcfile": the_ifcfile})
|
runpath = run_intmp_tests({
|
||||||
|
"features": the_features_path,
|
||||||
|
"ifcfile": the_ifcfile
|
||||||
|
})
|
||||||
print(runpath)
|
print(runpath)
|
||||||
|
|
||||||
# check if it worked out well
|
# check if it worked out well
|
||||||
@@ -263,12 +297,17 @@ def run_all(the_features_path, the_ifcfile):
|
|||||||
|
|
||||||
# create html report and open in webbrowser
|
# create html report and open in webbrowser
|
||||||
from .reports import generate_report
|
from .reports import generate_report
|
||||||
|
|
||||||
generate_report(runpath)
|
generate_report(runpath)
|
||||||
# get the feature files
|
# get the feature files
|
||||||
feature_files = os.listdir(os.path.join(the_features_path, "features"))
|
feature_files = os.listdir(
|
||||||
|
os.path.join(the_features_path, "features")
|
||||||
|
)
|
||||||
# print(feature_files)
|
# print(feature_files)
|
||||||
for ff in feature_files:
|
for ff in feature_files:
|
||||||
webbrowser.open(os.path.join(runpath, "report", ff + ".html"))
|
webbrowser.open(os.path.join(
|
||||||
|
runpath,
|
||||||
|
"report",
|
||||||
|
ff + ".html"
|
||||||
|
))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user