Python scripts: PEP8 fixes

This commit is contained in:
XhmikosR 2013-03-02 17:45:26 +02:00 committed by Daniel Marjamäki
parent d8fc126cf0
commit ae73466f97
5 changed files with 49 additions and 41 deletions

View File

@ -148,6 +148,7 @@ HTML_FOOTER = """
HTML_ERROR = "<span style=\"border-width: 2px;border-color: black;border-style: solid;background: #ffaaaa;padding: 3px;\">&lt;--- %s</span>\n"
class AnnotateCodeFormatter(HtmlFormatter):
errors = []
@ -162,6 +163,7 @@ class AnnotateCodeFormatter(HtmlFormatter):
line_no = line_no + 1
yield i, t
class CppCheckHandler(XmlContentHandler):
"""Parses the cppcheck xml file and produces a list of all its errors."""
errors = []

View File

@ -25,6 +25,7 @@ import os
import sys
import re
class Extract:
"""
Read Cppcheck test file and create data
@ -50,37 +51,37 @@ class Extract:
for line in fin:
# testclass starts
res = re.match('class ('+name+')', line)
if res != None:
if res is not None:
testclass = res.group(1)
# end of testclass
if re.match('};', line) != None:
if re.match('};', line) is not None:
testclass = None
# function start
res = re.match('\\s+void ('+name+')\\(\\)', line)
if res != None:
if res is not None:
functionName = res.group(1)
elif re.match('\\s+}', line) != None:
elif re.match('\\s+}', line) is not None:
functionName = None
if functionName == None:
if functionName is None:
continue
# check
res = re.match('\s+check.*\('+string, line)
if res != None:
if res is not None:
code = res.group(1)
# code..
res = re.match('\\s+'+string, line)
if res != None:
if res is not None:
code = code + res.group(1)
# assert
res = re.match('\\s+ASSERT_EQUALS\\(\\"([^"]*)\\",', line)
if res != None and len(code) > 10:
if res is not None and len(code) > 10:
node = {'testclass': testclass,
'functionName': functionName,
'code': code,
@ -91,10 +92,12 @@ class Extract:
# close test file
fin.close()
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():
@ -144,8 +147,8 @@ def writeHtmlFile(nodes, functionName, filename, errorsOnly):
fout.write('<td>' + strtoxml(node['expected']).replace('\\n', '<br>') + '</td>')
fout.write('</tr>\n')
if testclass != None:
fout.write('</table>\n');
if testclass is not None:
fout.write('</table>\n')
fout.write('</body></html>\n')
fout.close()
@ -175,7 +178,7 @@ for arg in sys.argv[1:]:
# extract test cases
if filename != None:
if filename is not None:
# parse test file
e = Extract()
e.parseFile(filename)
@ -193,7 +196,7 @@ if filename != None:
s += '/>'
print (s)
print ('</tree>')
elif htmldir != None:
elif htmldir is not None:
if not htmldir.endswith('/'):
htmldir += '/'
if not os.path.exists(htmldir):

View File

@ -22,6 +22,7 @@ import re
import glob
import argparse
class MatchCompiler:
def __init__(self, verify_mode=False):
self._verifyMode = verify_mode
@ -136,7 +137,7 @@ class MatchCompiler:
gotoNextToken = ' tok = tok->next();\n'
# if varid is provided, check that it's non-zero on first use
if varid and tok.find('%varid%') != -1 and checked_varid == False:
if varid and tok.find('%varid%') != -1 and checked_varid is False:
ret += ' if (varid==0U)\n'
ret += ' throw InternalError(tok, "Internal error. Token::Match called with varid 0. Please report this to Cppcheck developers");\n'
checked_varid = True
@ -313,7 +314,7 @@ class MatchCompiler:
# Compile function or use previously compiled one
patternNumber = self._lookupMatchFunctionId(pattern, None, varId, False)
if patternNumber == None:
if patternNumber is None:
patternNumber = len(self._rawMatchFunctions) + 1
self._insertMatchFunctionId(patternNumber, pattern, None, varId, False)
self._rawMatchFunctions.append(self._compilePattern(pattern, patternNumber, varId))
@ -340,7 +341,7 @@ class MatchCompiler:
break
res = self.parseMatch(line, pos1)
if res == None:
if res is None:
break
assert(len(res) == 3 or len(res) == 4) # assert that Token::Match has either 2 or 3 arguments
@ -353,7 +354,7 @@ class MatchCompiler:
varId = res[3]
res = re.match(r'\s*"([^"]*)"\s*$', raw_pattern)
if res == None:
if res is None:
break # Non-const pattern - bailout
pattern = res.group(1)
@ -410,7 +411,7 @@ class MatchCompiler:
# Compile function or use previously compiled one
findMatchNumber = self._lookupMatchFunctionId(pattern, endToken, varId, True)
if findMatchNumber == None:
if findMatchNumber is None:
findMatchNumber = len(self._rawMatchFunctions) + 1
self._insertMatchFunctionId(findMatchNumber, pattern, endToken, varId, True)
self._rawMatchFunctions.append(self._compileFindPattern(pattern, findMatchNumber, endToken, varId))
@ -438,7 +439,7 @@ class MatchCompiler:
break
res = self.parseMatch(line, pos1)
if res == None:
if res is None:
break
assert(len(res) >= 3 or len(res) < 6) # assert that Token::find(simple)match has either 2, 3 or four arguments
@ -462,16 +463,16 @@ class MatchCompiler:
# Token *findmatch(const Token *tok, const char pattern[], unsigned int varId = 0);
# Token *findmatch(const Token *tok, const char pattern[], const Token *end, unsigned int varId = 0);
endToken = None
if is_findsimplematch == True and len(res) == 4:
if is_findsimplematch is True and len(res) == 4:
endToken = res[3]
elif is_findsimplematch == False:
elif is_findsimplematch is False:
if varId and len(res) == 5:
endToken = res[3]
elif varId == None and len(res) == 4:
elif varId is None and len(res) == 4:
endToken = res[3]
res = re.match(r'\s*"([^"]*)"\s*$', pattern)
if res == None:
if res is None:
break # Non-const pattern - bailout
pattern = res.group(1)
@ -488,7 +489,7 @@ class MatchCompiler:
break
res = self._parseStringComparison(line, match.start())
if res == None:
if res is None:
break
startPos = res[0]
@ -538,6 +539,7 @@ class MatchCompiler:
fout.write(header+stringList+strFunctions+code)
fout.close()
def main():
# Main program
build_dir = 'build'

View File

@ -19,6 +19,7 @@
import unittest
import matchcompiler
class MatchCompilerTest(unittest.TestCase):
def setUp(self):
self.mc = matchcompiler.MatchCompiler(verify_mode=False)