mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
bimtester: improve and fix copy in temp and run
This commit is contained in:
@@ -1,3 +0,0 @@
|
|||||||
# dummy file to be able to run the command to get a list of all steps
|
|
||||||
# the command has to be run in the parent directory of this one
|
|
||||||
# behave --steps-catalog
|
|
||||||
@@ -147,29 +147,22 @@ def run_copyintmp_tests(args={}):
|
|||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if ("features" in args and args["features"] != ""):
|
# get the features_path, the dir where the feature files to test are in
|
||||||
|
if ("featuresdir" in args and args["featuresdir"] != ""):
|
||||||
is_features = True
|
is_features = True
|
||||||
else:
|
the_features_path = os.path.join(args["featuresdir"], "features")
|
||||||
is_features = False
|
|
||||||
if ("ifcfile" in args and args["ifcfile"] != ""):
|
|
||||||
is_ifcfile = True
|
|
||||||
else:
|
|
||||||
is_ifcfile = False
|
|
||||||
|
|
||||||
if is_features is True and is_ifcfile is True:
|
|
||||||
# features and ifcfile are given:
|
|
||||||
# the ifcfile in feature files is replaced
|
|
||||||
|
|
||||||
# get the features_path, the dir where the feature files to test are in
|
|
||||||
the_features_path = os.path.join(args["features"], "features")
|
|
||||||
if not os.path.isdir(the_features_path):
|
if not os.path.isdir(the_features_path):
|
||||||
print(
|
print(
|
||||||
"Error, the features directory '{}' does not exist."
|
"Error, the features directory '{}' does not exist."
|
||||||
.format(the_features_path)
|
.format(the_features_path)
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
else:
|
||||||
|
is_features = False
|
||||||
|
|
||||||
# get ifc path and ifc filename
|
# get ifc path and ifc filename
|
||||||
|
if ("ifcfile" in args and args["ifcfile"] != ""):
|
||||||
|
is_ifcfile = True
|
||||||
ifcfile = args["ifcfile"]
|
ifcfile = args["ifcfile"]
|
||||||
ifc_path = os.path.dirname(os.path.realpath(ifcfile))
|
ifc_path = os.path.dirname(os.path.realpath(ifcfile))
|
||||||
if os.path.isdir(ifc_path) is False:
|
if os.path.isdir(ifc_path) is False:
|
||||||
@@ -180,25 +173,33 @@ def run_copyintmp_tests(args={}):
|
|||||||
else:
|
else:
|
||||||
print("Error, the ifc file '{}' does not exist.".format(ifcfile))
|
print("Error, the ifc file '{}' does not exist.".format(ifcfile))
|
||||||
return False
|
return False
|
||||||
|
else:
|
||||||
|
is_ifcfile = False
|
||||||
|
|
||||||
|
# print(is_features)
|
||||||
|
# print(is_ifcfile)
|
||||||
|
|
||||||
|
if is_features is True and is_ifcfile is True:
|
||||||
|
print("features given, ifcfile given.")
|
||||||
|
# the ifcfile in feature files is replaced
|
||||||
|
|
||||||
elif is_features is False and is_ifcfile is True:
|
elif is_features is False and is_ifcfile is True:
|
||||||
# ifcfile only is given (TODO):
|
print("features given, ifcfile NOT given.")
|
||||||
# features = ifcfile directory
|
# features = ifcfile directory
|
||||||
# the ifcfile in feature files is replaced
|
# the ifcfile in feature files is replaced
|
||||||
print("Not yet implemented: features was NOT given, ifcfile was given.")
|
the_features_path = os.path.join(ifc_path, "features")
|
||||||
return False
|
|
||||||
|
|
||||||
elif is_features is True and is_ifcfile is False:
|
elif is_features is True and is_ifcfile is False:
|
||||||
# features only is given (TODO):
|
print("features given, ifcfile NOT given.")
|
||||||
# the ifcfile provided in the feature files is used
|
# the ifcfile provided in the feature files is used
|
||||||
print("Not yet implemented: features was given, ifcfile was NOT given.")
|
print("Not yet implemented.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
elif is_features is False and is_ifcfile is False:
|
elif is_features is False and is_ifcfile is False:
|
||||||
# none of both is given (TODO):
|
print("features NOT given, ifcfile NOT given.")
|
||||||
# the current directory = features
|
# the current directory = features
|
||||||
# the ifcfile provided in the feature files is used
|
# the ifcfile provided in the feature files is used
|
||||||
print("Not yet implemented: features NOT was given, ifcfile was NOT given.")
|
print("Not yet implemented.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -216,7 +217,10 @@ def run_copyintmp_tests(args={}):
|
|||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
rmtree(copy_base_path) # fails on read only files
|
rmtree(copy_base_path) # fails on read only files
|
||||||
if os.path.isdir(copy_base_path):
|
if os.path.isdir(copy_base_path):
|
||||||
print("Delete former beimtester run dir {} failed".format(copy_base_path))
|
print(
|
||||||
|
"Delete former beimtester run dir '{}' failed"
|
||||||
|
.format(copy_base_path)
|
||||||
|
)
|
||||||
return False
|
return False
|
||||||
os.mkdir(copy_base_path)
|
os.mkdir(copy_base_path)
|
||||||
report_path = os.path.join(copy_base_path, "report")
|
report_path = os.path.join(copy_base_path, "report")
|
||||||
@@ -286,40 +290,36 @@ def run_copyintmp_tests(args={}):
|
|||||||
# the print replaces the line in the file
|
# the print replaces the line in the file
|
||||||
print(line.replace(theline, newifcline), end="")
|
print(line.replace(theline, newifcline), end="")
|
||||||
|
|
||||||
# get advanced args
|
# get behave args
|
||||||
# print to console from inside step files, add "--no-capture" flag
|
|
||||||
# https://github.com/behave/behave/issues/346
|
|
||||||
behave_args = [copy_features_path]
|
behave_args = [copy_features_path]
|
||||||
|
behave_args.extend([
|
||||||
|
# redirect prints in step methods
|
||||||
|
# if step fails some output is catched, thus might not be printed
|
||||||
|
# https://github.com/behave/behave/issues/346
|
||||||
|
"--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]),
|
||||||
|
# next two lines are one arg
|
||||||
|
"--define",
|
||||||
|
"localedir={}".format(locale_path)
|
||||||
|
])
|
||||||
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:
|
from json import dumps
|
||||||
behave_args.extend([
|
print(dumps(behave_args, indent=4))
|
||||||
# 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]),
|
|
||||||
# next two lines are one arg
|
|
||||||
"--define",
|
|
||||||
"localedir={}".format(locale_path)
|
|
||||||
])
|
|
||||||
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.")
|
||||||
|
|
||||||
# delete steps
|
|
||||||
# shutil.rmtree(steps_path)
|
|
||||||
|
|
||||||
return copy_base_path
|
return copy_base_path
|
||||||
|
|
||||||
|
|
||||||
@@ -327,7 +327,7 @@ def run_all(the_features_path, the_ifcfile):
|
|||||||
|
|
||||||
# run bimtester
|
# run bimtester
|
||||||
runpath = run_copyintmp_tests({
|
runpath = run_copyintmp_tests({
|
||||||
"features": the_features_path,
|
"featuresdir": the_features_path,
|
||||||
"ifcfile": the_ifcfile
|
"ifcfile": the_ifcfile
|
||||||
})
|
})
|
||||||
print(runpath)
|
print(runpath)
|
||||||
|
|||||||
Reference in New Issue
Block a user