9 yaml_name = "../adventure.yaml"
10 html_template_path = "coverage_dungeon.html.tpl"
11 html_output_path = "../coverage/adventure.yaml.html"
15 <td class="coverFile">{}</td>
16 <td class="{}"> </td>
17 <td class="{}"> </td>
23 <td class="coverFile">{}</td>
24 <td class="{}"> </td>
30 <td class="coverFile">{}</td>
31 <td class="{}"> </td>
35 def loc_coverage(locations, text):
36 for locname, loc in locations:
37 if loc["description"]["long"] == None or loc["description"]["long"] == '':
38 loc["description"]["long"] = True
39 if loc["description"]["long"] != True:
40 if text.find(loc["description"]["long"]) != -1:
41 loc["description"]["long"] = True
42 if loc["description"]["short"] == None or loc["description"]["short"] == '':
43 loc["description"]["short"] = True
44 if loc["description"]["short"] != True:
45 if text.find(loc["description"]["short"]) != -1:
46 loc["description"]["short"] = True
48 def arb_coverage(arb_msgs, text):
49 for i, msg in enumerate(arb_msgs):
50 (msg_name, msg_text) = msg
51 if msg_text == None or msg_text == '':
52 arb_msgs[i] = (msg_name, True)
53 elif msg_text != True:
54 if text.find(msg_text) != -1:
55 arb_msgs[i] = (msg_name, True)
57 def obj_coverage(objects, text):
58 for i, objouter in enumerate(objects):
59 (obj_name, obj) = objouter
60 if obj["descriptions"]:
61 for j, desc in enumerate(obj["descriptions"]):
62 if desc == None or desc == '':
63 obj["descriptions"][j] = True
64 objects[i] = (obj_name, obj)
66 if text.find(desc) != -1:
67 obj["descriptions"][j] = True
68 objects[i] = (obj_name, obj)
70 if __name__ == "__main__":
71 with open(yaml_name, "r") as f:
74 with open(html_template_path, "r") as f:
75 html_template = f.read()
77 locations = db["locations"]
78 arb_msgs = db["arbitrary_messages"]
79 objects = db["objects"]
82 for filename in os.listdir(test_dir):
83 if filename.endswith(".chk"):
84 with open(filename, "r") as chk:
86 loc_coverage(locations, text)
87 arb_coverage(arb_msgs, text)
88 obj_coverage(objects, text)
90 print("\nadventure.yaml coverage rate:")
93 location_total = len(locations) * 2
95 for locouter in locations:
98 long_success = "covered"
99 short_success = "covered"
100 if loc["description"]["long"] != True:
101 long_success = "uncovered"
103 location_covered += 1
105 if loc["description"]["short"] != True:
106 short_success = "uncovered"
108 location_covered += 1
110 location_html += location_row.format(locname, long_success, short_success)
111 location_percent = round((location_covered / location_total) * 100, 1)
112 print(" locations..........: {}% covered ({} of {})".format(location_percent, location_covered, location_total))
115 arb_total = len(arb_msgs)
117 for name, msg in arb_msgs:
120 success = "uncovered"
123 arb_msg_html += arb_msg_row.format(name, success)
124 arb_percent = round((arb_covered / arb_total) * 100, 1)
125 print(" arbitrary_messages.: {}% covered ({} of {})".format(arb_percent, arb_covered, arb_total))
130 for (obj_name, obj) in objects:
131 if obj["descriptions"]:
132 for j, desc in enumerate(obj["descriptions"]):
136 success = "uncovered"
139 object_html += object_row.format("%s[%d]" % (obj_name, j), success)
140 objects_percent = round((objects_covered / objects_total) * 100, 1)
141 print(" objects............: {}% covered ({} of {})".format(objects_percent, objects_covered, objects_total))
143 with open(html_output_path, "w") as f:
144 f.write(html_template.format(
145 location_total, location_covered, location_percent,
146 arb_total, arb_covered, arb_percent,
147 objects_total, objects_covered, objects_percent,
148 location_html, arb_msg_html, object_html