Merge branch 'v0.6.0' of https://github.com/IfcOpenShell/IfcOpenShell into presentationlayer

This commit is contained in:
Kristoffer
2020-11-08 11:25:04 +01:00
+28 -6
View File
@@ -67,13 +67,25 @@ def get_features(args):
return has_features return has_features
def generate_report(): def generate_report(adir="."):
print("# Generating HTML reports now.") print("# Generating HTML reports now.")
if not os.path.exists("report"):
os.mkdir("report") # get html template
report_path = "report/report.json" 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): if not os.path.exists(report_path):
return print("No report data was found.") return print("No report data was found.")
# read json report and create html report for each feature
report = json.loads(open(report_path).read()) report = json.loads(open(report_path).read())
for feature in report: for feature in report:
file_name = os.path.basename(feature["location"]).split(":")[0] file_name = os.path.basename(feature["location"]).split(":")[0]
@@ -85,6 +97,13 @@ def generate_report():
"is_success": feature["status"] == "passed", "is_success": feature["status"] == "passed",
"scenarios": [], "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"]: for scenario in feature["elements"]:
steps = [] steps = []
total_duration = 0 total_duration = 0
@@ -117,6 +136,7 @@ def generate_report():
data["scenarios"].append( data["scenarios"].append(
{ {
"name": scenario["name"], "name": scenario["name"],
# on behave < 1.2.6 there is no 'status' thus report fails
"is_success": scenario["status"] == "passed", "is_success": scenario["status"] == "passed",
"time": round(total_duration, 2), "time": round(total_duration, 2),
"steps": steps, "steps": steps,
@@ -129,8 +149,10 @@ def generate_report():
data["total_steps"] = sum([s["total_steps"] for s in data["scenarios"]]) data["total_steps"] = sum([s["total_steps"] for s in data["scenarios"]])
data["pass_rate"] = round((data["total_passes"] / data["total_steps"]) * 100) data["pass_rate"] = round((data["total_passes"] / data["total_steps"]) * 100)
with open("report/{}.html".format(file_name), "w") as out: # create the html file
with open(get_resource_path("features/template.html")) as template: 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)) out.write(pystache.render(template.read(), data))