Now YAML coverage test generates a nice HTML template

This commit is contained in:
Aaron Traas 2017-07-07 22:37:12 -04:00
parent 6af7db8cd9
commit 4446c61d5f
4 changed files with 192 additions and 9 deletions

View file

@ -12,7 +12,7 @@ binary:debug:
- apk update
- apk add make gcc musl-dev python3 libedit-dev
- pip3 install PyYAML
script:
script:
- make debug
artifacts:
paths:
@ -31,7 +31,7 @@ binary:release:
- apk update
- apk add make gcc musl-dev python3 libedit-dev
- pip3 install PyYAML
script:
script:
- make advent cheat
artifacts:
paths:
@ -81,7 +81,8 @@ test:debug:
stage: test
before_script:
- apk update
- apk add make gcc libedit-dev
- apk add make gcc python3 libedit-dev
- pip3 install PyYAML
- apk add lcov --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted
script:
- cd tests
@ -118,4 +119,3 @@ pages:
- master
dependencies:
- test:debug

View file

@ -1,6 +1,6 @@
# Test-suite makefile for reposurgeon
# Use absolute path so tests that change working directory still use
# Use absolute path so tests that change working directory still use
# scripts from parent directory. Note that using $PWD seems to fail
# here under Gitlab's CI environment.
PATH := $(realpath ..):$(realpath .):${PATH}
@ -26,6 +26,7 @@ check: savecheck regress
coverage: check
lcov -t "advent" -o ../advent.info -c -d .. --gcov-tool=$(GCOV)
genhtml -o ../coverage/ ../advent.info
python3 coverage_dungeon.py
.SUFFIXES: .chk

View file

@ -0,0 +1,112 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>LCOV - advent.info</title>
<link rel="stylesheet" type="text/css" href="gcov.css">
<style>
.covered {{
text-align: center;
background-color: #A7FC9D;
}}
.covered::before {{
content: '\002714';
}}
.uncovered {{
text-align: center;
background-color: #FF0000;
}}
.uncovered::before {{
content: '\002715';
}}
</style>
</head>
<body>
<table width="100%" border=0 cellspacing=0 cellpadding=0>
<tr><td class="title">adventure.yaml Coverage report</td></tr>
<tr><td class="ruler"><img src="glass.png" width=3 height=3 alt=""></td></tr>
<tr>
<td width="100%">
<table cellpadding=1 border=0 width="100%">
<tr>
<td width="10%"></td>
<td width="35%"></td>
<td width="20%"></td>
<td width="5%"></td>
<td width="10%" class="headerCovTableHead">Total</td>
<td width="10%" class="headerCovTableHead">Covered</td>
<td width="10%" class="headerCovTableHead">% Coverage</td>
</tr>
<tr>
<td class="headerItem">Test:</td>
<td class="headerValue">adventure.yaml</td>
<td></td>
<td class="headerItem">Locations:</td>
<td class="headerCovTableEntry">{}</td>
<td class="headerCovTableEntry">{}</td>
<td class="headerCovTableEntry">{}%</td>
</tr>
<tr>
<td class="headerItem">Date:</td>
<td class="headerValue">2017-07-07 21:47:56</td>
<td></td>
<td class="headerItem">Arbitrary Messages:</td>
<td class="headerCovTableEntry">{}</td>
<td class="headerCovTableEntry">{}</td>
<td class="headerCovTableEntry">{}%</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td class="headerItem">Objects:</td>
<td class="headerCovTableEntry">{}</td>
<td class="headerCovTableEntry">{}</td>
<td class="headerCovTableEntry">{}%</td>
</tr>
<tr><td><img src="glass.png" width=3 height=3 alt=""></td></tr>
</table>
</td>
</tr>
<tr><td class="ruler"><img src="glass.png" width=3 height=3 alt=""></td></tr>
</table>
<br>
<center>
<table width="60%" cellpadding=1 cellspacing=1 border=0>
<tr>
<td class="tableHead">Location</td>
<td class="tableHead">long</td>
<td class="tableHead">short</td>
</tr>
{}
</table>
<br>
<table width="60%" cellpadding=1 cellspacing=1 border=0>
<tr>
<td class="tableHead">Arbitrary Message</td>
<td class="tableHead">Covered?</td>
</tr>
{}
</table>
<br>
<table width="60%" cellpadding=1 cellspacing=1 border=0>
<tr>
<td class="tableHead">Objects</td>
<td class="tableHead">Covered?</td>
</tr>
{}
</table>
</center>
<br>
<table width="100%" border=0 cellspacing=0 cellpadding=0>
<tr><td class="ruler"><img src="glass.png" width=3 height=3 alt=""></td></tr>
<tr><td class="versionInfo">Generated by: <a href="https://gitlab.com/esr/open-adventure/blob/master/tests/coverage_dungeon.py">Open Adventure Dungeon Coverage Generator</a></td></tr>
</table>
<br>
</body>
</html>

