+def threshold_coverage(classes, text, report):
+ # works for class thresholds and turn threshold, which have a "message"
+ # property
+ for name, item in enumerate(classes):
+ if name not in report["messages"]:
+ report["messages"][name] = {"covered": False}
+ report["total"] += 1
+ if not report["messages"][name]["covered"] and search(item["message"], text):
+ report["messages"][name]["covered"] = True
+ report["covered"] += 1
+
+
+def arb_coverage(arb_msgs, text, report):
+ for name, message in arb_msgs:
+ if name not in report["messages"]:
+ report["messages"][name] = {"covered": False}
+ report["total"] += 1
+ if not report["messages"][name]["covered"] and (
+ search(message, text) or name in DANGLING_MESSAGES
+ ):
+ report["messages"][name]["covered"] = True
+ report["covered"] += 1
+
+
+def actions_coverage(items, text, report):
+ # works for actions
+ for name, item in items:
+ if name not in report["messages"]:
+ report["messages"][name] = {"covered": False}
+ report["total"] += 1
+ if not report["messages"][name]["covered"] and (
+ search(item["message"], text) or name in DANGLING_ACTIONS
+ ):
+ report["messages"][name]["covered"] = True
+ report["covered"] += 1
+
+
+def coverage_report(db, check_file_contents):
+ # Create report for each category, including total items, number of items
+ # covered, and a list of the covered messages
+ report = {}
+ for name in db.keys():
+ # initialize each catagory
+ report[name] = {
+ "name": name, # convenience for string formatting
+ "total": 0,
+ "covered": 0,
+ "messages": {},
+ }
+
+ # search for each message in every test check file
+ for chk in check_file_contents:
+ arb_coverage(db["arbitrary_messages"], chk, report["arbitrary_messages"])
+ hint_coverage(db["hints"], chk, report["hints"])
+ loc_coverage(db["locations"], chk, report["locations"])
+ obit_coverage(db["obituaries"], chk, report["obituaries"])
+ obj_coverage(db["objects"], chk, report["objects"])
+ actions_coverage(db["actions"], chk, report["actions"])
+ threshold_coverage(db["classes"], chk, report["classes"])
+ threshold_coverage(db["turn_thresholds"], chk, report["turn_thresholds"])
+
+ return report
+
+
+if __name__ == "__main__":
+ # load DB
+ try:
+ with open(YAML_PATH, "r", encoding="ascii", errors="surrogateescape") as f:
+ db = yaml.safe_load(f)
+ except IOError as e:
+ print("ERROR: could not load %s (%s)" % (YAML_PATH, e.strerror))
+ sys.exit(-1)
+
+ # get contents of all the check files
+ check_file_contents = []
+ for filename in os.listdir(TEST_DIR):