Python scripts: PEP8 fixes
This commit is contained in:
parent
d8fc126cf0
commit
ae73466f97
|
@ -148,6 +148,7 @@ HTML_FOOTER = """
|
||||||
|
|
||||||
HTML_ERROR = "<span style=\"border-width: 2px;border-color: black;border-style: solid;background: #ffaaaa;padding: 3px;\"><--- %s</span>\n"
|
HTML_ERROR = "<span style=\"border-width: 2px;border-color: black;border-style: solid;background: #ffaaaa;padding: 3px;\"><--- %s</span>\n"
|
||||||
|
|
||||||
|
|
||||||
class AnnotateCodeFormatter(HtmlFormatter):
|
class AnnotateCodeFormatter(HtmlFormatter):
|
||||||
errors = []
|
errors = []
|
||||||
|
|
||||||
|
@ -162,6 +163,7 @@ class AnnotateCodeFormatter(HtmlFormatter):
|
||||||
line_no = line_no + 1
|
line_no = line_no + 1
|
||||||
yield i, t
|
yield i, t
|
||||||
|
|
||||||
|
|
||||||
class CppCheckHandler(XmlContentHandler):
|
class CppCheckHandler(XmlContentHandler):
|
||||||
"""Parses the cppcheck xml file and produces a list of all its errors."""
|
"""Parses the cppcheck xml file and produces a list of all its errors."""
|
||||||
errors = []
|
errors = []
|
||||||
|
|
|
@ -25,6 +25,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
class Extract:
|
class Extract:
|
||||||
"""
|
"""
|
||||||
Read Cppcheck test file and create data
|
Read Cppcheck test file and create data
|
||||||
|
@ -50,37 +51,37 @@ class Extract:
|
||||||
for line in fin:
|
for line in fin:
|
||||||
# testclass starts
|
# testclass starts
|
||||||
res = re.match('class ('+name+')', line)
|
res = re.match('class ('+name+')', line)
|
||||||
if res != None:
|
if res is not None:
|
||||||
testclass = res.group(1)
|
testclass = res.group(1)
|
||||||
|
|
||||||
# end of testclass
|
# end of testclass
|
||||||
if re.match('};', line) != None:
|
if re.match('};', line) is not None:
|
||||||
testclass = None
|
testclass = None
|
||||||
|
|
||||||
# function start
|
# function start
|
||||||
res = re.match('\\s+void ('+name+')\\(\\)', line)
|
res = re.match('\\s+void ('+name+')\\(\\)', line)
|
||||||
if res != None:
|
if res is not None:
|
||||||
functionName = res.group(1)
|
functionName = res.group(1)
|
||||||
|
|
||||||
elif re.match('\\s+}', line) != None:
|
elif re.match('\\s+}', line) is not None:
|
||||||
functionName = None
|
functionName = None
|
||||||
|
|
||||||
if functionName == None:
|
if functionName is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# check
|
# check
|
||||||
res = re.match('\s+check.*\('+string, line)
|
res = re.match('\s+check.*\('+string, line)
|
||||||
if res != None:
|
if res is not None:
|
||||||
code = res.group(1)
|
code = res.group(1)
|
||||||
|
|
||||||
# code..
|
# code..
|
||||||
res = re.match('\\s+'+string, line)
|
res = re.match('\\s+'+string, line)
|
||||||
if res != None:
|
if res is not None:
|
||||||
code = code + res.group(1)
|
code = code + res.group(1)
|
||||||
|
|
||||||
# assert
|
# assert
|
||||||
res = re.match('\\s+ASSERT_EQUALS\\(\\"([^"]*)\\",', line)
|
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,
|
node = {'testclass': testclass,
|
||||||
'functionName': functionName,
|
'functionName': functionName,
|
||||||
'code': code,
|
'code': code,
|
||||||
|
@ -91,10 +92,12 @@ class Extract:
|
||||||
# close test file
|
# close test file
|
||||||
fin.close()
|
fin.close()
|
||||||
|
|
||||||
|
|
||||||
def strtoxml(s):
|
def strtoxml(s):
|
||||||
"""Convert string to xml/html format"""
|
"""Convert string to xml/html format"""
|
||||||
return s.replace('&', '&').replace('"', '"').replace('<', '<').replace('>', '>')
|
return s.replace('&', '&').replace('"', '"').replace('<', '<').replace('>', '>')
|
||||||
|
|
||||||
|
|
||||||
def trimname(name):
|
def trimname(name):
|
||||||
"""Trim test name. Trailing underscore and digits are removed"""
|
"""Trim test name. Trailing underscore and digits are removed"""
|
||||||
while name[-1].isdigit():
|
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('<td>' + strtoxml(node['expected']).replace('\\n', '<br>') + '</td>')
|
||||||
fout.write('</tr>\n')
|
fout.write('</tr>\n')
|
||||||
|
|
||||||
if testclass != None:
|
if testclass is not None:
|
||||||
fout.write('</table>\n');
|
fout.write('</table>\n')
|
||||||
fout.write('</body></html>\n')
|
fout.write('</body></html>\n')
|
||||||
fout.close()
|
fout.close()
|
||||||
|
|
||||||
|
@ -175,7 +178,7 @@ for arg in sys.argv[1:]:
|
||||||
|
|
||||||
|
|
||||||
# extract test cases
|
# extract test cases
|
||||||
if filename != None:
|
if filename is not None:
|
||||||
# parse test file
|
# parse test file
|
||||||
e = Extract()
|
e = Extract()
|
||||||
e.parseFile(filename)
|
e.parseFile(filename)
|
||||||
|
@ -193,7 +196,7 @@ if filename != None:
|
||||||
s += '/>'
|
s += '/>'
|
||||||
print (s)
|
print (s)
|
||||||
print ('</tree>')
|
print ('</tree>')
|
||||||
elif htmldir != None:
|
elif htmldir is not None:
|
||||||
if not htmldir.endswith('/'):
|
if not htmldir.endswith('/'):
|
||||||
htmldir += '/'
|
htmldir += '/'
|
||||||
if not os.path.exists(htmldir):
|
if not os.path.exists(htmldir):
|
||||||
|
|
|
@ -22,6 +22,7 @@ import re
|
||||||
import glob
|
import glob
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
class MatchCompiler:
|
class MatchCompiler:
|
||||||
def __init__(self, verify_mode=False):
|
def __init__(self, verify_mode=False):
|
||||||
self._verifyMode = verify_mode
|
self._verifyMode = verify_mode
|
||||||
|
@ -136,7 +137,7 @@ class MatchCompiler:
|
||||||
gotoNextToken = ' tok = tok->next();\n'
|
gotoNextToken = ' tok = tok->next();\n'
|
||||||
|
|
||||||
# if varid is provided, check that it's non-zero on first use
|
# 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 += ' if (varid==0U)\n'
|
||||||
ret += ' throw InternalError(tok, "Internal error. Token::Match called with varid 0. Please report this to Cppcheck developers");\n'
|
ret += ' throw InternalError(tok, "Internal error. Token::Match called with varid 0. Please report this to Cppcheck developers");\n'
|
||||||
checked_varid = True
|
checked_varid = True
|
||||||
|
@ -313,7 +314,7 @@ class MatchCompiler:
|
||||||
# Compile function or use previously compiled one
|
# Compile function or use previously compiled one
|
||||||
patternNumber = self._lookupMatchFunctionId(pattern, None, varId, False)
|
patternNumber = self._lookupMatchFunctionId(pattern, None, varId, False)
|
||||||
|
|
||||||
if patternNumber == None:
|
if patternNumber is None:
|
||||||
patternNumber = len(self._rawMatchFunctions) + 1
|
patternNumber = len(self._rawMatchFunctions) + 1
|
||||||
self._insertMatchFunctionId(patternNumber, pattern, None, varId, False)
|
self._insertMatchFunctionId(patternNumber, pattern, None, varId, False)
|
||||||
self._rawMatchFunctions.append(self._compilePattern(pattern, patternNumber, varId))
|
self._rawMatchFunctions.append(self._compilePattern(pattern, patternNumber, varId))
|
||||||
|
@ -340,7 +341,7 @@ class MatchCompiler:
|
||||||
break
|
break
|
||||||
|
|
||||||
res = self.parseMatch(line, pos1)
|
res = self.parseMatch(line, pos1)
|
||||||
if res == None:
|
if res is None:
|
||||||
break
|
break
|
||||||
|
|
||||||
assert(len(res) == 3 or len(res) == 4) # assert that Token::Match has either 2 or 3 arguments
|
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]
|
varId = res[3]
|
||||||
|
|
||||||
res = re.match(r'\s*"([^"]*)"\s*$', raw_pattern)
|
res = re.match(r'\s*"([^"]*)"\s*$', raw_pattern)
|
||||||
if res == None:
|
if res is None:
|
||||||
break # Non-const pattern - bailout
|
break # Non-const pattern - bailout
|
||||||
|
|
||||||
pattern = res.group(1)
|
pattern = res.group(1)
|
||||||
|
@ -410,7 +411,7 @@ class MatchCompiler:
|
||||||
# Compile function or use previously compiled one
|
# Compile function or use previously compiled one
|
||||||
findMatchNumber = self._lookupMatchFunctionId(pattern, endToken, varId, True)
|
findMatchNumber = self._lookupMatchFunctionId(pattern, endToken, varId, True)
|
||||||
|
|
||||||
if findMatchNumber == None:
|
if findMatchNumber is None:
|
||||||
findMatchNumber = len(self._rawMatchFunctions) + 1
|
findMatchNumber = len(self._rawMatchFunctions) + 1
|
||||||
self._insertMatchFunctionId(findMatchNumber, pattern, endToken, varId, True)
|
self._insertMatchFunctionId(findMatchNumber, pattern, endToken, varId, True)
|
||||||
self._rawMatchFunctions.append(self._compileFindPattern(pattern, findMatchNumber, endToken, varId))
|
self._rawMatchFunctions.append(self._compileFindPattern(pattern, findMatchNumber, endToken, varId))
|
||||||
|
@ -438,7 +439,7 @@ class MatchCompiler:
|
||||||
break
|
break
|
||||||
|
|
||||||
res = self.parseMatch(line, pos1)
|
res = self.parseMatch(line, pos1)
|
||||||
if res == None:
|
if res is None:
|
||||||
break
|
break
|
||||||
|
|
||||||
assert(len(res) >= 3 or len(res) < 6) # assert that Token::find(simple)match has either 2, 3 or four arguments
|
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[], unsigned int varId = 0);
|
||||||
# Token *findmatch(const Token *tok, const char pattern[], const Token *end, unsigned int varId = 0);
|
# Token *findmatch(const Token *tok, const char pattern[], const Token *end, unsigned int varId = 0);
|
||||||
endToken = None
|
endToken = None
|
||||||
if is_findsimplematch == True and len(res) == 4:
|
if is_findsimplematch is True and len(res) == 4:
|
||||||
endToken = res[3]
|
endToken = res[3]
|
||||||
elif is_findsimplematch == False:
|
elif is_findsimplematch is False:
|
||||||
if varId and len(res) == 5:
|
if varId and len(res) == 5:
|
||||||
endToken = res[3]
|
endToken = res[3]
|
||||||
elif varId == None and len(res) == 4:
|
elif varId is None and len(res) == 4:
|
||||||
endToken = res[3]
|
endToken = res[3]
|
||||||
|
|
||||||
res = re.match(r'\s*"([^"]*)"\s*$', pattern)
|
res = re.match(r'\s*"([^"]*)"\s*$', pattern)
|
||||||
if res == None:
|
if res is None:
|
||||||
break # Non-const pattern - bailout
|
break # Non-const pattern - bailout
|
||||||
|
|
||||||
pattern = res.group(1)
|
pattern = res.group(1)
|
||||||
|
@ -488,7 +489,7 @@ class MatchCompiler:
|
||||||
break
|
break
|
||||||
|
|
||||||
res = self._parseStringComparison(line, match.start())
|
res = self._parseStringComparison(line, match.start())
|
||||||
if res == None:
|
if res is None:
|
||||||
break
|
break
|
||||||
|
|
||||||
startPos = res[0]
|
startPos = res[0]
|
||||||
|
@ -538,6 +539,7 @@ class MatchCompiler:
|
||||||
fout.write(header+stringList+strFunctions+code)
|
fout.write(header+stringList+strFunctions+code)
|
||||||
fout.close()
|
fout.close()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Main program
|
# Main program
|
||||||
build_dir = 'build'
|
build_dir = 'build'
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
import matchcompiler
|
import matchcompiler
|
||||||
|
|
||||||
|
|
||||||
class MatchCompilerTest(unittest.TestCase):
|
class MatchCompilerTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.mc = matchcompiler.MatchCompiler(verify_mode=False)
|
self.mc = matchcompiler.MatchCompiler(verify_mode=False)
|
||||||
|
|
Loading…
Reference in New Issue