Add test that dropping vase in tghe soft room does not break it.
[open-adventure.git] / tests / coverage_dungeon.py
index 57180b5b4459d8d82eb960da27487ae4bdc02a9d..182930cb878511ea881a3473fb28ff71e119f80e 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # This is the open-adventure dungeon text coverage report generator. It
 # consumes a YAML description of the dungeon and determines whether the
@@ -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"
 
@@ -66,10 +71,10 @@ def search(needle, haystack):
     needle_san = re.escape(needle) \
              .replace("\\n", "\n") \
              .replace("\\t", "\t") \
-             .replace("\%S", ".*") \
-             .replace("\%s", ".*") \
-             .replace("\%d", ".*") \
-             .replace("\%V", ".*")
+             .replace("%S", ".*") \
+             .replace("%s", ".*") \
+             .replace("%d", ".*") \
+             .replace("%V", ".*")
 
     return re.search(needle_san, haystack)
 
@@ -152,13 +157,13 @@ def arb_coverage(arb_msgs, text, report):
             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 and search(item["message"], text):
+        if report["messages"][name]["covered"] != True and (search(item["message"], text) or name in DANGLING):
             report["messages"][name]["covered"] = True
             report["covered"] += 1
 
@@ -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"])
 
@@ -193,7 +197,7 @@ if __name__ == "__main__":
     # load DB
     try:
         with open(YAML_PATH, "r") as f:
-            db = yaml.load(f)
+            db = yaml.safe_load(f)
     except IOError as e:
         print('ERROR: could not load {} ({}})'.format(YAML_PATH, e.strerror))
         exit(-1)
@@ -219,7 +223,7 @@ if __name__ == "__main__":
             category["percent"] = (category["covered"] / float(category["total"])) * 100
 
             # render section header
-            cat_messages = sorted(category["messages"].items())
+            cat_messages = list(category["messages"].items())
             cat_keys = cat_messages[0][1].keys()
             headers_html = ""
             colspan = 10 - len(cat_keys)