View file

@ -7,6 +7,30 @@ import pprint
test_dir = "."
yaml_name = "../adventure.yaml"
html_template_path = "coverage_dungeon.html.tpl"
html_output_path = "../coverage/adventure.yaml.html"
location_row = """
<tr>
<td class="coverFile">{}</td>
<td class="{}">&nbsp;</td>
<td class="{}">&nbsp;</td>
</tr>
"""
arb_msg_row = """
<tr>
<td class="coverFile">{}</td>
<td class="{}">&nbsp;</td>
</tr>
"""
object_row = """
<tr>
<td class="coverFile">{}</td>
<td class="{}">&nbsp;</td>
</tr>
"""
def loc_coverage(locations, text):
for locname, loc in locations:
@ -47,6 +71,9 @@ if __name__ == "__main__":
with open(yaml_name, "r") as f:
db = yaml.load(f)
with open(html_template_path, "r") as f:
html_template = f.read()
locations = db["locations"]
arb_msgs = db["arbitrary_messages"]
objects = db["objects"]
@ -60,20 +87,63 @@ if __name__ == "__main__":
arb_coverage(arb_msgs, text)
obj_coverage(objects, text)
print("\nadventure.yaml coverage rate:")
location_html = ""
location_total = len(locations) * 2
location_covered = 0
for locouter in locations:
locname = locouter[0]
loc = locouter[1]
long_success = "covered"
short_success = "covered"
if loc["description"]["long"] != True:
print("%s long description not covered!" % locname)
long_success = "uncovered"
else:
location_covered += 1
if loc["description"]["short"] != True:
print("location: %s short description not covered!" % locname)
short_success = "uncovered"
else:
location_covered += 1
location_html += location_row.format(locname, long_success, short_success)
location_percent = round((location_covered / location_total) * 100, 1)
print(" locations..........: {}% covered ({} of {})".format(location_percent, location_covered, location_total))
arb_msg_html = ""
arb_total = len(arb_msgs)
arb_covered = 0
for name, msg in arb_msgs:
success = "covered"
if msg != True:
print("arbitrary message: %s not covered!" % name)
success = "uncovered"
else:
arb_covered += 1
arb_msg_html += arb_msg_row.format(name, success)
arb_percent = round((arb_covered / arb_total) * 100, 1)
print(" arbitrary_messages.: {}% covered ({} of {})".format(arb_percent, arb_covered, arb_total))
object_html = ""
objects_total = 0
objects_covered = 0
for (obj_name, obj) in objects:
if obj["descriptions"]:
for j, desc in enumerate(obj["descriptions"]):
objects_total += 1
success = "covered"
if desc != True:
print("object: %s desctiption #%d not covered!" % (obj_name, j))
success = "uncovered"
else:
objects_covered += 1
object_html += object_row.format("%s[%d]" % (obj_name, j), success)
objects_percent = round((objects_covered / objects_total) * 100, 1)
print(" objects............: {}% covered ({} of {})".format(objects_percent, objects_covered, objects_total))
with open(html_output_path, "w") as f:
f.write(html_template.format(
location_total, location_covered, location_percent,
arb_total, arb_covered, arb_percent,
objects_total, objects_covered, objects_percent,
location_html, arb_msg_html, object_html
))