BIMTester can now accept both IDS .xml as well as Gherkin .feature files and generate HTML reports

This commit is contained in:
Dion Moult
2021-02-28 14:35:21 +11:00
parent 36cfb0d3f5
commit 4e889b75d7
4 changed files with 69 additions and 6 deletions
+3 -3
View File
@@ -21,12 +21,12 @@ class ReportGenerator:
self.generate_feature_report(feature, output_file)
def generate_feature_report(self, feature, output_file):
file_name = os.path.basename(feature["location"]).split(":")[0]
# file_name = os.path.basename(feature["location"]).split(":")[0]
data = {
"file_name": file_name,
# "file_name": file_name,
"time": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"name": feature["name"],
"description": feature["description"],
"description": feature.get("description", ""),
"is_success": feature["status"] == "passed",
"scenarios": [],
}
@@ -35,11 +35,11 @@
<span class="{{#is_success}}success{{/is_success}}{{^is_success}}failure{{/is_success}}">{{#is_success}}{{_success}}{{/is_success}}{{^is_success}}{{_failure}}{{/is_success}}</span>
{{_tests_passed}}: <strong>{{total_passes}} / {{total_steps}}</strong> ({{pass_rate}}%)
<br />
{{#description}}
<p class="description">
{{#description}}
{{.}}<br />
{{/description}}
</p>
{{/description}}
<hr>
</header>
{{#scenarios}}
+63
View File
@@ -1,6 +1,8 @@
import os
import sys
import json
import shutil
import logging
import tempfile
import ifcopenshell
@@ -14,6 +16,46 @@ from distutils.dir_util import copy_tree
from behave.__main__ import main as behave_main
# TODO: refactor when this isn't super experimental
from logging import StreamHandler
class IDSHandler(StreamHandler):
def __init__(self):
StreamHandler.__init__(self)
self.results = {
"name": "Specification name",
"status": "passed",
"location": "filename.xml",
"elements": [
{
"keyword": "Scenario",
"name": "Checking IDS specifications",
"status": "passed",
"steps": []
}
]
}
def emit(self, record):
msg = self.format(record)
# Obviously, not a final product
is_fail = "is compliant" not in msg
if is_fail:
self.results["status"] = "failed"
self.results["elements"][0]["status"] = "failed"
self.results["elements"][0]["steps"].append({
"keyword": "*",
"match": {},
"name": msg,
"result": {
"duration": 0.0,
"error_message": "Assertion Failed",
"status": "failed" if is_fail else "passed"
},
"step_type": "given"
})
class TestRunner:
def __init__(self, ifc_path, schema_path=None, ifc=None):
IfcStore.path = ifc_path
@@ -34,6 +76,27 @@ class TestRunner:
self.locale_path = os.path.join(self.base_path, "locale")
def run(self, args):
if args["feature"][-4:].lower() == ".xml":
return self.test_ids(args)
return self.test_feature(args)
def test_ids(self, args):
# Local import whilst this is experimental
import ifcopenshell.ids
logger = logging.getLogger("IDS")
logging.basicConfig(level=logging.INFO, format="%(message)s")
ids_handler = IDSHandler()
logger.addHandler(ids_handler)
ids_file = ifcopenshell.ids.ids(args["feature"])
ids_file.validate(IfcStore.file, logger)
tmpdir = tempfile.mkdtemp()
report_json = os.path.join(tmpdir, "report.json")
json.dump([ids_handler.results], open(report_json, "w"))
return report_json
def test_feature(self, args):
tmpdir = tempfile.mkdtemp()
features_path = os.path.join(tmpdir, "features")
steps_path = os.path.join(features_path, "steps")
+1 -1
View File
@@ -10,7 +10,7 @@ parser = argparse.ArgumentParser(description="Runs unit tests for BIM data")
parser.add_argument("-a", "--action", type=str, help="Action to perform, from run/purge", default="run")
parser.add_argument("--advanced-arguments", type=str, help="Specify arguments to Behave", default="")
parser.add_argument("-c", "--console", action="store_true", help="Show results in the console")
parser.add_argument("-f", "--feature", type=str, help="Specify a feature file to test", required=True)
parser.add_argument("-f", "--feature", type=str, help="Specify a feature file or IDS to test", required=True)
parser.add_argument("-i", "--ifc", type=str, help="Specify an IFC file to test", required=True)
parser.add_argument("-p", "--path", type=str, help="Define a path for use in test steps that use relative paths")
parser.add_argument("-r", "--report", type=str, help="Specify an output file for a HTML report")