Package new BIMTester for the BlenderBIM Add-on

This commit is contained in:
Dion Moult
2020-12-07 16:42:01 +11:00
parent c1bbb1e721
commit b72b2aa7d7
3 changed files with 59 additions and 86 deletions
+33 -69
View File
@@ -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
+20 -14
View File
@@ -238,20 +238,26 @@ endif
rm -rf dist/working
# Provides BIMTester functionality
cd dist/blenderbim/libs/site/packages/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester.py
mkdir dist/blenderbim/libs/site/packages/features/
mkdir dist/blenderbim/libs/site/packages/features/steps/
cd dist/blenderbim/libs/site/packages/features/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/environment.py
cd dist/blenderbim/libs/site/packages/features/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/template.html
cd dist/blenderbim/libs/site/packages/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/steps/classification.py
cd dist/blenderbim/libs/site/packages/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/steps/element_classes.py
cd dist/blenderbim/libs/site/packages/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/steps/geocoding.py
cd dist/blenderbim/libs/site/packages/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/steps/geolocation.py
cd dist/blenderbim/libs/site/packages/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/steps/geometric_detail.py
cd dist/blenderbim/libs/site/packages/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/steps/model_federation.py
cd dist/blenderbim/libs/site/packages/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/steps/project_setup.py
cd dist/blenderbim/libs/site/packages/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/steps/steps.py
cd dist/blenderbim/libs/site/packages/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/steps/utils.py
mkdir dist/blenderbim/libs/site/packages/bimtester/
cd dist/blenderbim/libs/site/packages/bimtester && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/__init__.py
cd dist/blenderbim/libs/site/packages/bimtester && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/clean.py
cd dist/blenderbim/libs/site/packages/bimtester && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/guiwidget.py
cd dist/blenderbim/libs/site/packages/bimtester && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/reports.py
cd dist/blenderbim/libs/site/packages/bimtester && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/run.py
mkdir dist/blenderbim/libs/site/packages/bimtester/features/
mkdir dist/blenderbim/libs/site/packages/bimtester/features/steps/
cd dist/blenderbim/libs/site/packages/bimtester/features/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/features/environment.py
cd dist/blenderbim/libs/site/packages/bimtester/features/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/features/template.html
cd dist/blenderbim/libs/site/packages/bimtester/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/features/steps/classification.py
cd dist/blenderbim/libs/site/packages/bimtester/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/features/steps/element_classes.py
cd dist/blenderbim/libs/site/packages/bimtester/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/features/steps/geocoding.py
cd dist/blenderbim/libs/site/packages/bimtester/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/features/steps/geolocation.py
cd dist/blenderbim/libs/site/packages/bimtester/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/features/steps/geometric_detail.py
cd dist/blenderbim/libs/site/packages/bimtester/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/features/steps/ifcdata.py
cd dist/blenderbim/libs/site/packages/bimtester/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/features/steps/model_federation.py
cd dist/blenderbim/libs/site/packages/bimtester/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/features/steps/project_setup.py
cd dist/blenderbim/libs/site/packages/bimtester/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/features/steps/steps.py
cd dist/blenderbim/libs/site/packages/bimtester/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/features/steps/utils.py
# Required by IFCCOBie for XLSX support
mkdir dist/working
@@ -3853,14 +3853,16 @@ class ExecuteBIMTester(bpy.types.Operator):
def execute(self, context):
import bimtester
import bimtester.run
import bimtester.reports
filename = os.path.join(
bpy.context.scene.BIMProperties.features_dir, bpy.context.scene.BIMProperties.features_file + ".feature"
)
cwd = os.getcwd()
os.chdir(bpy.context.scene.BIMProperties.features_dir)
bimtester.run_tests({"feature": filename, "advanced_arguments": None, "console": False})
bimtester.generate_report()
bimtester.run.run_tests({"feature": filename, "advanced_arguments": None, "console": False})
bimtester.reports.generate_report()
webbrowser.open(
"file://"
+ os.path.join(
@@ -3879,13 +3881,14 @@ class BIMTesterPurge(bpy.types.Operator):
def execute(self, context):
import bimtester
import bimtester.clean
filename = os.path.join(
bpy.context.scene.BIMProperties.features_dir, bpy.context.scene.BIMProperties.features_file + ".feature"
)
cwd = os.getcwd()
os.chdir(bpy.context.scene.BIMProperties.features_dir)
bimtester.TestPurger().purge()
bimtester.clean.TestPurger().purge()
os.chdir(cwd)
return {"FINISHED"}