Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit b72b2aa

Browse files
committed
Package new BIMTester for the BlenderBIM Add-on
1 parent c1bbb1e commit b72b2aa

3 files changed

Lines changed: 59 additions & 86 deletions

File tree

src/ifcbimtester/bimtester/run.py

Lines changed: 33 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ 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([
34-
"--format",
35-
"json.pretty",
36-
"--outfile",
37-
"report/report.json"
38-
])
33+
behave_args.extend(["--format", "json.pretty", "--outfile", "report/report.json"])
3934
behave_main(behave_args)
4035
print("# All tests are finished.")
4136
return True
@@ -48,13 +43,7 @@ def get_features(args):
4843
if f.endswith(".feature"):
4944
os.remove(os.path.join(features_dir, f))
5045
if 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-
)
46+
shutil.copyfile(args["feature"], os.path.join(get_resource_path("features"), os.path.basename(args["feature"])))
5847
return True
5948
if os.path.exists("features"):
6049
shutil.copytree("features", get_resource_path("features"))
@@ -66,15 +55,10 @@ def get_features(args):
6655
if args["feature"] and args["feature"] != f:
6756
continue
6857
has_features = True
69-
shutil.copyfile(
70-
f,
71-
os.path.join(get_resource_path("features"), os.path.basename(f))
72-
)
58+
shutil.copyfile(f, os.path.join(get_resource_path("features"), os.path.basename(f)))
7359
return has_features
7460

7561

76-
77-
7862
"""
7963
# clean logs to be able to run tests
8064
# once again but on another building model and in another directory
@@ -110,14 +94,14 @@ def run_intmp_tests(args={}):
11094
they will be directly passed to the behave call
11195
11296
features and ifcfile are given:
113-
the ifcfile in feature files is replaced
97+
the ifcfile in feature files is replaced
11498
11599
features only is given (TODO):
116100
the ifcfile provided in the feature files is used
117101
118102
ifcfile only is given (TODO):
119103
features = ifcfile directory
120-
the ifcfile in feature files is replaced
104+
the ifcfile in feature files is replaced
121105
122106
none of both is given (TODO):
123107
the current directory = features
@@ -127,12 +111,10 @@ def run_intmp_tests(args={}):
127111
"""
128112

129113
from behave import __version__ as behave_version
114+
130115
# https://github.com/behave/behave/issues/871
131116
if behave_version == "1.2.5":
132-
print(
133-
"At least behave version 1.2.6 is needed, but version {} found."
134-
.format(behave_version)
135-
)
117+
print("At least behave version 1.2.6 is needed, but version {} found.".format(behave_version))
136118
return False
137119

138120
# get the features_path, the feature files where the tests are in
@@ -170,6 +152,7 @@ def run_intmp_tests(args={}):
170152
run_path = os.path.join(tempfile.gettempdir(), "bimtesterfc")
171153
if os.path.isdir(run_path):
172154
from shutil import rmtree
155+
173156
rmtree(run_path) # fails on read only files
174157
if os.path.isdir(run_path):
175158
print("Delete former beimtester run dir {} failed".format(run_path))
@@ -202,10 +185,7 @@ def run_intmp_tests(args={}):
202185
theline = line
203186
if ifc_filename is None:
204187
ifc_filename = os.path.basename(theline.split('"')[1])
205-
newifcline = (
206-
' * The IFC file "{}" must be provided\n'
207-
.format(os.path.join(ifc_path, ifc_filename))
208-
)
188+
newifcline = ' * The IFC file "{}" must be provided\n'.format(os.path.join(ifc_path, ifc_filename))
209189
# print(newifcline)
210190
break
211191
else:
@@ -219,26 +199,15 @@ def run_intmp_tests(args={}):
219199
print(line.replace(theline, newifcline), end="")
220200

221201
# copy step files and environment file
222-
steps_path = os.path.join(
223-
bimtester_path,
224-
"features",
225-
"steps"
226-
)
202+
steps_path = os.path.join(bimtester_path, "features", "steps")
227203
# print(steps_path)
228204
# print(copy_steps_path)
229205
if os.path.exists(steps_path):
230206
shutil.copytree(steps_path, copy_steps_path)
231207

232-
environment_file = os.path.join(
233-
bimtester_path,
234-
"features",
235-
"environment.py"
236-
)
208+
environment_file = os.path.join(bimtester_path, "features", "environment.py")
237209
if os.path.isfile(environment_file):
238-
shutil.copyfile(
239-
environment_file,
240-
os.path.join(copy_features_path, "environment.py")
241-
)
210+
shutil.copyfile(environment_file, os.path.join(copy_features_path, "environment.py"))
242211

243212
# get advanced args
244213
# print to console from inside step files, add "--no-capture" flag
@@ -247,24 +216,27 @@ def run_intmp_tests(args={}):
247216
if "advanced_arguments" in args:
248217
behave_args.extend(args["advanced_arguments"].split())
249218
elif "console" not in args:
250-
behave_args.extend([
251-
# redirect prints in step methods
252-
# if step fails some output is catched, thus might not be printed
253-
"--no-capture",
254-
# next two lines are one arg
255-
"--format",
256-
"json.pretty",
257-
# next two lines are one arg
258-
"--outfile",
259-
os.path.join(report_path, "report.json"),
260-
# next two lines are one arg
261-
"--define",
262-
"ifcbasename={}".format(os.path.splitext(ifc_filename)[0])
263-
])
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+
)
264235
print(behave_args)
265236

