- with open(filename, "r") as chk:
- text = chk.read()
- loc_coverage(locations, text)
- arb_coverage(arb_msgs, text)
- obj_coverage(objects, text)
-
- print("\nadventure.yaml coverage rate:")
-
- location_html = ""
- location_total = len(locations) * 2
- location_covered = 0
- for locouter in locations:
- locname = locouter[0]
- loc = locouter[1]
- long_success = "covered"
- short_success = "covered"
- if loc["description"]["long"] != True:
- long_success = "uncovered"
- else:
- location_covered += 1
-
- if loc["description"]["short"] != True:
- short_success = "uncovered"
- else:
- location_covered += 1
-
- location_html += location_row.format(locname, long_success, short_success)
- location_percent = round((location_covered / location_total) * 100, 1)
- print(" locations..........: {}% covered ({} of {})".format(location_percent, location_covered, location_total))
-
- arb_msg_html = ""
- arb_total = len(arb_msgs)
- arb_covered = 0
- for name, msg in arb_msgs:
- success = "covered"
- if msg != True:
- success = "uncovered"
- else:
- arb_covered += 1
- arb_msg_html += arb_msg_row.format(name, success)
- arb_percent = round((arb_covered / arb_total) * 100, 1)
- print(" arbitrary_messages.: {}% covered ({} of {})".format(arb_percent, arb_covered, arb_total))
-
- object_html = ""
- objects_total = 0
- objects_covered = 0
- for (obj_name, obj) in objects:
- if obj["descriptions"]:
- for j, desc in enumerate(obj["descriptions"]):
- objects_total += 1
- success = "covered"
- if desc != True:
- success = "uncovered"
- else:
- objects_covered += 1
- object_html += object_row.format("%s[%d]" % (obj_name, j), success)
- objects_percent = round((objects_covered / objects_total) * 100, 1)
- print(" objects............: {}% covered ({} of {})".format(objects_percent, objects_covered, objects_total))
-
- with open(html_output_path, "w") as f:
- f.write(html_template.format(
- location_total, location_covered, location_percent,
- arb_total, arb_covered, arb_percent,
- objects_total, objects_covered, objects_percent,
- location_html, arb_msg_html, object_html
- ))
+ with open(filename, "r") as f:
+ check_file_contents.append(f.read())
+
+ # run coverage analysis report on dungeon database
+ report = coverage_report(db, check_file_contents)
+
+ # render report output
+ categories_html = ""
+ summary_html = ""
+ summary_stdout = "adventure.yaml coverage rate:\n"
+ for name, category in sorted(report.items()):
+ # ignore categories with zero entries
+ if category["total"] > 0:
+ # Calculate percent coverage
+ category["percent"] = (category["covered"] / float(category["total"])) * 100
+
+ # render section header
+ cat_messages = list(category["messages"].items())
+ cat_keys = cat_messages[0][1].keys()
+ headers_html = ""
+ colspan = 10 - len(cat_keys)
+ for key in cat_keys:
+ headers_html += HTML_CATEGORY_HEADER_CELL.format(key)
+ category_html = HTML_CATEGORY_HEADER.format(colspan=colspan, label=category["name"], cells=headers_html)
+
+ # render message coverage row
+ for message_id, covered in cat_messages:
+ category_html_row = ""
+ for key, value in covered.items():
+ category_html_row += HTML_CATEGORY_COVERAGE_CELL.format("uncovered" if not value else "covered")
+ category_html += HTML_CATEGORY_ROW.format(id=message_id,colspan=colspan, cells=category_html_row)
+ categories_html += HTML_CATEGORY_SECTION.format(id=name, rows=category_html)
+
+ # render category summaries
+ summary_stdout += STDOUT_REPORT_CATEGORY.format(**category)
+ summary_html += HTML_SUMMARY_ROW.format(**category)
+
+ # output some quick report stats
+ print(summary_stdout)
+
+ if len(sys.argv) > 1:
+ html_output_path = sys.argv[1]
+ else:
+ html_output_path = DEFAULT_HTML_OUTPUT_PATH
+
+ # render HTML report
+ try:
+ with open(HTML_TEMPLATE_PATH, "r") as f:
+ # read in HTML template
+ html_template = f.read()
+ except IOError as e:
+ print('ERROR: reading HTML report template failed ({})'.format(e.strerror))
+ sys.exit(-1)
+
+ # parse template with report and write it out
+ try:
+ with open(html_output_path, "w") as f:
+ f.write(html_template.format(categories=categories_html, summary=summary_html))
+ except IOError as e:
+ print('ERROR: writing HTML report failed ({})'.format(e.strerror))