From 05c952073b54a685d681134ffa8d1cafea8a4557 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Fri, 6 Nov 2020 21:21:18 +0100 Subject: [PATCH] bimtester: some small improvements --- src/ifcbimtester/bimtester.py | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/ifcbimtester/bimtester.py b/src/ifcbimtester/bimtester.py index 6a3246cee6..63496fa175 100755 --- a/src/ifcbimtester/bimtester.py +++ b/src/ifcbimtester/bimtester.py @@ -67,13 +67,25 @@ def get_features(args): return has_features -def generate_report(): +def generate_report(adir="."): print("# Generating HTML reports now.") - if not os.path.exists("report"): - os.mkdir("report") - report_path = "report/report.json" + + # get html template + html_template_file = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "features/template.html" + ) + + # get report file + report_dir = os.path.join(adir, "report") + if not os.path.exists(report_dir): + return print("No report directory was found.") + report_path = os.path.join(report_dir, "report.json") + # print(report_path) if not os.path.exists(report_path): return print("No report data was found.") + + # read json report and create html report for each feature report = json.loads(open(report_path).read()) for feature in report: file_name = os.path.basename(feature["location"]).split(":")[0] @@ -85,6 +97,13 @@ def generate_report(): "is_success": feature["status"] == "passed", "scenarios": [], } + if "elements" not in feature: + if "status" in feature and feature["status"] == "skipped": + print("Feature was skipped. No html report will be created.") + else: + print("For a unknown reason no html report well be created.") + # happens if the feature file does not consist of any valid Scenario + continue for scenario in feature["elements"]: steps = [] total_duration = 0 @@ -117,6 +136,7 @@ def generate_report(): data["scenarios"].append( { "name": scenario["name"], + # on behave < 1.2.6 there is no 'status' thus report fails "is_success": scenario["status"] == "passed", "time": round(total_duration, 2), "steps": steps, @@ -129,8 +149,10 @@ def generate_report(): data["total_steps"] = sum([s["total_steps"] for s in data["scenarios"]]) data["pass_rate"] = round((data["total_passes"] / data["total_steps"]) * 100) - with open("report/{}.html".format(file_name), "w") as out: - with open(get_resource_path("features/template.html")) as template: + # create the html file + html_report_file = os.path.join(report_dir, "{}.html".format(file_name)) + with open(html_report_file, "w") as out: + with open(html_template_file) as template: out.write(pystache.render(template.read(), data))