extracttests.py: added docstrings. added navigation links.

This commit is contained in:
Daniel Marjamäki 2011-11-27 11:35:01 +01:00
parent db186b2c25
commit 0c54f88dd0
1 changed files with 17 additions and 0 deletions

View File

@ -1,12 +1,19 @@
#!/usr/bin/python
"""Extract test cases information from Cppcheck test file"""
import sys
import re
class Extract:
"""Read Cppcheck test file and create data representation"""
# array that stores all the test cases
nodes = []
def parseFile(self,filename):
"""parse test file and add info to the nodes variable"""
name = '[0-9a-zA-Z_]+'
str = '\\"(.+)\\"'
@ -53,9 +60,11 @@ class Extract:
code = ''
def strtoxml(s):
"""Convert string to xml/html format"""
return s.replace('&','&amp;').replace('"', '&quot;').replace('<','&lt;').replace('>','&gt;')
def trimname(name):
"""Trim test name. Trailing underscore and digits are removed"""
while name[-1].isdigit():
name = name[:-1]
if name[-1] == '_':
@ -64,6 +73,7 @@ def trimname(name):
def writeHtmlFile(nodes, functionName, filename, errorsOnly):
"""Write html file for a function name"""
fout = open(filename, 'w')
fout.write('<html>\n')
fout.write('<head>\n')
@ -76,6 +86,13 @@ def writeHtmlFile(nodes, functionName, filename, errorsOnly):
fout.write('</head>\n')
fout.write('<body>\n')
fout.write('<a href="index.htm">Home</a> -- ')
if errorsOnly:
fout.write('<a href="all-'+functionName+'.htm">All test cases</a>')
else:
fout.write('<a href="errors-'+functionName+'.htm">Error test cases</a>')
fout.write('<br><br>')
testclass = None
num = 0
for node in nodes: