mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
bimtester: improve the signatures of the methods to run behave in temporary directory
This commit is contained in:
committed by
Dion Moult
parent
4a5fe83dab
commit
26d35a7644
@@ -1,5 +1,6 @@
|
||||
# TODO: improve layout, start with feature file path and beside button !!!!!
|
||||
# TODO: if browse widgets will be canceled, last QLineEdit should be restored
|
||||
# TODO: keep path or file if in browse widget canceled
|
||||
|
||||
import os
|
||||
|
||||
@@ -12,19 +13,25 @@ from .run import run_all
|
||||
|
||||
class GuiWidgetBimTester(QtWidgets.QWidget):
|
||||
|
||||
# get some initial values
|
||||
this_path = os.path.join(os.path.dirname(__file__))
|
||||
desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")
|
||||
|
||||
initial_ifcfile = "/home/hugo/Documents/zeug_sort/z_some_ifc/example_model.ifc"
|
||||
if not os.path.isfile(initial_ifcfile):
|
||||
initial_ifcfile = desktop_path
|
||||
initial_featurespath = os.path.join(this_path, "..", "..", "features_bimtester", "fea_min")
|
||||
if not os.path.isdir(initial_featurespath):
|
||||
initial_featurespath = desktop_path
|
||||
|
||||
def __init__(self):
|
||||
def __init__(
|
||||
self,
|
||||
features="",
|
||||
ifcfile=""
|
||||
):
|
||||
super(GuiWidgetBimTester, self).__init__()
|
||||
|
||||
# get some initial values
|
||||
user_path = os.path.expanduser("~")
|
||||
print(features)
|
||||
self.initial_featurespath = features
|
||||
if not os.path.isdir(self.initial_featurespath):
|
||||
self.initial_featurespath = user_path
|
||||
print(ifcfile)
|
||||
self.initial_ifcfile = ifcfile
|
||||
if not os.path.isfile(self.initial_ifcfile):
|
||||
self.initial_ifcfile = user_path
|
||||
|
||||
# init ui
|
||||
self._setup_ui()
|
||||
|
||||
def __del__(self,):
|
||||
@@ -180,8 +187,6 @@ class GuiWidgetBimTester(QtWidgets.QWidget):
|
||||
QtWidgets.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
|
||||
|
||||
# get input values
|
||||
splitifcpath = os.path.split(self.get_ifcfile())
|
||||
the_ifcfile_path, the_ifcfile_name = splitifcpath[0], splitifcpath[1]
|
||||
if self.featuredirfromifc_cb.isChecked() is True:
|
||||
the_features_path = the_ifcfile_path
|
||||
print(
|
||||
@@ -190,15 +195,14 @@ class GuiWidgetBimTester(QtWidgets.QWidget):
|
||||
)
|
||||
else:
|
||||
the_features_path = self.get_featurefilesdir()
|
||||
the_ifcfile = self.get_ifcfile()
|
||||
print(the_features_path)
|
||||
print(the_ifcfile_path)
|
||||
print(the_ifcfile_name)
|
||||
print(the_ifcfile)
|
||||
|
||||
# run bimtester
|
||||
status = run_all(
|
||||
the_features_path,
|
||||
the_ifcfile_path,
|
||||
the_ifcfile_name
|
||||
the_ifcfile,
|
||||
)
|
||||
print(status)
|
||||
|
||||
|
||||
@@ -73,6 +73,8 @@ def get_features(args):
|
||||
return has_features
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
# clean logs to be able to run tests
|
||||
# once again but on another building model and in another directory
|
||||
@@ -88,46 +90,42 @@ reset_runtime()
|
||||
"""
|
||||
|
||||
|
||||
"""
|
||||
from code_bimtester import run
|
||||
myfeatures_path = "/home/hugo/.FreeCAD/Mod/bimtester/features_bimtester/fea_min/"
|
||||
myifcfile_path = "/home/hugo/Documents/zeug_sort/z_some_ifc/"
|
||||
ifcfilename = "example_model.ifc"
|
||||
run.run_all(myfeatures_path, myifcfile_path, ifcfilename)
|
||||
|
||||
|
||||
from code_bimtester import run
|
||||
myfeatures_path = "/home/hugo/Documents/zeug_sort/ifcos_bimtester/myrun/"
|
||||
run.run_all(myfeatures_path, myfeatures_path)
|
||||
|
||||
"""
|
||||
|
||||
|
||||
# TODO: if the ifc file name or path contains special character
|
||||
# like German Umlaute behave gives an error
|
||||
|
||||
|
||||
# TODO: change run_intmp_tests() and run_all()
|
||||
# arguments feature_path and ifc_file
|
||||
#
|
||||
# both is given:
|
||||
# replace the ifc in feature files
|
||||
#
|
||||
# feature_path only is given:
|
||||
# use the ifc provided in the feature files
|
||||
#
|
||||
# ifc_file only is given:
|
||||
# assume feature files are in the directory of the ifc
|
||||
#
|
||||
# none of both is given:
|
||||
# use current directory and the ifc from feature files
|
||||
|
||||
|
||||
# TODO: add arg for run_intmp_tests() to bimtester.py
|
||||
|
||||
|
||||
def run_intmp_tests(args={}):
|
||||
|
||||
"""
|
||||
run bimtester unit test in a temporary directory
|
||||
features, steps and environment.py are copied to a temp directory
|
||||
|
||||
Keys of parameter args
|
||||
----------------------
|
||||
features: optional (ATM mandatory)
|
||||
the path the features directory with feature files is in
|
||||
ifcfile: optional (ATM mandatory)
|
||||
the ifc file
|
||||
advanced_arguments: optional
|
||||
they will be directly passed to the behave call
|
||||
|
||||
features and ifcfile are given:
|
||||
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
|
||||
|
||||
none of both is given (TODO):
|
||||
the current directory = features
|
||||
the ifcfile provided in the feature files is used
|
||||
|
||||
TODO: if the above is implemented adapt signature of run_all
|
||||
"""
|
||||
|
||||
from behave import __version__ as behave_version
|
||||
# https://github.com/behave/behave/issues/871
|
||||
if behave_version == "1.2.5":
|
||||
@@ -137,32 +135,31 @@ def run_intmp_tests(args={}):
|
||||
)
|
||||
return False
|
||||
|
||||
# mandatory parameter: ifcdir, featuredir
|
||||
# optional parameter: ifcfilename
|
||||
# copy features and steps to tmp, replace ifcdir in features files
|
||||
# run
|
||||
|
||||
# get ifcpath, this is the path the ifc file is in
|
||||
if "ifcpath" in args and args["ifcpath"] != "":
|
||||
# TODO check if path exists
|
||||
ifc_path = args["ifcpath"]
|
||||
else:
|
||||
print("No ifc path was given.")
|
||||
return False
|
||||
|
||||
# get the features_path, the feature files where the tests are in
|
||||
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")
|
||||
else:
|
||||
# TODO assume features beside ifc thus use ifc path
|
||||
print("No features path was given.")
|
||||
return False
|
||||
|
||||
if "ifcfilename" in args and args["ifcfilename"] != "":
|
||||
# TODO check if file
|
||||
ifc_filename = args["ifcfilename"]
|
||||
# get ifc path and ifc filename
|
||||
if "ifcfile" in args and args["ifcfile"] != "":
|
||||
ifcfile = args["ifcfile"]
|
||||
ifc_path = os.path.dirname(os.path.realpath(ifcfile))
|
||||
if os.path.isdir(ifc_path) is False:
|
||||
print("ifc path does not exist.")
|
||||
return False
|
||||
if os.path.isfile(ifcfile) is True:
|
||||
ifc_filename = os.path.basename(ifcfile)
|
||||
else:
|
||||
print("ifc file '{}' does not exist.".format(ifcfile))
|
||||
return False
|
||||
else:
|
||||
ifc_filename = None
|
||||
# TODO use ifc path from feature files
|
||||
print("No ifc file was given.")
|
||||
return False
|
||||
|
||||
# set up paths
|
||||
# a unique temp path should not be used
|
||||
@@ -277,33 +274,32 @@ def run_intmp_tests(args={}):
|
||||
return run_path
|
||||
|
||||
|
||||
def run_all(the_features_path, the_ifcfile_path, the_ifcfile_name=None):
|
||||
def run_all(the_features_path, the_ifcfile):
|
||||
|
||||
# feature files
|
||||
# run bimtester
|
||||
runpath = run_intmp_tests({
|
||||
"features": the_features_path,
|
||||
"ifcfile": the_ifcfile
|
||||
})
|
||||
print(runpath)
|
||||
|
||||
# check if it worked out well
|
||||
if runpath is False:
|
||||
print("BIMTester behave tests returned False.")
|
||||
return False
|
||||
|
||||
if not os.path.isdir(runpath):
|
||||
print("runpath does not exist. This should not happen. Debug")
|
||||
return False
|
||||
|
||||
# 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")
|
||||
)
|
||||
# print(feature_files)
|
||||
|
||||
# run bimtester
|
||||
if the_ifcfile_name is None:
|
||||
runpath = run_intmp_tests({
|
||||
"features": the_features_path,
|
||||
"ifcpath": the_ifcfile_path
|
||||
})
|
||||
else:
|
||||
runpath = run_intmp_tests({
|
||||
"features": the_features_path,
|
||||
"ifcpath": the_ifcfile_path,
|
||||
"ifcfilename": the_ifcfile_name
|
||||
})
|
||||
|
||||
# create html report
|
||||
from .reports import generate_report
|
||||
generate_report(runpath)
|
||||
# print(runpath)
|
||||
|
||||
# open the webbrowser
|
||||
for ff in feature_files:
|
||||
webbrowser.open(os.path.join(
|
||||
runpath,
|
||||
|
||||
Reference in New Issue
Block a user