266237
# run tests
267238
from behave.__main__ import main as behave_main
239+
268240
behave_main(behave_args)
269241
print("All tests are finished.")
270242

@@ -277,10 +249,7 @@ def run_intmp_tests(args={}):
277249
def run_all(the_features_path, the_ifcfile):
278250

279251
# run bimtester
280-
runpath = run_intmp_tests({
281-
"features": the_features_path,
282-
"ifcfile": the_ifcfile
283-
})
252+
runpath = run_intmp_tests({"features": the_features_path, "ifcfile": the_ifcfile})
284253
print(runpath)
285254

286255
# check if it worked out well
@@ -294,17 +263,12 @@ def run_all(the_features_path, the_ifcfile):
294263

295264
# create html report and open in webbrowser
296265
from .reports import generate_report
266+
297267
generate_report(runpath)
298268
# get the feature files
299-
feature_files = os.listdir(
300-
os.path.join(the_features_path, "features")
301-
)
269+
feature_files = os.listdir(os.path.join(the_features_path, "features"))
302270
# print(feature_files)
303271
for ff in feature_files:
304-
webbrowser.open(os.path.join(
305-
runpath,
306-
"report",
307-
ff + ".html"
308-
))
272+
webbrowser.open(os.path.join(runpath, "report", ff + ".html"))
309273

310274
return True

src/ifcblenderexport/Makefile

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -238,20 +238,26 @@ endif
238238
rm -rf dist/working
239239

240240
# Provides BIMTester functionality
241-
cd dist/blenderbim/libs/site/packages/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester.py
242-
mkdir dist/blenderbim/libs/site/packages/features/
243-
mkdir dist/blenderbim/libs/site/packages/features/steps/
244-
cd dist/blenderbim/libs/site/packages/features/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/environment.py
245-
cd dist/blenderbim/libs/site/packages/features/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/template.html
246-
cd dist/blenderbim/libs/site/packages/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/steps/classification.py
247-
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
248-
cd dist/blenderbim/libs/site/packages/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/steps/geocoding.py
249-
cd dist/blenderbim/libs/site/packages/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/steps/geolocation.py
250-
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
251-
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
252-
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
253-
cd dist/blenderbim/libs/site/packages/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/steps/steps.py
254-
cd dist/blenderbim/libs/site/packages/features/steps/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/features/steps/utils.py
241+
mkdir dist/blenderbim/libs/site/packages/bimtester/
242+
cd dist/blenderbim/libs/site/packages/bimtester && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/__init__.py
243+
cd dist/blenderbim/libs/site/packages/bimtester && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/clean.py
244+
cd dist/blenderbim/libs/site/packages/bimtester && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/guiwidget.py
245+
cd dist/blenderbim/libs/site/packages/bimtester && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/reports.py
246+
cd dist/blenderbim/libs/site/packages/bimtester && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/run.py
247+
mkdir dist/blenderbim/libs/site/packages/bimtester/features/
248+
mkdir dist/blenderbim/libs/site/packages/bimtester/features/steps/
249+
cd dist/blenderbim/libs/site/packages/bimtester/features/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/features/environment.py
250+
cd dist/blenderbim/libs/site/packages/bimtester/features/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcbimtester/bimtester/features/template.html
251+
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
252+
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
253+
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
254+
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
255+
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
256+
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
257+
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
258+
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
259+
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
260+
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
255261

256262
# Required by IFCCOBie for XLSX support
257263
mkdir dist/working

src/ifcblenderexport/blenderbim/bim/operator.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3853,14 +3853,16 @@ class ExecuteBIMTester(bpy.types.Operator):
38533853

38543854
def execute(self, context):
38553855
import bimtester
3856+
import bimtester.run
3857+
import bimtester.reports
38563858

38573859
filename = os.path.join(
38583860
bpy.context.scene.BIMProperties.features_dir, bpy.context.scene.BIMProperties.features_file + ".feature"
38593861
)
38603862
cwd = os.getcwd()
38613863
os.chdir(bpy.context.scene.BIMProperties.features_dir)
3862-
bimtester.run_tests({"feature": filename, "advanced_arguments": None, "console": False})
3863-
bimtester.generate_report()
3864+
bimtester.run.run_tests({"feature": filename, "advanced_arguments": None, "console": False})
3865+
bimtester.reports.generate_report()
38643866
webbrowser.open(
38653867
"file://"
38663868
+ os.path.join(
@@ -3879,13 +3881,14 @@ class BIMTesterPurge(bpy.types.Operator):
38793881

38803882
def execute(self, context):
38813883
import bimtester
3884+
import bimtester.clean
38823885

38833886
filename = os.path.join(
38843887
bpy.context.scene.BIMProperties.features_dir, bpy.context.scene.BIMProperties.features_file + ".feature"
38853888
)
38863889
cwd = os.getcwd()
38873890
os.chdir(bpy.context.scene.BIMProperties.features_dir)
3888-
bimtester.TestPurger().purge()
3891+
bimtester.clean.TestPurger().purge()
38893892
os.chdir(cwd)
38903893
return {"FINISHED"}
38913894

0 commit comments

Comments
 (0)