X-Git-Url: https://jxself.org/git/?p=open-adventure.git;a=blobdiff_plain;f=tests%2Fcoverage_dungeon.py;h=365995ce644598d9178f8cd976e8a19b50a052c9;hp=e991bdd1c86fddb87a77ec570f87de8235d203a0;hb=42c66160a77370e7f70a9024f5d1eff3ef2710cd;hpb=3be0cb3596a537a39311107734ad04ad7adbe550 diff --git a/tests/coverage_dungeon.py b/tests/coverage_dungeon.py index e991bdd..365995c 100755 --- a/tests/coverage_dungeon.py +++ b/tests/coverage_dungeon.py @@ -6,6 +6,10 @@ # # The default HTML output is appropriate for use with Gitlab CI. # You can override it with a command-line argument. +# +# The DANGLING list is for actions that should be considered always found +# even if the checkfile search doesn't find them. Typically this will because +# they emit a templated message that can't be regression-tested by equality. import os import sys @@ -14,8 +18,9 @@ import re TEST_DIR = "." YAML_PATH = "../adventure.yaml" -HTML_TEMPLATE_PATH = "coverage_dungeon.html.tpl" +HTML_TEMPLATE_PATH = "../templates/coverage_dungeon.html.tpl" DEFAULT_HTML_OUTPUT_PATH = "../coverage/adventure.yaml.html" +DANGLING = ["ACT_VERSION"] STDOUT_REPORT_CATEGORY = " {name:.<19}: {percent:5.1f}% covered ({covered} of {total})\n" @@ -58,7 +63,12 @@ def search(needle, haystack): # Search for needle in haystack, first escaping needle for regex, then # replacing %s, %d, etc. with regex wildcards, so the variable messages # within the dungeon definition will actually match - needle = re.escape(needle) \ + + if needle == None or needle == "" or needle == "NO_MESSAGE": + # if needle is empty, assume we're going to find an empty string + return True + + needle_san = re.escape(needle) \ .replace("\\n", "\n") \ .replace("\\t", "\t") \ .replace("\%S", ".*") \ @@ -66,7 +76,7 @@ def search(needle, haystack): .replace("\%d", ".*") \ .replace("\%V", ".*") - return re.search(needle, haystack) + return re.search(needle_san, haystack) def obj_coverage(objects, text, report): # objects have multiple descriptions based on state @@ -78,26 +88,24 @@ def obj_coverage(objects, text, report): if name not in report["messages"]: report["messages"][name] = {"covered" : False} report["total"] += 1 - if report["messages"][name]["covered"] != True: - if desc == None or desc == '' or search(desc, text): - report["messages"][name]["covered"] = True - report["covered"] += 1 + if report["messages"][name]["covered"] != True and search(desc, text): + report["messages"][name]["covered"] = True + report["covered"] += 1 def loc_coverage(locations, text, report): # locations have a long and a short description, that each have to # be checked seperately for name, loc in locations: + desc = loc["description"] if name not in report["messages"]: report["messages"][name] = {"long" : False, "short": False} report["total"] += 2 - if report["messages"][name]["long"] != True: - if loc["description"]["long"] == None or loc["description"]["long"] == '' or search(loc["description"]["long"], text): - report["messages"][name]["long"] = True - report["covered"] += 1 - if report["messages"][name]["short"] != True: - if loc["description"]["short"] == None or loc["description"]["short"] == '' or search(loc["description"]["short"], text): - report["messages"][name]["short"] = True - report["covered"] += 1 + if report["messages"][name]["long"] != True and search(desc["long"], text): + report["messages"][name]["long"] = True + report["covered"] += 1 + if report["messages"][name]["short"] != True and search(desc["short"], text): + report["messages"][name]["short"] = True + report["covered"] += 1 def hint_coverage(obituaries, text, report): # hints have a "question" where the hint is offered, followed @@ -136,31 +144,28 @@ def threshold_coverage(classes, text, report): if name not in report["messages"]: report["messages"][name] = {"covered" : "False"} report["total"] += 1 - if report["messages"][name]["covered"] != True: - if item["message"] == None or item["message"] == "NO_MESSAGE" or search(item["message"], text): - report["messages"][name]["covered"] = True - report["covered"] += 1 + if report["messages"][name]["covered"] != True 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 report["messages"][name]["covered"] != True: - if message == None or search(message, text): - report["messages"][name]["covered"] = True - report["covered"] += 1 + if report["messages"][name]["covered"] != True and search(message, text): + report["messages"][name]["covered"] = True + report["covered"] += 1 -def specials_actions_coverage(items, text, report): - # works for actions or specials +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 report["messages"][name]["covered"] != True: - if item["message"] == None or item["message"] == "NO_MESSAGE" or search(item["message"], text): - report["messages"][name]["covered"] = True - report["covered"] += 1 + if report["messages"][name]["covered"] != True and (search(item["message"], text) or name in DANGLING): + report["messages"][name]["covered"] = True + report["covered"] += 1 def coverage_report(db, check_file_contents): # Create report for each catagory, including total items, number of items @@ -175,15 +180,14 @@ def coverage_report(db, check_file_contents): "messages" : {} } - # search for each message in ever test check file + # 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"]) - specials_actions_coverage(db["actions"], chk, report["actions"]) - specials_actions_coverage(db["specials"], chk, report["specials"]) + actions_coverage(db["actions"], chk, report["actions"]) threshold_coverage(db["classes"], chk, report["classes"]) threshold_coverage(db["turn_thresholds"], chk, report["turn_thresholds"])