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
+31 -67
View File
@@ -30,12 +30,7 @@ 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([ behave_args.extend(["--format", "json.pretty", "--outfile", "report/report.json"])
"--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
@@ -48,13 +43,7 @@ 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( shutil.copyfile(args["feature"], os.path.join(get_resource_path("features"), os.path.basename(args["feature"])))
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"))
@@ -66,15 +55,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( shutil.copyfile(f, os.path.join(get_resource_path("features"), os.path.basename(f)))
f,
os.path.join(get_resource_path("features"), os.path.basename(f))
)
return has_features return has_features
""" """
# clean logs to be able to run tests # clean logs to be able to run tests
# once again but on another building model and in another directory # once again but on another building model and in another directory
@@ -127,12 +111,10 @@ 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( print("At least behave version 1.2.6 is needed, but version {} found.".format(behave_version))
"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
@@ -170,6 +152,7 @@ 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))
@@ -202,10 +185,7 @@ 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 = ( newifcline = ' * The IFC file "{}" must be provided\n'.format(os.path.join(ifc_path, ifc_filename))
' * The IFC file "{}" must be provided\n'
.format(os.path.join(ifc_path, ifc_filename))
)
# print(newifcline) # print(newifcline)
break break
else: else:
@@ -219,26 +199,15 @@ 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( steps_path = os.path.join(bimtester_path, "features", "steps")
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( environment_file = os.path.join(bimtester_path, "features", "environment.py")
bimtester_path,
"features",
"environment.py"
)
if os.path.isfile(environment_file): if os.path.isfile(environment_file):
shutil.copyfile( shutil.copyfile(environment_file, os.path.join(copy_features_path, "environment.py"))
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
@@ -247,24 +216,27 @@ 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 [
# if step fails some output is catched, thus might not be printed # redirect prints in step methods
"--no-capture", # if step fails some output is catched, thus might not be printed
# next two lines are one arg "--no-capture",
"--format", # next two lines are one arg
"json.pretty", "--format",
# next two lines are one arg "json.pretty",
"--outfile", # next two lines are one arg
os.path.join(report_path, "report.json"), "--outfile",
# next two lines are one arg os.path.join(report_path, "report.json"),
"--define", # next two lines are one arg
"ifcbasename={}".format(os.path.splitext(ifc_filename)[0]) "--define",
]) "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.")
@@ -277,10 +249,7 @@ 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({ runpath = run_intmp_tests({"features": the_features_path, "ifcfile": the_ifcfile})
"features": the_features_path,
"ifcfile": the_ifcfile
})
print(runpath) print(runpath)
# check if it worked out well # 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 # 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( feature_files = os.listdir(os.path.join(the_features_path, "features"))
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( webbrowser.open(os.path.join(runpath, "report", ff + ".html"))
runpath,
"report",
ff + ".html"
))
return True return True
+20 -14
View File
@@ -238,20 +238,26 @@ endif
rm -rf dist/working rm -rf dist/working
# Provides BIMTester functionality # 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/bimtester/
mkdir dist/blenderbim/libs/site/packages/features/ cd dist/blenderbim/libs/site/packages/bimtester && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/__init__.py
mkdir dist/blenderbim/libs/site/packages/features/steps/ 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/features/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/environment.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/features/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/template.html 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/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/steps/classification.py cd dist/blenderbim/libs/site/packages/bimtester && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/run.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 mkdir dist/blenderbim/libs/site/packages/bimtester/features/
cd dist/blenderbim/libs/site/packages/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/steps/geocoding.py mkdir dist/blenderbim/libs/site/packages/bimtester/features/steps/
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/bimtester/features/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/features/environment.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/bimtester/features/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/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/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/classification.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/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/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/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/geocoding.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 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 # Required by IFCCOBie for XLSX support
mkdir dist/working mkdir dist/working
@@ -3853,14 +3853,16 @@ class ExecuteBIMTester(bpy.types.Operator):
def execute(self, context): def execute(self, context):
import bimtester import bimtester
import bimtester.run
import bimtester.reports
filename = os.path.join( filename = os.path.join(
bpy.context.scene.BIMProperties.features_dir, bpy.context.scene.BIMProperties.features_file + ".feature" bpy.context.scene.BIMProperties.features_dir, bpy.context.scene.BIMProperties.features_file + ".feature"
) )
cwd = os.getcwd() cwd = os.getcwd()
os.chdir(bpy.context.scene.BIMProperties.features_dir) os.chdir(bpy.context.scene.BIMProperties.features_dir)
bimtester.run_tests({"feature": filename, "advanced_arguments": None, "console": False}) bimtester.run.run_tests({"feature": filename, "advanced_arguments": None, "console": False})
bimtester.generate_report() bimtester.reports.generate_report()
webbrowser.open( webbrowser.open(
"file://" "file://"
+ os.path.join( + os.path.join(
@@ -3879,13 +3881,14 @@ class BIMTesterPurge(bpy.types.Operator):
def execute(self, context): def execute(self, context):
import bimtester import bimtester
import bimtester.clean
filename = os.path.join( filename = os.path.join(
bpy.context.scene.BIMProperties.features_dir, bpy.context.scene.BIMProperties.features_file + ".feature" bpy.context.scene.BIMProperties.features_dir, bpy.context.scene.BIMProperties.features_file + ".feature"
) )
cwd = os.getcwd() cwd = os.getcwd()
os.chdir(bpy.context.scene.BIMProperties.features_dir) os.chdir(bpy.context.scene.BIMProperties.features_dir)
bimtester.TestPurger().purge() bimtester.clean.TestPurger().purge()
os.chdir(cwd) os.chdir(cwd)
return {"FINISHED"} return {"FINISHED"}