autopep8 formatting
This commit is contained in:
parent
f8710cb984
commit
88447385c2
|
@ -130,7 +130,9 @@ _UNRECOGNIZED_ARGS_ATTR = '_unrecognized_args'
|
|||
# Utility functions and classes
|
||||
# =============================
|
||||
|
||||
|
||||
class _AttributeHolder(object):
|
||||
|
||||
"""Abstract base class that provides __repr__.
|
||||
|
||||
The __repr__ method returns a string in the format::
|
||||
|
@ -166,6 +168,7 @@ def _ensure_value(namespace, name, value):
|
|||
# ===============
|
||||
|
||||
class HelpFormatter(object):
|
||||
|
||||
"""Formatter for generating usage messages and argument help strings.
|
||||
|
||||
Only the name of this class is considered a public API. All the methods
|
||||
|
@ -646,6 +649,7 @@ class HelpFormatter(object):
|
|||
|
||||
|
||||
class RawDescriptionHelpFormatter(HelpFormatter):
|
||||
|
||||
"""Help message formatter which retains any formatting in descriptions.
|
||||
|
||||
Only the name of this class is considered a public API. All the methods
|
||||
|
@ -657,6 +661,7 @@ class RawDescriptionHelpFormatter(HelpFormatter):
|
|||
|
||||
|
||||
class RawTextHelpFormatter(RawDescriptionHelpFormatter):
|
||||
|
||||
"""Help message formatter which retains formatting of all help text.
|
||||
|
||||
Only the name of this class is considered a public API. All the methods
|
||||
|
@ -668,6 +673,7 @@ class RawTextHelpFormatter(RawDescriptionHelpFormatter):
|
|||
|
||||
|
||||
class ArgumentDefaultsHelpFormatter(HelpFormatter):
|
||||
|
||||
"""Help message formatter which adds default values to argument help.
|
||||
|
||||
Only the name of this class is considered a public API. All the methods
|
||||
|
@ -702,6 +708,7 @@ def _get_action_name(argument):
|
|||
|
||||
|
||||
class ArgumentError(Exception):
|
||||
|
||||
"""An error from creating or using an argument (optional or positional).
|
||||
|
||||
The string value of this exception is the message, augmented with
|
||||
|
@ -722,6 +729,7 @@ class ArgumentError(Exception):
|
|||
|
||||
|
||||
class ArgumentTypeError(Exception):
|
||||
|
||||
"""An error from trying to convert a command line string to a type."""
|
||||
pass
|
||||
|
||||
|
@ -731,6 +739,7 @@ class ArgumentTypeError(Exception):
|
|||
# ==============
|
||||
|
||||
class Action(_AttributeHolder):
|
||||
|
||||
"""Information about how to convert command line strings to Python objects.
|
||||
|
||||
Action objects are used by an ArgumentParser to represent the information
|
||||
|
@ -1108,7 +1117,8 @@ class _SubParsersAction(Action):
|
|||
# parse all the remaining options into the namespace
|
||||
# store any unrecognized options on the object, so that the top
|
||||
# level parser can decide what to do with them
|
||||
namespace, arg_strings = parser.parse_known_args(arg_strings, namespace)
|
||||
namespace, arg_strings = parser.parse_known_args(
|
||||
arg_strings, namespace)
|
||||
if arg_strings:
|
||||
vars(namespace).setdefault(_UNRECOGNIZED_ARGS_ATTR, [])
|
||||
getattr(namespace, _UNRECOGNIZED_ARGS_ATTR).extend(arg_strings)
|
||||
|
@ -1119,6 +1129,7 @@ class _SubParsersAction(Action):
|
|||
# ==============
|
||||
|
||||
class FileType(object):
|
||||
|
||||
"""Factory for creating file object types
|
||||
|
||||
Instances of FileType are typically passed as type= arguments to the
|
||||
|
@ -1161,7 +1172,9 @@ class FileType(object):
|
|||
# Optional and Positional Parsing
|
||||
# ===========================
|
||||
|
||||
|
||||
class Namespace(_AttributeHolder):
|
||||
|
||||
"""Simple object for storing attributes.
|
||||
|
||||
Implements equality by attribute names and values, and provides a simple
|
||||
|
@ -1263,7 +1276,6 @@ class _ActionsContainer(object):
|
|||
return action.default
|
||||
return self._defaults.get(dest, None)
|
||||
|
||||
|
||||
# =======================
|
||||
# Adding argument actions
|
||||
# =======================
|
||||
|
@ -1535,6 +1547,7 @@ class _MutuallyExclusiveGroup(_ArgumentGroup):
|
|||
|
||||
|
||||
class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||
|
||||
"""Object for parsing command line strings into Python objects.
|
||||
|
||||
Keyword Arguments:
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def readdate(data):
|
||||
datepos = -1
|
||||
if data[:5] == 'DATE ':
|
||||
|
@ -62,7 +63,8 @@ for lib in range(2):
|
|||
if datestr == lastupdate:
|
||||
recent.append(a)
|
||||
|
||||
mainpage.write('<a href="daca2-'+a+'.html">'+a+'</a><br>\n')
|
||||
mainpage.write(
|
||||
'<a href="daca2-' + a + '.html">' + a + '</a><br>\n')
|
||||
|
||||
data = data.replace('&', ' ')
|
||||
data = data.replace('<', '<')
|
||||
|
|
|
@ -21,6 +21,7 @@ FTPSERVER = 'ftp.sunet.se'
|
|||
FTPPATH = '/pub/Linux/distributions/Debian/debian/pool/main/'
|
||||
FOLDER = 'b'
|
||||
|
||||
|
||||
def handleRemoveReadonly(func, path, exc):
|
||||
import stat
|
||||
if not os.access(path, os.W_OK):
|
||||
|
@ -30,6 +31,7 @@ def handleRemoveReadonly(func, path, exc):
|
|||
else:
|
||||
raise
|
||||
|
||||
|
||||
def removeAllExceptResults():
|
||||
count = 5
|
||||
while count > 0:
|
||||
|
@ -63,6 +65,7 @@ def removeAllExceptResults():
|
|||
continue
|
||||
count = 0
|
||||
|
||||
|
||||
def removeLargeFiles(path):
|
||||
for g in glob.glob(path + '*'):
|
||||
if g == '.' or g == '..':
|
||||
|
@ -74,6 +77,7 @@ def removeLargeFiles(path):
|
|||
if statinfo.st_size > 100000:
|
||||
os.remove(g)
|
||||
|
||||
|
||||
def scanarchive(fullpath):
|
||||
results = open('results.txt', 'at')
|
||||
results.write(fullpath + '\n')
|
||||
|
|
|
@ -27,6 +27,7 @@ import re
|
|||
|
||||
|
||||
class Extract:
|
||||
|
||||
"""
|
||||
Read Cppcheck test file and create data
|
||||
representation
|
||||
|
@ -114,7 +115,8 @@ def writeHtmlFile(nodes, functionName, filename, errorsOnly):
|
|||
fout.write('<head>\n')
|
||||
fout.write(' <style type="text/css">\n')
|
||||
fout.write(' body { font-size: 0.8em }\n')
|
||||
fout.write(' th { background-color: #A3C159; text-transform: uppercase }\n')
|
||||
fout.write(
|
||||
' th { background-color: #A3C159; text-transform: uppercase }\n')
|
||||
fout.write(' td { background-color: white; vertical-align: text-top }\n')
|
||||
fout.write(' pre { background-color: #EEEEEE }\n')
|
||||
fout.write(' </style>\n')
|
||||
|
@ -125,7 +127,8 @@ def writeHtmlFile(nodes, functionName, filename, errorsOnly):
|
|||
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(
|
||||
'<a href="errors-' + functionName + '.htm">Error test cases</a>')
|
||||
fout.write('<br><br>')
|
||||
|
||||
testclass = None
|
||||
|
@ -138,13 +141,17 @@ def writeHtmlFile(nodes, functionName, filename, errorsOnly):
|
|||
|
||||
if not testclass:
|
||||
testclass = node['testclass']
|
||||
fout.write('<h1>' + node['testclass'] + '::' + functionName + '</h1>')
|
||||
fout.write(
|
||||
'<h1>' + node['testclass'] + '::' + functionName + '</h1>')
|
||||
fout.write('<table border="0" cellspacing="0">\n')
|
||||
fout.write(' <tr><th>Nr</th><th>Code</th><th>Expected</th></tr>\n')
|
||||
fout.write(
|
||||
' <tr><th>Nr</th><th>Code</th><th>Expected</th></tr>\n')
|
||||
|
||||
fout.write(' <tr><td>' + str(num) + '</td>')
|
||||
fout.write('<td><pre>' + strtoxml(node['code']).replace('\\n', '\n') + '</pre></td>')
|
||||
fout.write('<td>' + strtoxml(node['expected']).replace('\\n', '<br>') + '</td>')
|
||||
fout.write('<td><pre>' + strtoxml(
|
||||
node['code']).replace('\\n', '\n') + '</pre></td>')
|
||||
fout.write(
|
||||
'<td>' + strtoxml(node['expected']).replace('\\n', '<br>') + '</td>')
|
||||
fout.write('</tr>\n')
|
||||
|
||||
if testclass is not None:
|
||||
|
@ -155,7 +162,8 @@ def writeHtmlFile(nodes, functionName, filename, errorsOnly):
|
|||
|
||||
if len(sys.argv) <= 1 or '--help' in sys.argv:
|
||||
print ('Extract test cases from test file')
|
||||
print ('Syntax: extracttests.py [--html=folder] [--xml] [--code=folder] path/testfile.cpp')
|
||||
print (
|
||||
'Syntax: extracttests.py [--html=folder] [--xml] [--code=folder] path/testfile.cpp')
|
||||
sys.exit(0)
|
||||
|
||||
# parse command line
|
||||
|
@ -206,8 +214,10 @@ if filename is not None:
|
|||
findex.write('<head>\n')
|
||||
findex.write(' <style type="text/css">\n')
|
||||
findex.write(' table { font-size: 0.8em }\n')
|
||||
findex.write(' th { background-color: #A3C159; text-transform: uppercase }\n')
|
||||
findex.write(' td { background-color: #F0FFE0; vertical-align: text-top }\n')
|
||||
findex.write(
|
||||
' th { background-color: #A3C159; text-transform: uppercase }\n')
|
||||
findex.write(
|
||||
' td { background-color: #F0FFE0; vertical-align: text-top }\n')
|
||||
findex.write(' A:link { text-decoration: none }\n')
|
||||
findex.write(' A:visited { text-decoration: none }\n')
|
||||
findex.write(' A:active { text-decoration: none }\n')
|
||||
|
@ -238,8 +248,10 @@ if filename is not None:
|
|||
if numerr == 0:
|
||||
findex.write('<td><div align="right">0</div></td>')
|
||||
else:
|
||||
findex.write('<td><a href="errors-'+functionname+'.htm"><div align="right">' + str(numerr) + '</div></a></td>')
|
||||
findex.write('<td><a href="all-'+functionname+'.htm"><div align="right">' + str(numall) + '</div></a></td>')
|
||||
findex.write('<td><a href="errors-' + functionname +
|
||||
'.htm"><div align="right">' + str(numerr) + '</div></a></td>')
|
||||
findex.write('<td><a href="all-' + functionname +
|
||||
'.htm"><div align="right">' + str(numall) + '</div></a></td>')
|
||||
findex.write('</tr>\n')
|
||||
|
||||
findex.write('</table>\n')
|
||||
|
@ -291,7 +303,8 @@ if filename is not None:
|
|||
if expected != '':
|
||||
expected = expected.replace('\\n', '\n')
|
||||
expected = expected.replace('\\"', '"')
|
||||
expected = re.sub('\\[test.cp?p?:', '['+filename+':', expected)
|
||||
expected = re.sub(
|
||||
'\\[test.cp?p?:', '[' + filename + ':', expected)
|
||||
errors.write(expected)
|
||||
errors.close()
|
||||
else:
|
||||
|
|
|
@ -21,13 +21,17 @@ import matchcompiler
|
|||
|
||||
|
||||
class MatchCompilerTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.mc = matchcompiler.MatchCompiler(verify_mode=False)
|
||||
|
||||
def test_parseMatch(self):
|
||||
self.assertEqual(self.mc.parseMatch(' Token::Match(tok, ";") ', 2), ['Token::Match(tok, ";")', 'tok', ' ";"'])
|
||||
self.assertEqual(self.mc.parseMatch(' Token::Match(tok,', 2), None) # multiline Token::Match is not supported yet
|
||||
self.assertEqual(self.mc.parseMatch(' Token::Match(Token::findsimplematch(tok,")"), ";")', 2), ['Token::Match(Token::findsimplematch(tok,")"), ";")', 'Token::findsimplematch(tok,")")', ' ";"']) # inner function call
|
||||
self.assertEqual(self.mc.parseMatch(' Token::Match(tok, ";") ', 2), [
|
||||
'Token::Match(tok, ";")', 'tok', ' ";"'])
|
||||
self.assertEqual(self.mc.parseMatch(' Token::Match(tok,', 2), None)
|
||||
# multiline Token::Match is not supported yet
|
||||
self.assertEqual(self.mc.parseMatch(' Token::Match(Token::findsimplematch(tok,")"), ";")', 2), [
|
||||
'Token::Match(Token::findsimplematch(tok,")"), ";")', 'Token::findsimplematch(tok,")")', ' ";"']) # inner function call
|
||||
|
||||
def test_replaceTokenMatch(self):
|
||||
input = 'if (Token::Match(tok, "foobar")) {'
|
||||
|
@ -44,7 +48,8 @@ class MatchCompilerTest(unittest.TestCase):
|
|||
input = 'if (Token::Match(tok, "foo\"special\"bar %num%")) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
# FIXME: Currently detected as non-static pattern
|
||||
self.assertEqual(output, 'if (Token::Match(tok, "foo"special"bar %num%")) {')
|
||||
self.assertEqual(
|
||||
output, 'if (Token::Match(tok, "foo"special"bar %num%")) {')
|
||||
# self.assertEqual(3, len(self.mc._matchStrs))
|
||||
|
||||
def test_replaceTokenMatchWithVarId(self):
|
||||
|
@ -55,13 +60,15 @@ class MatchCompilerTest(unittest.TestCase):
|
|||
|
||||
input = 'if (Token::Match(tok->next()->next(), "%varid% foobar", tok->varId())) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
self.assertEqual(output, 'if (match2(tok->next()->next(), tok->varId())) {')
|
||||
self.assertEqual(
|
||||
output, 'if (match2(tok->next()->next(), tok->varId())) {')
|
||||
self.assertEqual(1, len(self.mc._matchStrs))
|
||||
|
||||
input = 'if (Token::Match(tok, "foo\"special\"bar %type% %varid%", my_varid_cache)) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
# FIXME: Currently detected as non-static pattern
|
||||
self.assertEqual(output, 'if (Token::Match(tok, "foo"special"bar %type% %varid%", my_varid_cache)) {')
|
||||
self.assertEqual(
|
||||
output, 'if (Token::Match(tok, "foo"special"bar %type% %varid%", my_varid_cache)) {')
|
||||
# self.assertEqual(1, len(self.mc._matchStrs))
|
||||
|
||||
# test caching: reuse existing matchX()
|
||||
|
@ -92,7 +99,8 @@ class MatchCompilerTest(unittest.TestCase):
|
|||
input = 'if (Token::simpleMatch(tok, "foo\"special\"bar")) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
# FIXME: Currently detected as non-static pattern
|
||||
self.assertEqual(output, 'if (Token::simpleMatch(tok, "foo\"special\"bar")) {')
|
||||
self.assertEqual(
|
||||
output, 'if (Token::simpleMatch(tok, "foo\"special\"bar")) {')
|
||||
self.assertEqual(1, len(self.mc._matchStrs))
|
||||
|
||||
def test_replaceTokenFindSimpleMatch(self):
|
||||
|
@ -104,14 +112,16 @@ class MatchCompilerTest(unittest.TestCase):
|
|||
|
||||
input = 'if (Token::findsimplematch(tok->next()->next(), "foobar", tok->link())) {'
|
||||
output = self.mc._replaceTokenFindMatch(input)
|
||||
self.assertEqual(output, 'if (findmatch2(tok->next()->next(), tok->link())) {')
|
||||
self.assertEqual(
|
||||
output, 'if (findmatch2(tok->next()->next(), tok->link())) {')
|
||||
self.assertEqual(1, len(self.mc._matchStrs))
|
||||
self.assertEqual(1, self.mc._matchStrs['foobar'])
|
||||
|
||||
input = 'if (Token::findsimplematch(tok, "foo\"special\"bar")) {'
|
||||
output = self.mc._replaceTokenFindMatch(input)
|
||||
# FIXME: Currently detected as non-static pattern
|
||||
self.assertEqual(output, 'if (Token::findsimplematch(tok, "foo\"special\"bar")) {')
|
||||
self.assertEqual(
|
||||
output, 'if (Token::findsimplematch(tok, "foo\"special\"bar")) {')
|
||||
self.assertEqual(1, len(self.mc._matchStrs))
|
||||
|
||||
def test_replaceTokenFindMatch(self):
|
||||
|
@ -131,14 +141,16 @@ class MatchCompilerTest(unittest.TestCase):
|
|||
# findmatch with end token
|
||||
input = 'if (Token::findmatch(tok->next()->next(), "foobar %type%", tok->link())) {'
|
||||
output = self.mc._replaceTokenFindMatch(input)
|
||||
self.assertEqual(output, 'if (findmatch3(tok->next()->next(), tok->link())) {')
|
||||
self.assertEqual(
|
||||
output, 'if (findmatch3(tok->next()->next(), tok->link())) {')
|
||||
self.assertEqual(2, len(self.mc._matchStrs))
|
||||
self.assertEqual(1, self.mc._matchStrs['foobar'])
|
||||
|
||||
# findmatch with end token and varid
|
||||
input = 'if (Token::findmatch(tok->next()->next(), "foobar %type% %varid%", tok->link(), 123)) {'
|
||||
output = self.mc._replaceTokenFindMatch(input)
|
||||
self.assertEqual(output, 'if (findmatch4(tok->next()->next(), tok->link(), 123)) {')
|
||||
self.assertEqual(
|
||||
output, 'if (findmatch4(tok->next()->next(), tok->link(), 123)) {')
|
||||
self.assertEqual(2, len(self.mc._matchStrs))
|
||||
self.assertEqual(1, self.mc._matchStrs['foobar'])
|
||||
|
||||
|
|
Loading…
Reference in New Issue