mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-28 19:27:10 +00:00
BIMTester custom schema is now specified as an argument, not as a test requirement, which is where it belongs.
This commit is contained in:
@@ -3,18 +3,21 @@ import sys
|
|||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
|
import ifcopenshell.express
|
||||||
import behave.formatter.pretty # Needed for pyinstaller to package it
|
import behave.formatter.pretty # Needed for pyinstaller to package it
|
||||||
from bimtester.ifc import IfcStore
|
from bimtester.ifc import IfcStore
|
||||||
from bimtester.lang import switch_locale
|
|
||||||
from behave import __version__ as behave_version
|
|
||||||
from behave.__main__ import main as behave_main
|
from behave.__main__ import main as behave_main
|
||||||
|
|
||||||
|
|
||||||
class TestRunner:
|
class TestRunner:
|
||||||
def __init__(self, ifc_path, ifc=None):
|
def __init__(self, ifc_path, ifc=None, schema=None):
|
||||||
IfcStore.path = ifc_path
|
IfcStore.path = ifc_path
|
||||||
IfcStore.file = ifc if ifc else ifcopenshell.open(ifc_path)
|
IfcStore.file = ifc if ifc else ifcopenshell.open(ifc_path)
|
||||||
|
|
||||||
|
if schema:
|
||||||
|
schema = ifcopenshell.express.parse(path)
|
||||||
|
ifcopenshell.register_schema(schema)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# PyInstaller creates a temp folder and stores path in _MEIPASS
|
# PyInstaller creates a temp folder and stores path in _MEIPASS
|
||||||
self.base_path = sys._MEIPASS
|
self.base_path = sys._MEIPASS
|
||||||
@@ -24,35 +27,26 @@ class TestRunner:
|
|||||||
self.locale_path = os.path.join(self.base_path, "locale")
|
self.locale_path = os.path.join(self.base_path, "locale")
|
||||||
|
|
||||||
def run(self, args):
|
def run(self, args):
|
||||||
print("# Run tests.")
|
|
||||||
tmpdir = tempfile.mkdtemp()
|
tmpdir = tempfile.mkdtemp()
|
||||||
features_path = os.path.join(tmpdir, "features")
|
features_path = os.path.join(tmpdir, "features")
|
||||||
report_json = os.path.join(tmpdir, "report.json")
|
report_json = os.path.join(tmpdir, "report.json")
|
||||||
shutil.copytree(os.path.join(self.base_path, "features"), features_path)
|
shutil.copytree(os.path.join(self.base_path, "features"), features_path)
|
||||||
shutil.copy(args["feature"], features_path)
|
shutil.copy(args["feature"], features_path)
|
||||||
behave_main(self.get_behave_args(args, features_path, report_json))
|
behave_main(self.get_behave_args(args, features_path, report_json))
|
||||||
print("# All tests are finished.")
|
|
||||||
return report_json
|
return report_json
|
||||||
|
|
||||||
def get_behave_args(self, args, features_path, report_json):
|
def get_behave_args(self, args, features_path, report_json):
|
||||||
behave_args = [features_path]
|
behave_args = [features_path]
|
||||||
|
|
||||||
behave_args.extend(["--define", "localedir={}".format(self.locale_path)])
|
behave_args.extend(["--define", "localedir={}".format(self.locale_path)])
|
||||||
|
|
||||||
if args["advanced_arguments"]:
|
if args["advanced_arguments"]:
|
||||||
behave_args.extend(args["advanced_arguments"].split())
|
behave_args.extend(args["advanced_arguments"].split())
|
||||||
|
|
||||||
if args["ifc"]:
|
if args["ifc"]:
|
||||||
behave_args.extend(["--define", "ifc={}".format(args["ifc"])])
|
behave_args.extend(["--define", "ifc={}".format(args["ifc"])])
|
||||||
|
|
||||||
if args["path"]:
|
if args["path"]:
|
||||||
behave_args.extend(["--define", "path={}".format(args["path"])])
|
behave_args.extend(["--define", "path={}".format(args["path"])])
|
||||||
|
|
||||||
if args["lang"]:
|
if args["lang"]:
|
||||||
behave_args.extend(["--lang={}".format(args["lang"])])
|
behave_args.extend(["--lang={}".format(args["lang"])])
|
||||||
|
|
||||||
if not args["console"]:
|
if not args["console"]:
|
||||||
# https://github.com/behave/behave/issues/346
|
# https://github.com/behave/behave/issues/346
|
||||||
behave_args.extend(["--no-capture", "--format", "json.pretty", "--outfile", report_json])
|
behave_args.extend(["--no-capture", "--format", "json.pretty", "--outfile", report_json])
|
||||||
|
|
||||||
return behave_args
|
return behave_args
|
||||||
|
|||||||
@@ -14,15 +14,14 @@ parser.add_argument("-f", "--feature", type=str, help="Specify a feature file to
|
|||||||
parser.add_argument("-i", "--ifc", type=str, help="Specify a ifc file", required=True)
|
parser.add_argument("-i", "--ifc", type=str, help="Specify a ifc file", required=True)
|
||||||
parser.add_argument("-p", "--path", type=str, help="Define a path for use in tests")
|
parser.add_argument("-p", "--path", type=str, help="Define a path for use in tests")
|
||||||
parser.add_argument("-r", "--report", type=str, help="Specify an output file for a HTML report")
|
parser.add_argument("-r", "--report", type=str, help="Specify an output file for a HTML report")
|
||||||
|
parser.add_argument("--schema", type=str, help="Specify an output file for a HTML report")
|
||||||
parser.add_argument("--lang", type=str, help="Specify a language", default="")
|
parser.add_argument("--lang", type=str, help="Specify a language", default="")
|
||||||
|
|
||||||
args = vars(parser.parse_args())
|
args = vars(parser.parse_args())
|
||||||
|
|
||||||
if args["action"] == "run":
|
if args["action"] == "run":
|
||||||
report_json = bimtester.run.TestRunner(args["ifc"]).run(args)
|
report_json = bimtester.run.TestRunner(args["ifc"], schema=args["schema"] or None).run(args)
|
||||||
if args["report"]:
|
if args["report"]:
|
||||||
bimtester.reports.ReportGenerator().generate(report_json, args["report"])
|
bimtester.reports.ReportGenerator().generate(report_json, args["report"])
|
||||||
elif args["action"] == "purge":
|
elif args["action"] == "purge":
|
||||||
bimtester.clean.TestPurger().purge()
|
bimtester.clean.TestPurger().purge()
|
||||||
|
|
||||||
print("# All tasks are complete :-)")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user