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"
STDOUT_REPORT_CATEGORY = " {name:.<19}: {percent:5.1f}% covered ({covered} of {total})\n"
-HTML_SUMMARY_ROW = """
+HTML_SUMMARY_ROW = '''
<tr>
<td class="headerItem"><a href="#{name}">{name}:</a></td>
<td class="headerCovTableEntry">{total}</td>
<td class="headerCovTableEntry">{covered}</td>
<td class="headerCovTableEntry">{percent:.1f}%</td>
</tr>
-"""
+'''
-HTML_CATEGORY_SECTION = """
+HTML_CATEGORY_SECTION = '''
<tr id="{id}"></tr>
{rows}
<tr>
<td> </td>
</tr>
-"""
+'''
-HTML_CATEGORY_HEADER = """
+HTML_CATEGORY_HEADER = '''
<tr>
<td class="tableHead" width="60%" colspan="{colspan}">{label}</td>
{cells}
</tr>
-"""
+'''
HTML_CATEGORY_HEADER_CELL = '<td class="tableHead" width="15%">{}</td>\n'
HTML_CATEGORY_COVERAGE_CELL = '<td class="{}"> </td>\n'
-HTML_CATEGORY_ROW = """
+HTML_CATEGORY_ROW = '''
<tr>
<td class="coverFile" colspan="{colspan}">{id}</td>
{cells}
</tr>
-"""
+'''
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", ".*") \
.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
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
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):
+ 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
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"])
category["percent"] = (category["covered"] / float(category["total"])) * 100
# render section header
- cat_keys = list(category["messages"].items())[0][1].keys()
+ cat_messages = sorted(category["messages"].items())
+ cat_keys = cat_messages[0][1].keys()
headers_html = ""
colspan = 10 - len(cat_keys)
for key in cat_keys:
category_html = HTML_CATEGORY_HEADER.format(colspan=colspan, label=category["name"], cells=headers_html)
# render message coverage row
- for message_id, covered in sorted(category["messages"].items()):
+ 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 value != True else "covered")