YAML coverage generator minor cleanup

This commit is contained in:
Aaron Traas 2017-07-17 10:57:13 -04:00 committed by Eric S. Raymond
parent 9fa52c7889
commit e9cd50ec38

View file

@ -58,7 +58,12 @@ def search(needle, haystack):
# Search for needle in haystack, first escaping needle for regex, then # Search for needle in haystack, first escaping needle for regex, then
# replacing %s, %d, etc. with regex wildcards, so the variable messages # replacing %s, %d, etc. with regex wildcards, so the variable messages
# within the dungeon definition will actually match # 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("\\n", "\n") \
.replace("\\t", "\t") \ .replace("\\t", "\t") \
.replace("\%S", ".*") \ .replace("\%S", ".*") \
@ -66,7 +71,7 @@ def search(needle, haystack):
.replace("\%d", ".*") \ .replace("\%d", ".*") \
.replace("\%V", ".*") .replace("\%V", ".*")
return re.search(needle, haystack) return re.search(needle_san, haystack)
def obj_coverage(objects, text, report): def obj_coverage(objects, text, report):
# objects have multiple descriptions based on state # objects have multiple descriptions based on state
@ -78,8 +83,7 @@ def obj_coverage(objects, text, report):
if name not in report["messages"]: if name not in report["messages"]:
report["messages"][name] = {"covered" : False} report["messages"][name] = {"covered" : False}
report["total"] += 1 report["total"] += 1
if report["messages"][name]["covered"] != True: if report["messages"][name]["covered"] != True and search(desc, text):
if desc == None or desc == '' or search(desc, text):
report["messages"][name]["covered"] = True report["messages"][name]["covered"] = True
report["covered"] += 1 report["covered"] += 1
@ -87,15 +91,14 @@ def loc_coverage(locations, text, report):
# locations have a long and a short description, that each have to # locations have a long and a short description, that each have to
# be checked seperately # be checked seperately
for name, loc in locations: for name, loc in locations:
desc = loc["description"]
if name not in report["messages"]: if name not in report["messages"]:
report["messages"][name] = {"long" : False, "short": False} report["messages"][name] = {"long" : False, "short": False}
report["total"] += 2 report["total"] += 2
if report["messages"][name]["long"] != True: if report["messages"][name]["long"] != True and search(desc["long"], text):
if loc["description"]["long"] == None or loc["description"]["long"] == '' or search(loc["description"]["long"], text):
report["messages"][name]["long"] = True report["messages"][name]["long"] = True
report["covered"] += 1 report["covered"] += 1
if report["messages"][name]["short"] != True: if report["messages"][name]["short"] != True and search(desc["short"], text):
if loc["description"]["short"] == None or loc["description"]["short"] == '' or search(loc["description"]["short"], text):
report["messages"][name]["short"] = True report["messages"][name]["short"] = True
report["covered"] += 1 report["covered"] += 1
@ -136,8 +139,7 @@ def threshold_coverage(classes, text, report):
if name not in report["messages"]: if name not in report["messages"]:
report["messages"][name] = {"covered" : "False"} report["messages"][name] = {"covered" : "False"}
report["total"] += 1 report["total"] += 1
if report["messages"][name]["covered"] != True: if report["messages"][name]["covered"] != True and search(item["message"], text):
if item["message"] == None or item["message"] == "NO_MESSAGE" or search(item["message"], text):
report["messages"][name]["covered"] = True report["messages"][name]["covered"] = True
report["covered"] += 1 report["covered"] += 1
@ -146,8 +148,7 @@ def arb_coverage(arb_msgs, text, report):
if name not in report["messages"]: if name not in report["messages"]:
report["messages"][name] = {"covered" : False} report["messages"][name] = {"covered" : False}
report["total"] += 1 report["total"] += 1
if report["messages"][name]["covered"] != True: if report["messages"][name]["covered"] != True and search(message, text):
if message == None or search(message, text):
report["messages"][name]["covered"] = True report["messages"][name]["covered"] = True
report["covered"] += 1 report["covered"] += 1
@ -157,8 +158,7 @@ def specials_actions_coverage(items, text, report):
if name not in report["messages"]: if name not in report["messages"]:
report["messages"][name] = {"covered" : False} report["messages"][name] = {"covered" : False}
report["total"] += 1 report["total"] += 1
if report["messages"][name]["covered"] != True: if report["messages"][name]["covered"] != True and search(item["message"], text):
if item["message"] == None or item["message"] == "NO_MESSAGE" or search(item["message"], text):
report["messages"][name]["covered"] = True report["messages"][name]["covered"] = True
report["covered"] += 1 report["covered"] += 1