mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-19 11:43:53 +00:00
Package new BIMTester for the BlenderBIM Add-on
This commit is contained in:
@@ -30,12 +30,7 @@ def run_tests(args):
|
||||
if args["advanced_arguments"]:
|
||||
behave_args.extend(args["advanced_arguments"].split())
|
||||
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)
|
||||
print("# All tests are finished.")
|
||||
return True
|
||||
@@ -48,13 +43,7 @@ def get_features(args):
|
||||
if f.endswith(".feature"):
|
||||
os.remove(os.path.join(features_dir, f))
|
||||
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
|
||||
if os.path.exists("features"):
|
||||
shutil.copytree("features", get_resource_path("features"))
|
||||
@@ -66,15 +55,10 @@ def get_features(args):
|
||||
if args["feature"] and args["feature"] != f:
|
||||
continue
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
# clean logs to be able to run tests
|
||||
# once again but on another building model and in another directory
|
||||
@@ -110,14 +94,14 @@ def run_intmp_tests(args={}):
|
||||
they will be directly passed to the behave call
|
||||
|
||||
features and ifcfile are given:
|
||||
the ifcfile in feature files is replaced
|
||||
the ifcfile in feature files is replaced
|
||||
|
||||
features only is given (TODO):
|
||||
the ifcfile provided in the feature files is used
|
||||
|
||||
ifcfile only is given (TODO):
|
||||
features = ifcfile directory
|
||||
the ifcfile in feature files is replaced
|
||||
the ifcfile in feature files is replaced
|
||||
|
||||
none of both is given (TODO):
|
||||
the current directory = features
|
||||
@@ -127,12 +111,10 @@ def run_intmp_tests(args={}):
|
||||
"""
|
||||
|
||||
from behave import __version__ as behave_version
|
||||
|
||||
# https://github.com/behave/behave/issues/871
|
||||
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
|
||||
|
||||
# get the features_path, the feature files where the tests are in
|
||||
@@ -170,6 +152,7 @@ def run_intmp_tests(args={}):
|
||||
run_path = os.path.join(tempfile.gettempdir(), "bimtesterfc")
|
||||
if os.path.isdir(run_path):
|
||||
from shutil import rmtree
|
||||
|
||||
rmtree(run_path) # fails on read only files
|
||||
if os.path.isdir(run_path):
|
||||
print("Delete former beimtester run dir {} failed".format(run_path))
|
||||
@@ -202,10 +185,7 @@ def run_intmp_tests(args={}):
|
||||
theline = line
|
||||
if ifc_filename is None:
|
||||
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)
|
||||
break
|
||||
else:
|
||||
@@ -219,26 +199,15 @@ def run_intmp_tests(args={}):
|
||||
print(line.replace(theline, newifcline), end="")
|
||||
|
||||
# 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(copy_steps_path)
|
||||
if os.path.exists(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):
|
||||
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
|
||||
# print to console from inside step files, add "--no-capture" flag
|
||||
@@ -247,24 +216,27 @@ def run_intmp_tests(args={}):
|
||||
if "advanced_arguments" in args:
|
||||
behave_args.extend(args["advanced_arguments"].split())
|
||||
elif "console" not in args:
|
||||
behave_args.extend([
|
||||
# redirect prints in step methods
|
||||
# if step fails some output is catched, thus might not be printed
|
||||
"--no-capture",
|
||||
# next two lines are one arg
|
||||
"--format",
|
||||
"json.pretty",
|
||||
# next two lines are one arg
|
||||
"--outfile",
|
||||
os.path.join(report_path, "report.json"),
|
||||
# next two lines are one arg
|
||||
"--define",
|
||||
"ifcbasename={}".format(os.path.splitext(ifc_filename)[0])
|
||||
])
|
||||
behave_args.extend(
|
||||
[
|
||||
# redirect prints in step methods
|
||||
# if step fails some output is catched, thus might not be printed
|
||||
"--no-capture",
|
||||
# next two lines are one arg
|
||||
"--format",
|
||||
"json.pretty",
|
||||
# next two lines are one arg
|
||||
"--outfile",
|
||||
os.path.join(report_path, "report.json"),
|
||||
# next two lines are one arg
|
||||
"--define",
|
||||
"ifcbasename={}".format(os.path.splitext(ifc_filename)[0]),
|
||||
]
|
||||
)
|
||||
print(behave_args)
|
||||
|
||||
# run tests
|
||||
from behave.__main__ import main as behave_main
|
||||
|
||||
behave_main(behave_args)
|
||||
print("All tests are finished.")
|
||||
|
||||
@@ -277,10 +249,7 @@ def run_intmp_tests(args={}):
|
||||
def run_all(the_features_path, the_ifcfile):
|
||||
|
||||
# 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)
|
||||
|
||||
# check if it worked out well
|
||||
@@ -294,17 +263,12 @@ def run_all(the_features_path, the_ifcfile):
|
||||
|
||||
# create html report and open in webbrowser
|
||||
from .reports import generate_report
|
||||
|
||||
generate_report(runpath)
|
||||
# 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)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user