summaryrefslogtreecommitdiff
path: root/third_party/pep8/testsuite
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/pep8/testsuite')
-rw-r--r--third_party/pep8/testsuite/E10.py41
-rw-r--r--third_party/pep8/testsuite/E11.py36
-rw-r--r--third_party/pep8/testsuite/E12.py376
-rw-r--r--third_party/pep8/testsuite/E12not.py644
-rw-r--r--third_party/pep8/testsuite/E20.py55
-rw-r--r--third_party/pep8/testsuite/E21.py14
-rw-r--r--third_party/pep8/testsuite/E22.py157
-rw-r--r--third_party/pep8/testsuite/E23.py15
-rw-r--r--third_party/pep8/testsuite/E24.py13
-rw-r--r--third_party/pep8/testsuite/E25.py36
-rw-r--r--third_party/pep8/testsuite/E26.py59
-rw-r--r--third_party/pep8/testsuite/E27.py30
-rw-r--r--third_party/pep8/testsuite/E30.py90
-rw-r--r--third_party/pep8/testsuite/E30not.py134
-rw-r--r--third_party/pep8/testsuite/E40.py38
-rw-r--r--third_party/pep8/testsuite/E50.py118
-rw-r--r--third_party/pep8/testsuite/E70.py20
-rw-r--r--third_party/pep8/testsuite/E71.py73
-rw-r--r--third_party/pep8/testsuite/E72.py51
-rw-r--r--third_party/pep8/testsuite/E73.py18
-rw-r--r--third_party/pep8/testsuite/E90.py26
-rw-r--r--third_party/pep8/testsuite/W19.py145
-rw-r--r--third_party/pep8/testsuite/W29.py21
-rw-r--r--third_party/pep8/testsuite/W39.py18
-rw-r--r--third_party/pep8/testsuite/W60.py15
-rw-r--r--third_party/pep8/testsuite/__init__.py0
-rw-r--r--third_party/pep8/testsuite/latin-1.py6
-rw-r--r--third_party/pep8/testsuite/noqa.py15
-rw-r--r--third_party/pep8/testsuite/python3.py6
-rw-r--r--third_party/pep8/testsuite/support.py197
-rw-r--r--third_party/pep8/testsuite/test_all.py63
-rw-r--r--third_party/pep8/testsuite/test_api.py389
-rw-r--r--third_party/pep8/testsuite/test_shell.py189
-rw-r--r--third_party/pep8/testsuite/test_util.py23
-rw-r--r--third_party/pep8/testsuite/utf-8-bom.py6
-rw-r--r--third_party/pep8/testsuite/utf-8.py52
36 files changed, 3189 insertions, 0 deletions
diff --git a/third_party/pep8/testsuite/E10.py b/third_party/pep8/testsuite/E10.py
new file mode 100644
index 00000000000..cd142e39333
--- /dev/null
+++ b/third_party/pep8/testsuite/E10.py
@@ -0,0 +1,41 @@
+#: E101 W191
+for a in 'abc':
+ for b in 'xyz':
+ print a # indented with 8 spaces
+ print b # indented with 1 tab
+#: E101 E122 W191 W191
+if True:
+ pass
+
+change_2_log = \
+"""Change 2 by slamb@testclient on 2006/04/13 21:46:23
+
+ creation
+"""
+
+p4change = {
+ 2: change_2_log,
+}
+
+
+class TestP4Poller(unittest.TestCase):
+ def setUp(self):
+ self.setUpGetProcessOutput()
+ return self.setUpChangeSource()
+
+ def tearDown(self):
+ pass
+
+#
+#: E101 W191 W191
+if True:
+ foo(1,
+ 2)
+#: E101 E101 W191 W191
+def test_keys(self):
+ """areas.json - All regions are accounted for."""
+ expected = set([
+ u'Norrbotten',
+ u'V\xe4sterbotten',
+ ])
+#:
diff --git a/third_party/pep8/testsuite/E11.py b/third_party/pep8/testsuite/E11.py
new file mode 100644
index 00000000000..4ed1096334a
--- /dev/null
+++ b/third_party/pep8/testsuite/E11.py
@@ -0,0 +1,36 @@
+#: E111
+if x > 2:
+ print x
+#: E111
+if True:
+ print
+#: E112
+if False:
+print
+#: E113
+print
+ print
+#: E114 E116
+mimetype = 'application/x-directory'
+ # 'httpd/unix-directory'
+create_date = False
+#: E116 E116 E116
+def start(self):
+ if True:
+ self.master.start()
+ # try:
+ # self.master.start()
+ # except MasterExit:
+ # self.shutdown()
+ # finally:
+ # sys.exit()
+#: E115 E115 E115 E115 E115 E115
+def start(self):
+ if True:
+# try:
+# self.master.start()
+# except MasterExit:
+# self.shutdown()
+# finally:
+# sys.exit()
+ self.master.start()
diff --git a/third_party/pep8/testsuite/E12.py b/third_party/pep8/testsuite/E12.py
new file mode 100644
index 00000000000..7d76ee37a54
--- /dev/null
+++ b/third_party/pep8/testsuite/E12.py
@@ -0,0 +1,376 @@
+#: E121
+print "E121", (
+ "dent")
+#: E122
+print "E122", (
+"dent")
+#: E123
+my_list = [
+ 1, 2, 3,
+ 4, 5, 6,
+ ]
+#: E124
+print "E124", ("visual",
+ "indent_two"
+ )
+#: E124
+print "E124", ("visual",
+ "indent_five"
+)
+#: E124
+a = (123,
+)
+#: E129
+if (row < 0 or self.moduleCount <= row or
+ col < 0 or self.moduleCount <= col):
+ raise Exception("%s,%s - %s" % (row, col, self.moduleCount))
+#: E126
+print "E126", (
+ "dent")
+#: E126
+print "E126", (
+ "dent")
+#: E127
+print "E127", ("over-",
+ "over-indent")
+#: E128
+print "E128", ("visual",
+ "hanging")
+#: E128
+print "E128", ("under-",
+ "under-indent")
+#:
+
+
+#: E126
+my_list = [
+ 1, 2, 3,
+ 4, 5, 6,
+ ]
+#: E121
+result = {
+ 'key1': 'value',
+ 'key2': 'value',
+}
+#: E126 E126
+rv.update(dict.fromkeys((
+ 'qualif_nr', 'reasonComment_en', 'reasonComment_fr',
+ 'reasonComment_de', 'reasonComment_it'),
+ '?'),
+ "foo")
+#: E126
+abricot = 3 + \
+ 4 + \
+ 5 + 6
+#: E131
+print "hello", (
+
+ "there",
+ # "john",
+ "dude")
+#: E126
+part = set_mimetype((
+ a.get('mime_type', 'text')),
+ 'default')
+#:
+
+
+#: E122
+if True:
+ result = some_function_that_takes_arguments(
+ 'a', 'b', 'c',
+ 'd', 'e', 'f',
+)
+#: E122
+if some_very_very_very_long_variable_name or var \
+or another_very_long_variable_name:
+ raise Exception()
+#: E122
+if some_very_very_very_long_variable_name or var[0] \
+or another_very_long_variable_name:
+ raise Exception()
+#: E122
+if True:
+ if some_very_very_very_long_variable_name or var \
+ or another_very_long_variable_name:
+ raise Exception()
+#: E122
+if True:
+ if some_very_very_very_long_variable_name or var[0] \
+ or another_very_long_variable_name:
+ raise Exception()
+#: E122
+dictionary = [
+ "is": {
+ "nested": yes(),
+ },
+]
+#: E122
+setup('',
+ scripts=[''],
+ classifiers=[
+ 'Development Status :: 4 - Beta',
+ 'Environment :: Console',
+ 'Intended Audience :: Developers',
+ ])
+#:
+
+
+#: E123 W291
+print "E123", (
+ "bad", "hanging", "close"
+ )
+#
+#: E123 E123 E123
+result = {
+ 'foo': [
+ 'bar', {
+ 'baz': 'frop',
+ }
+ ]
+ }
+#: E123
+result = some_function_that_takes_arguments(
+ 'a', 'b', 'c',
+ 'd', 'e', 'f',
+ )
+#: E124
+my_list = [1, 2, 3,
+ 4, 5, 6,
+]
+#: E124
+my_list = [1, 2, 3,
+ 4, 5, 6,
+ ]
+#: E124
+result = some_function_that_takes_arguments('a', 'b', 'c',
+ 'd', 'e', 'f',
+)
+#: E124
+fooff(aaaa,
+ cca(
+ vvv,
+ dadd
+ ), fff,
+)
+#: E124
+fooff(aaaa,
+ ccaaa(
+ vvv,
+ dadd
+ ),
+ fff,
+)
+#: E124
+d = dict('foo',
+ help="exclude files or directories which match these "
+ "comma separated patterns (default: %s)" % DEFAULT_EXCLUDE
+ )
+#: E124 E128 E128
+if line_removed:
+ self.event(cr, uid,
+ name="Removing the option for contract",
+ description="contract line has been removed",
+ )
+#:
+
+
+#: E125
+if foo is None and bar is "frop" and \
+ blah == 'yeah':
+ blah = 'yeahnah'
+#: E125
+# Further indentation required as indentation is not distinguishable
+
+
+def long_function_name(
+ var_one, var_two, var_three,
+ var_four):
+ print(var_one)
+#
+#: E125
+
+
+def qualify_by_address(
+ self, cr, uid, ids, context=None,
+ params_to_check=frozenset(QUALIF_BY_ADDRESS_PARAM)):
+ """ This gets called by the web server """
+#: E129
+if (a == 2 or
+ b == "abc def ghi"
+ "jkl mno"):
+ return True
+#:
+
+
+#: E126
+my_list = [
+ 1, 2, 3,
+ 4, 5, 6,
+ ]
+#: E126
+abris = 3 + \
+ 4 + \
+ 5 + 6
+#: E126
+fixed = re.sub(r'\t+', ' ', target[c::-1], 1)[::-1] + \
+ target[c + 1:]
+#: E126 E126
+rv.update(dict.fromkeys((
+ 'qualif_nr', 'reasonComment_en', 'reasonComment_fr',
+ 'reasonComment_de', 'reasonComment_it'),
+ '?'),
+ "foo")
+#: E126
+eat_a_dict_a_day({
+ "foo": "bar",
+})
+#: E126
+if (
+ x == (
+ 3
+ ) or
+ y == 4):
+ pass
+#: E126
+if (
+ x == (
+ 3
+ ) or
+ x == (
+ 3
+ ) or
+ y == 4):
+ pass
+#: E131
+troublesome_hash = {
+ "hash": "value",
+ "long": "the quick brown fox jumps over the lazy dog before doing a "
+ "somersault",
+}
+#:
+
+
+#: E128
+# Arguments on first line forbidden when not using vertical alignment
+foo = long_function_name(var_one, var_two,
+ var_three, var_four)
+#
+#: E128
+print('l.%s\t%s\t%s\t%r' %
+ (token[2][0], pos, tokenize.tok_name[token[0]], token[1]))
+#: E128
+
+
+def qualify_by_address(self, cr, uid, ids, context=None,
+ params_to_check=frozenset(QUALIF_BY_ADDRESS_PARAM)):
+ """ This gets called by the web server """
+#:
+
+
+#: E128
+foo(1, 2, 3,
+4, 5, 6)
+#: E128
+foo(1, 2, 3,
+ 4, 5, 6)
+#: E128
+foo(1, 2, 3,
+ 4, 5, 6)
+#: E128
+foo(1, 2, 3,
+ 4, 5, 6)
+#: E127
+foo(1, 2, 3,
+ 4, 5, 6)
+#: E127
+foo(1, 2, 3,
+ 4, 5, 6)
+#: E127
+foo(1, 2, 3,
+ 4, 5, 6)
+#: E127
+foo(1, 2, 3,
+ 4, 5, 6)
+#: E127
+foo(1, 2, 3,
+ 4, 5, 6)
+#: E127
+foo(1, 2, 3,
+ 4, 5, 6)
+#: E127
+foo(1, 2, 3,
+ 4, 5, 6)
+#: E127
+foo(1, 2, 3,
+ 4, 5, 6)
+#: E127
+foo(1, 2, 3,
+ 4, 5, 6)
+#: E128 E128
+if line_removed:
+ self.event(cr, uid,
+ name="Removing the option for contract",
+ description="contract line has been removed",
+ )
+#: E124 E127 E127
+if line_removed:
+ self.event(cr, uid,
+ name="Removing the option for contract",
+ description="contract line has been removed",
+ )
+#: E127
+rv.update(d=('a', 'b', 'c'),
+ e=42)
+#
+#: E127
+rv.update(d=('a' + 'b', 'c'),
+ e=42, f=42
+ + 42)
+#: E127
+input1 = {'a': {'calc': 1 + 2}, 'b': 1
+ + 42}
+#: E128
+rv.update(d=('a' + 'b', 'c'),
+ e=42, f=(42
+ + 42))
+#: E123
+if True:
+ def example_issue254():
+ return [node.copy(
+ (
+ replacement
+ # First, look at all the node's current children.
+ for child in node.children
+ # Replace them.
+ for replacement in replace(child)
+ ),
+ dict(name=token.undefined)
+ )]
+#: E125:2:5 E125:8:5
+if ("""
+ """):
+ pass
+
+for foo in """
+ abc
+ 123
+ """.strip().split():
+ print(foo)
+#: E122:6:5 E122:7:5 E122:8:1
+print dedent(
+ '''
+ mkdir -p ./{build}/
+ mv ./build/ ./{build}/%(revision)s/
+ '''.format(
+ build='build',
+ # more stuff
+)
+)
+#: E701:1:8 E122:2:1 E203:4:8 E128:5:1
+if True:\
+print(True)
+
+print(a
+, end=' ')
+#:
diff --git a/third_party/pep8/testsuite/E12not.py b/third_party/pep8/testsuite/E12not.py
new file mode 100644
index 00000000000..e76ef13433a
--- /dev/null
+++ b/third_party/pep8/testsuite/E12not.py
@@ -0,0 +1,644 @@
+if (
+ x == (
+ 3
+ ) or
+ y == 4):
+ pass
+
+y = x == 2 \
+ or x == 3
+
+if x == 2 \
+ or y > 1 \
+ or x == 3:
+ pass
+
+if x == 2 \
+ or y > 1 \
+ or x == 3:
+ pass
+
+
+if (foo == bar and
+ baz == frop):
+ pass
+
+if (
+ foo == bar and
+ baz == frop
+):
+ pass
+
+
+a = (
+)
+
+a = (123,
+ )
+
+
+#
+
+
+if start[1] > end_col and not (
+ over_indent == 4 and indent_next):
+ return(0, "E121 continuation line over-"
+ "indented for visual indent")
+
+
+print "OK", ("visual",
+ "indent")
+
+print "Okay", ("visual",
+ "indent_three"
+ )
+
+print "a-ok", (
+ "there",
+ "dude",
+)
+
+print "hello", (
+ "there",
+ "dude")
+
+print "hello", (
+
+ "there",
+ # "john",
+ "dude")
+
+print "hello", (
+ "there", "dude")
+
+print "hello", (
+ "there", "dude",
+)
+
+# Aligned with opening delimiter
+foo = long_function_name(var_one, var_two,
+ var_three, var_four)
+
+#
+# Extra indentation is not necessary.
+foo = long_function_name(
+ var_one, var_two,
+ var_three, var_four)
+
+
+arm = 'AAA' \
+ 'BBB' \
+ 'CCC'
+
+bbb = 'AAA' \
+ 'BBB' \
+ 'CCC'
+
+cc = ('AAA'
+ 'BBB'
+ 'CCC')
+
+cc = {'text': 'AAA'
+ 'BBB'
+ 'CCC'}
+
+cc = dict(text='AAA'
+ 'BBB')
+
+sat = 'AAA' \
+ 'BBB' \
+ 'iii' \
+ 'CCC'
+
+abricot = (3 +
+ 4 +
+ 5 + 6)
+
+abricot = 3 + \
+ 4 + \
+ 5 + 6
+
+part = [-1, 2, 3,
+ 4, 5, 6]
+
+part = [-1, (2, 3,
+ 4, 5, 6), 7,
+ 8, 9, 0]
+
+fnct(1, 2, 3,
+ 4, 5, 6)
+
+fnct(1, 2, 3,
+ 4, 5, 6,
+ 7, 8, 9,
+ 10, 11)
+
+
+def long_function_name(
+ var_one, var_two, var_three,
+ var_four):
+ print(var_one)
+
+if ((row < 0 or self.moduleCount <= row or
+ col < 0 or self.moduleCount <= col)):
+ raise Exception("%s,%s - %s" % (row, col, self.moduleCount))
+
+
+result = {
+ 'foo': [
+ 'bar', {
+ 'baz': 'frop',
+ }
+ ]
+}
+
+
+foo = my.func({
+ "foo": "bar",
+}, "baz")
+
+
+#
+
+fooff(aaaa,
+ cca(
+ vvv,
+ dadd
+ ), fff,
+ ggg)
+
+fooff(aaaa,
+ abbb,
+ cca(
+ vvv,
+ aaa,
+ dadd),
+ "visual indentation is not a multiple of four",)
+#
+
+if bar:
+ return(
+ start, 'E121 lines starting with a '
+ 'closing bracket should be indented '
+ "to match that of the opening "
+ "bracket's line"
+ )
+#
+# you want vertical alignment, so use a parens
+if ((foo.bar("baz") and
+ foo.bar("frop")
+ )):
+ print "yes"
+
+# also ok, but starting to look like LISP
+if ((foo.bar("baz") and
+ foo.bar("frop"))):
+ print "yes"
+
+if (a == 2 or
+ b == "abc def ghi"
+ "jkl mno"):
+ return True
+
+if (a == 2 or
+ b == """abc def ghi
+jkl mno"""):
+ return True
+
+if length > options.max_line_length:
+ return options.max_line_length, \
+ "E501 line too long (%d characters)" % length
+
+
+#
+
+
+print 'l.{line}\t{pos}\t{name}\t{text}'.format(
+ line=token[2][0],
+ pos=pos,
+ name=tokenize.tok_name[token[0]],
+ text=repr(token[1]),
+)
+
+print('%-7d %s per second (%d total)' % (
+ options.counters[key] / elapsed, key,
+ options.counters[key]))
+
+
+if os.path.exists(os.path.join(path, PEP8_BIN)):
+ cmd = ([os.path.join(path, PEP8_BIN)] +
+ self._pep8_options(targetfile))
+
+
+fixed = (re.sub(r'\t+', ' ', target[c::-1], 1)[::-1] +
+ target[c + 1:])
+
+fixed = (
+ re.sub(r'\t+', ' ', target[c::-1], 1)[::-1] +
+ target[c + 1:]
+)
+
+
+if foo is None and bar is "frop" and \
+ blah == 'yeah':
+ blah = 'yeahnah'
+
+
+"""This is a multi-line
+ docstring."""
+
+
+if blah:
+ # is this actually readable? :)
+ multiline_literal = """
+while True:
+ if True:
+ 1
+""".lstrip()
+ multiline_literal = (
+ """
+while True:
+ if True:
+ 1
+""".lstrip()
+ )
+ multiline_literal = (
+ """
+while True:
+ if True:
+ 1
+"""
+ .lstrip()
+ )
+
+
+if blah:
+ multiline_visual = ("""
+while True:
+ if True:
+ 1
+"""
+ .lstrip())
+
+
+rv = {'aaa': 42}
+rv.update(dict.fromkeys((
+ 'qualif_nr', 'reasonComment_en', 'reasonComment_fr',
+ 'reasonComment_de', 'reasonComment_it'), '?'))
+
+rv.update(dict.fromkeys(('qualif_nr', 'reasonComment_en',
+ 'reasonComment_fr', 'reasonComment_de',
+ 'reasonComment_it'), '?'))
+
+rv.update(dict.fromkeys(('qualif_nr', 'reasonComment_en', 'reasonComment_fr',
+ 'reasonComment_de', 'reasonComment_it'), '?'))
+
+
+rv.update(dict.fromkeys(
+ ('qualif_nr', 'reasonComment_en', 'reasonComment_fr',
+ 'reasonComment_de', 'reasonComment_it'), '?'
+), "foo", context={
+ 'alpha': 4, 'beta': 53242234, 'gamma': 17,
+})
+
+
+rv.update(
+ dict.fromkeys((
+ 'qualif_nr', 'reasonComment_en', 'reasonComment_fr',
+ 'reasonComment_de', 'reasonComment_it'), '?'),
+ "foo",
+ context={
+ 'alpha': 4, 'beta': 53242234, 'gamma': 17,
+ },
+)
+
+
+#
+
+
+event_obj.write(cursor, user_id, {
+ 'user': user,
+ 'summary': text,
+ 'data': data,
+})
+
+event_obj.write(cursor, user_id, {
+ 'user': user,
+ 'summary': text,
+ 'data': {'aaa': 1, 'bbb': 2},
+})
+
+event_obj.write(cursor, user_id, {
+ 'user': user,
+ 'summary': text,
+ 'data': {
+ 'aaa': 1,
+ 'bbb': 2},
+})
+
+event_obj.write(cursor, user_id, {
+ 'user': user,
+ 'summary': text,
+ 'data': {'timestamp': now, 'content': {
+ 'aaa': 1,
+ 'bbb': 2
+ }},
+})
+
+
+def qualify_by_address(
+ self, cr, uid, ids, context=None,
+ params_to_check=frozenset(QUALIF_BY_ADDRESS_PARAM)):
+ """ This gets called by the web server """
+
+
+def qualify_by_address(self, cr, uid, ids, context=None,
+ params_to_check=frozenset(QUALIF_BY_ADDRESS_PARAM)):
+ """ This gets called by the web server """
+
+
+_ipv4_re = re.compile('^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.'
+ '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.'
+ '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.'
+ '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$')
+
+
+fct("""
+ AAA """ + status_2_string)
+
+
+if context:
+ msg = """\
+action: GET-CONFIG
+payload:
+ ip_address: "%(ip)s"
+ username: "%(username)s"
+""" % context
+
+
+if context:
+ msg = """\
+action: \
+GET-CONFIG
+""" % context
+
+
+if context:
+ msg = """\
+action: """\
+"""GET-CONFIG
+""" % context
+
+
+def unicode2html(s):
+ """Convert the characters &<>'" in string s to HTML-safe sequences.
+ Convert newline to <br> too."""
+ return unicode((s or '').replace('&', '&amp;')
+ .replace('>', '&gt;')
+ .replace('<', '&lt;')
+ .replace("'", '&#39;')
+ .replace('"', '&#34;')
+ .replace('\n', '<br>\n'))
+
+#
+parser.add_option('--count', action='store_true',
+ help="print total number of errors and warnings "
+ "to standard error and set exit code to 1 if "
+ "total is not null")
+
+parser.add_option('--exclude', metavar='patterns', default=DEFAULT_EXCLUDE,
+ help="exclude files or directories which match these "
+ "comma separated patterns (default: %s)" %
+ DEFAULT_EXCLUDE)
+
+add_option('--count',
+ help="print total number of errors "
+ "to standard error total is not null")
+
+add_option('--count',
+ help="print total number of errors "
+ "to standard error "
+ "total is not null")
+
+
+#
+
+
+help = ("print total number of errors " +
+ "to standard error")
+
+help = "print total number of errors " \
+ "to standard error"
+
+help = u"print total number of errors " \
+ u"to standard error"
+
+help = ur"print total number of errors " \
+ ur"to standard error"
+
+help = b"print total number of errors " \
+ b"to standard error"
+
+help = br"print total number of errors " \
+ br"to standard error"
+
+d = dict('foo', help="exclude files or directories which match these "
+ "comma separated patterns (default: %s)" %
+ DEFAULT_EXCLUDE)
+
+d = dict('foo', help=u"exclude files or directories which match these "
+ u"comma separated patterns (default: %s)" %
+ DEFAULT_EXCLUDE)
+
+d = dict('foo', help=b"exclude files or directories which match these "
+ b"comma separated patterns (default: %s)" %
+ DEFAULT_EXCLUDE)
+
+d = dict('foo', help=br"exclude files or directories which match these "
+ br"comma separated patterns (default: %s)" %
+ DEFAULT_EXCLUDE)
+
+d = dict('foo',
+ help="exclude files or directories which match these "
+ "comma separated patterns (default: %s)" %
+ DEFAULT_EXCLUDE)
+
+d = dict('foo',
+ help="exclude files or directories which match these "
+ "comma separated patterns (default: %s, %s)" %
+ (DEFAULT_EXCLUDE, DEFAULT_IGNORE)
+ )
+
+d = dict('foo',
+ help="exclude files or directories which match these "
+ "comma separated patterns (default: %s, %s)" %
+ # who knows what might happen here?
+ (DEFAULT_EXCLUDE, DEFAULT_IGNORE)
+ )
+
+# parens used to allow the indenting.
+troublefree_hash = {
+ "hash": "value",
+ "long": ("the quick brown fox jumps over the lazy dog before doing a "
+ "somersault"),
+ "long key that tends to happen more when you're indented": (
+ "stringwithalongtoken you don't want to break"
+ ),
+}
+
+# another accepted form
+troublefree_hash = {
+ "hash": "value",
+ "long": "the quick brown fox jumps over the lazy dog before doing "
+ "a somersault",
+ ("long key that tends to happen more "
+ "when you're indented"): "stringwithalongtoken you don't want to break",
+}
+# confusing but accepted... don't do that
+troublesome_hash = {
+ "hash": "value",
+ "long": "the quick brown fox jumps over the lazy dog before doing a "
+ "somersault",
+ "long key that tends to happen more "
+ "when you're indented": "stringwithalongtoken you don't want to break",
+}
+
+#
+d = dict('foo',
+ help="exclude files or directories which match these "
+ "comma separated patterns (default: %s)" %
+ DEFAULT_EXCLUDE
+ )
+d = dict('foo',
+ help="exclude files or directories which match these "
+ "comma separated patterns (default: %s)" % DEFAULT_EXCLUDE,
+ foobar="this clearly should work, because it is at "
+ "the right indent level",
+ )
+
+rv.update(dict.fromkeys(
+ ('qualif_nr', 'reasonComment_en', 'reasonComment_fr',
+ 'reasonComment_de', 'reasonComment_it'),
+ '?'), "foo",
+ context={'alpha': 4, 'beta': 53242234, 'gamma': 17})
+
+
+def f():
+ try:
+ if not Debug:
+ print('''
+If you would like to see debugging output,
+try: %s -d5
+''' % sys.argv[0])
+
+
+d = { # comment
+ 1: 2
+}
+
+# issue 138
+[
+ 12, # this is a multi-line inline
+ # comment
+]
+# issue 151
+if a > b and \
+ c > d:
+ moo_like_a_cow()
+#
+my_list = [
+ 1, 2, 3,
+ 4, 5, 6,
+]
+
+my_list = [1, 2, 3,
+ 4, 5, 6,
+ ]
+
+result = some_function_that_takes_arguments(
+ 'a', 'b', 'c',
+ 'd', 'e', 'f',
+)
+
+result = some_function_that_takes_arguments('a', 'b', 'c',
+ 'd', 'e', 'f',
+ )
+
+# issue 203
+dica = {
+ ('abc'
+ 'def'): (
+ 'abc'),
+}
+
+(abcdef[0]
+ [1]) = (
+ 'abc')
+
+('abc'
+ 'def') == (
+ 'abc')
+
+# issue 214
+bar(
+ 1).zap(
+ 2)
+
+bar(
+ 1).zap(
+ 2)
+#
+if True:
+
+ def example_issue254():
+ return [node.copy(
+ (
+ replacement
+ # First, look at all the node's current children.
+ for child in node.children
+ # Replace them.
+ for replacement in replace(child)
+ ),
+ dict(name=token.undefined)
+ )]
+
+
+def valid_example():
+ return [node.copy(properties=dict(
+ (key, val if val is not None else token.undefined)
+ for key, val in node.items()
+ ))]
+
+
+def other_example():
+ return [node.copy(properties=dict(
+ (key, val if val is not None else token.undefined)
+ for key, val in node.items()
+ ))]
+
+foo([
+ 'bug'
+])
+
+# issue 144, finally!
+some_hash = {
+ "long key that tends to happen more when you're indented":
+ "stringwithalongtoken you don't want to break",
+}
+
+{
+ 1:
+ 999999 if True
+ else 0,
+}
+
+
+print dedent(
+ '''
+ mkdir -p ./{build}/
+ mv ./build/ ./{build}/%(revision)s/
+ '''.format(
+ build='build',
+ # more stuff
+ )
+)
diff --git a/third_party/pep8/testsuite/E20.py b/third_party/pep8/testsuite/E20.py
new file mode 100644
index 00000000000..2f1ecc28c92
--- /dev/null
+++ b/third_party/pep8/testsuite/E20.py
@@ -0,0 +1,55 @@
+#: E201:1:6
+spam( ham[1], {eggs: 2})
+#: E201:1:10
+spam(ham[ 1], {eggs: 2})
+#: E201:1:15
+spam(ham[1], { eggs: 2})
+#: Okay
+spam(ham[1], {eggs: 2})
+#:
+
+
+#: E202:1:23
+spam(ham[1], {eggs: 2} )
+#: E202:1:22
+spam(ham[1], {eggs: 2 })
+#: E202:1:11
+spam(ham[1 ], {eggs: 2})
+#: Okay
+spam(ham[1], {eggs: 2})
+
+result = func(
+ arg1='some value',
+ arg2='another value',
+)
+
+result = func(
+ arg1='some value',
+ arg2='another value'
+)
+
+result = [
+ item for item in items
+ if item > 5
+]
+#:
+
+
+#: E203:1:10
+if x == 4 :
+ print x, y
+ x, y = y, x
+#: E203:2:15 E702:2:16
+if x == 4:
+ print x, y ; x, y = y, x
+#: E203:3:13
+if x == 4:
+ print x, y
+ x, y = y , x
+#: Okay
+if x == 4:
+ print x, y
+ x, y = y, x
+a[b1, :] == a[b1, ...]
+b = a[:, b1]
+#:
diff --git a/third_party/pep8/testsuite/E21.py b/third_party/pep8/testsuite/E21.py
new file mode 100644
index 00000000000..96b55b87901
--- /dev/null
+++ b/third_party/pep8/testsuite/E21.py
@@ -0,0 +1,14 @@
+#: E211
+spam (1)
+#: E211 E211
+dict ['key'] = list [index]
+#: E211
+dict['key'] ['subkey'] = list[index]
+#: Okay
+spam(1)
+dict['key'] = list[index]
+
+
+# This is not prohibited by PEP8, but avoid it.
+class Foo (Bar, Baz):
+ pass
diff --git a/third_party/pep8/testsuite/E22.py b/third_party/pep8/testsuite/E22.py
new file mode 100644
index 00000000000..9d8efda5e67
--- /dev/null
+++ b/third_party/pep8/testsuite/E22.py
@@ -0,0 +1,157 @@
+#: E221
+a = 12 + 3
+b = 4 + 5
+#: E221 E221
+x = 1
+y = 2
+long_variable = 3
+#: E221 E221
+x[0] = 1
+x[1] = 2
+long_variable = 3
+#: E221 E221
+x = f(x) + 1
+y = long_variable + 2
+z = x[0] + 3
+#: E221:3:14
+text = """
+ bar
+ foo %s""" % rofl
+#: Okay
+x = 1
+y = 2
+long_variable = 3
+#:
+
+
+#: E222
+a = a + 1
+b = b + 10
+#: E222 E222
+x = -1
+y = -2
+long_variable = 3
+#: E222 E222
+x[0] = 1
+x[1] = 2
+long_variable = 3
+#:
+
+
+#: E223
+foobart = 4
+a = 3 # aligned with tab
+#:
+
+
+#: E224
+a += 1
+b += 1000
+#:
+
+
+#: E225
+submitted +=1
+#: E225
+submitted+= 1
+#: E225
+c =-1
+#: E225
+x = x /2 - 1
+#: E225
+c = alpha -4
+#: E225
+c = alpha- 4
+#: E225
+z = x **y
+#: E225
+z = (x + 1) **y
+#: E225
+z = (x + 1)** y
+#: E225
+_1kB = _1MB >>10
+#: E225
+_1kB = _1MB>> 10
+#: E225 E225
+i=i+ 1
+#: E225 E225
+i=i +1
+#: E225 E226
+i=i+1
+#: E225 E226
+i =i+1
+#: E225 E226
+i= i+1
+#: E225 E226
+c = (a +b)*(a - b)
+#: E225 E226
+c = (a+ b)*(a - b)
+#:
+
+#: E226
+z = 2//30
+#: E226 E226
+c = (a+b) * (a-b)
+#: E226
+norman = True+False
+#: E226
+x = x*2 - 1
+#: E226
+x = x/2 - 1
+#: E226 E226
+hypot2 = x*x + y*y
+#: E226
+c = (a + b)*(a - b)
+#: E226
+def halves(n):
+ return (i//2 for i in range(n))
+#: E227
+_1kB = _1MB>>10
+#: E227
+_1MB = _1kB<<10
+#: E227
+a = b|c
+#: E227
+b = c&a
+#: E227
+c = b^a
+#: E228
+a = b%c
+#: E228
+msg = fmt%(errno, errmsg)
+#: E228
+msg = "Error %d occurred"%errno
+#:
+
+#: Okay
+i = i + 1
+submitted += 1
+x = x * 2 - 1
+hypot2 = x * x + y * y
+c = (a + b) * (a - b)
+_1MiB = 2 ** 20
+_1TiB = 2**30
+foo(bar, key='word', *args, **kwargs)
+baz(**kwargs)
+negative = -1
+spam(-1)
+-negative
+func1(lambda *args, **kw: (args, kw))
+func2(lambda a, b=h[:], c=0: (a, b, c))
+if not -5 < x < +5:
+ print >>sys.stderr, "x is out of range."
+print >> sys.stdout, "x is an integer."
+x = x / 2 - 1
+
+if alpha[:-i]:
+ *a, b = (1, 2, 3)
+
+
+def squares(n):
+ return (i**2 for i in range(n))
+
+ENG_PREFIXES = {
+ -6: "\u03bc", # Greek letter mu
+ -3: "m",
+}
+#:
diff --git a/third_party/pep8/testsuite/E23.py b/third_party/pep8/testsuite/E23.py
new file mode 100644
index 00000000000..e561fe795f9
--- /dev/null
+++ b/third_party/pep8/testsuite/E23.py
@@ -0,0 +1,15 @@
+#: E231
+a = (1,2)
+#: E231
+a[b1,:]
+#: E231
+a = [{'a':''}]
+#: Okay
+a = (4,)
+b = (5, )
+c = {'text': text[5:]}
+
+result = {
+ 'key1': 'value',
+ 'key2': 'value',
+}
diff --git a/third_party/pep8/testsuite/E24.py b/third_party/pep8/testsuite/E24.py
new file mode 100644
index 00000000000..36fb4aa7ebe
--- /dev/null
+++ b/third_party/pep8/testsuite/E24.py
@@ -0,0 +1,13 @@
+#: E241
+a = (1, 2)
+#: Okay
+b = (1, 20)
+#: E242
+a = (1, 2) # tab before 2
+#: Okay
+b = (1, 20) # space before 20
+#: E241 E241 E241
+# issue 135
+more_spaces = [a, b,
+ ef, +h,
+ c, -d]
diff --git a/third_party/pep8/testsuite/E25.py b/third_party/pep8/testsuite/E25.py
new file mode 100644
index 00000000000..ad8db8822e1
--- /dev/null
+++ b/third_party/pep8/testsuite/E25.py
@@ -0,0 +1,36 @@
+#: E251 E251
+def foo(bar = False):
+ '''Test function with an error in declaration'''
+ pass
+#: E251
+foo(bar= True)
+#: E251
+foo(bar =True)
+#: E251 E251
+foo(bar = True)
+#: E251
+y = bar(root= "sdasd")
+#: E251:2:29
+parser.add_argument('--long-option',
+ default=
+ "/rather/long/filesystem/path/here/blah/blah/blah")
+#: E251:1:45
+parser.add_argument('--long-option', default
+ ="/rather/long/filesystem/path/here/blah/blah/blah")
+#: E251:3:8 E251:3:10
+foo(True,
+ baz=(1, 2),
+ biz = 'foo'
+ )
+#: Okay
+foo(bar=(1 == 1))
+foo(bar=(1 != 1))
+foo(bar=(1 >= 1))
+foo(bar=(1 <= 1))
+(options, args) = parser.parse_args()
+d[type(None)] = _deepcopy_atomic
+
+# Annotated Function Definitions
+#: Okay
+def munge(input: AnyStr, sep: AnyStr = None, limit=1000) -> AnyStr:
+ pass
diff --git a/third_party/pep8/testsuite/E26.py b/third_party/pep8/testsuite/E26.py
new file mode 100644
index 00000000000..e64012620a8
--- /dev/null
+++ b/third_party/pep8/testsuite/E26.py
@@ -0,0 +1,59 @@
+#: E261:1:5
+pass # an inline comment
+#: E262:1:12
+x = x + 1 #Increment x
+#: E262:1:12
+x = x + 1 # Increment x
+#: E262:1:12
+x = y + 1 #: Increment x
+#: E265:1:1
+#Block comment
+a = 1
+#: E265:2:1
+m = 42
+#! This is important
+mx = 42 - 42
+#: E266:3:5 E266:6:5
+def how_it_feel(r):
+
+ ### This is a variable ###
+ a = 42
+
+ ### Of course it is unused
+ return
+#: E265:1:1 E266:2:1
+##if DEBUG:
+## logging.error()
+#: W291:1:42
+#########################################
+#:
+
+#: Okay
+#!/usr/bin/env python
+
+pass # an inline comment
+x = x + 1 # Increment x
+y = y + 1 #: Increment x
+
+# Block comment
+a = 1
+
+# Block comment1
+
+# Block comment2
+aaa = 1
+
+
+# example of docstring (not parsed)
+def oof():
+ """
+ #foo not parsed
+ """
+
+ ###########################################################################
+ # A SEPARATOR #
+ ###########################################################################
+
+ # ####################################################################### #
+ # ########################## another separator ########################## #
+ # ####################################################################### #
diff --git a/third_party/pep8/testsuite/E27.py b/third_party/pep8/testsuite/E27.py
new file mode 100644
index 00000000000..f9d3e8e17cb
--- /dev/null
+++ b/third_party/pep8/testsuite/E27.py
@@ -0,0 +1,30 @@
+#: Okay
+True and False
+#: E271
+True and False
+#: E272
+True and False
+#: E271
+if 1:
+#: E273
+True and False
+#: E273 E274
+True and False
+#: E271
+a and b
+#: E271
+1 and b
+#: E271
+a and 2
+#: E271 E272
+1 and b
+#: E271 E272
+a and 2
+#: E272
+this and False
+#: E273
+a and b
+#: E274
+a and b
+#: E273 E274
+this and False
diff --git a/third_party/pep8/testsuite/E30.py b/third_party/pep8/testsuite/E30.py
new file mode 100644
index 00000000000..d2d7bf35625
--- /dev/null
+++ b/third_party/pep8/testsuite/E30.py
@@ -0,0 +1,90 @@
+#: E301:5:5
+class X:
+
+ def a():
+ pass
+ def b():
+ pass
+#: E301:6:5
+class X:
+
+ def a():
+ pass
+ # comment
+ def b():
+ pass
+#:
+
+
+#: E302:3:1
+#!python
+# -*- coding: utf-8 -*-
+def a():
+ pass
+#: E302:2:1
+"""Main module."""
+def _main():
+ pass
+#: E302:2:1
+import sys
+def get_sys_path():
+ return sys.path
+#: E302:4:1
+def a():
+ pass
+
+def b():
+ pass
+#: E302:6:1
+def a():
+ pass
+
+# comment
+
+def b():
+ pass
+#:
+
+
+#: E303:5:1
+print
+
+
+
+print
+#: E303:5:1
+print
+
+
+
+# comment
+
+print
+#: E303:5:5 E303:8:5
+def a():
+ print
+
+
+ # comment
+
+
+ # another comment
+
+ print
+#:
+
+
+#: E304:3:1
+@decorator
+
+def function():
+ pass
+#: E303:5:1
+#!python
+
+
+
+"""This class docstring comes on line 5.
+It gives error E303: too many blank lines (3)
+"""
+#:
diff --git a/third_party/pep8/testsuite/E30not.py b/third_party/pep8/testsuite/E30not.py
new file mode 100644
index 00000000000..0fd8fb0c448
--- /dev/null
+++ b/third_party/pep8/testsuite/E30not.py
@@ -0,0 +1,134 @@
+#: Okay
+class X:
+ pass
+#: Okay
+
+def foo():
+ pass
+#: Okay
+# -*- coding: utf-8 -*-
+class X:
+ pass
+#: Okay
+# -*- coding: utf-8 -*-
+def foo():
+ pass
+#: Okay
+class X:
+
+ def a():
+ pass
+
+ # comment
+ def b():
+ pass
+
+ # This is a
+ # ... multi-line comment
+
+ def c():
+ pass
+
+
+# This is a
+# ... multi-line comment
+
+@some_decorator
+class Y:
+
+ def a():
+ pass
+
+ # comment
+
+ def b():
+ pass
+
+ @property
+ def c():
+ pass
+
+
+try:
+ from nonexistent import Bar
+except ImportError:
+ class Bar(object):
+ """This is a Bar replacement"""
+
+
+def with_feature(f):
+ """Some decorator"""
+ wrapper = f
+ if has_this_feature(f):
+ def wrapper(*args):
+ call_feature(args[0])
+ return f(*args)
+ return wrapper
+
+
+try:
+ next
+except NameError:
+ def next(iterator, default):
+ for item in iterator:
+ return item
+ return default
+
+
+def a():
+ pass
+
+
+class Foo():
+ """Class Foo"""
+
+ def b():
+
+ pass
+
+
+# comment
+def c():
+ pass
+
+
+# comment
+
+
+def d():
+ pass
+
+# This is a
+# ... multi-line comment
+
+# And this one is
+# ... a second paragraph
+# ... which spans on 3 lines
+
+
+# Function `e` is below
+# NOTE: Hey this is a testcase
+
+def e():
+ pass
+
+
+def a():
+ print
+
+ # comment
+
+ print
+
+ print
+
+# Comment 1
+
+# Comment 2
+
+
+# Comment 3
+
+def b():
+
+ pass
diff --git a/third_party/pep8/testsuite/E40.py b/third_party/pep8/testsuite/E40.py
new file mode 100644
index 00000000000..1051e32cf8e
--- /dev/null
+++ b/third_party/pep8/testsuite/E40.py
@@ -0,0 +1,38 @@
+#: E401
+import os, sys
+#: Okay
+import os
+import sys
+
+from subprocess import Popen, PIPE
+
+from myclass import MyClass
+from foo.bar.yourclass import YourClass
+
+import myclass
+import foo.bar.yourclass
+#: E402
+__all__ = ['abc']
+
+import foo
+#: Okay
+try:
+ import foo
+except:
+ pass
+else:
+ print('imported foo')
+finally:
+ print('made attempt to import foo')
+
+import bar
+#: E402
+VERSION = '1.2.3'
+
+import foo
+#: E402
+import foo
+
+a = 1
+
+import bar
diff --git a/third_party/pep8/testsuite/E50.py b/third_party/pep8/testsuite/E50.py
new file mode 100644
index 00000000000..f60f3890e7b
--- /dev/null
+++ b/third_party/pep8/testsuite/E50.py
@@ -0,0 +1,118 @@
+#: E501
+a = '12345678901234567890123456789012345678901234567890123456789012345678901234567890'
+#: E501
+a = '1234567890123456789012345678901234567890123456789012345678901234567890' or \
+ 6
+#: E501
+a = 7 or \
+ '1234567890123456789012345678901234567890123456789012345678901234567890' or \
+ 6
+#: E501 E501
+a = 7 or \
+ '1234567890123456789012345678901234567890123456789012345678901234567890' or \
+ '1234567890123456789012345678901234567890123456789012345678901234567890' or \
+ 6
+#: E501
+a = '1234567890123456789012345678901234567890123456789012345678901234567890' # \
+#: E502
+a = ('123456789012345678901234567890123456789012345678901234567890123456789' \
+ '01234567890')
+#: E502
+a = ('AAA \
+ BBB' \
+ 'CCC')
+#: E502
+if (foo is None and bar is "e000" and \
+ blah == 'yeah'):
+ blah = 'yeahnah'
+#
+#: Okay
+a = ('AAA'
+ 'BBB')
+
+a = ('AAA \
+ BBB'
+ 'CCC')
+
+a = 'AAA' \
+ 'BBB' \
+ 'CCC'
+
+a = ('AAA\
+BBBBBBBBB\
+CCCCCCCCC\
+DDDDDDDDD')
+#
+#: Okay
+if aaa:
+ pass
+elif bbb or \
+ ccc:
+ pass
+
+ddd = \
+ ccc
+
+('\
+ ' + ' \
+')
+('''
+ ''' + ' \
+')
+#: E501 E225 E226
+very_long_identifiers=and_terrible_whitespace_habits(are_no_excuse+for_long_lines)
+#
+#: E501
+'''multiline string
+with a long long long long long long long long long long long long long long long long line
+'''
+#: E501
+'''same thing, but this time without a terminal newline in the string
+long long long long long long long long long long long long long long long long line'''
+#
+# issue 224 (unavoidable long lines in docstrings)
+#: Okay
+"""
+I'm some great documentation. Because I'm some great documentation, I'm
+going to give you a reference to some valuable information about some API
+that I'm calling:
+
+ http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx
+"""
+#: E501
+"""
+longnospaceslongnospaceslongnospaceslongnospaceslongnospaceslongnospaceslongnospaceslongnospaces"""
+#: Okay
+"""
+This
+ almost_empty_line
+"""
+#: E501
+"""
+This
+ almost_empty_line
+"""
+#: E501
+# A basic comment
+# with a long long long long long long long long long long long long long long long long line
+
+#
+#: Okay
+# I'm some great comment. Because I'm so great, I'm going to give you a
+# reference to some valuable information about some API that I'm calling:
+#
+# http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx
+
+import this
+
+# longnospaceslongnospaceslongnospaceslongnospaceslongnospaceslongnospaceslongnospaceslongnospaces
+
+#
+#: Okay
+# This
+# almost_empty_line
+
+#
+#: E501
+# This
+# almost_empty_line
diff --git a/third_party/pep8/testsuite/E70.py b/third_party/pep8/testsuite/E70.py
new file mode 100644
index 00000000000..85ca66688f0
--- /dev/null
+++ b/third_party/pep8/testsuite/E70.py
@@ -0,0 +1,20 @@
+#: E701:1:5
+if a: a = False
+#: E701:1:40
+if not header or header[:6] != 'bytes=': return
+#: E702:1:10
+a = False; b = True
+#: E702:1:17
+import bdist_egg; bdist_egg.write_safety_flag(cmd.egg_info, safe)
+#: E703:1:13
+import shlex;
+#: E702:1:9 E703:1:23
+del a[:]; a.append(42);
+#: E704:1:1
+def f(x): return 2
+#: E704:1:1 E226:1:19
+def f(x): return 2*x
+#: E704:2:5 E226:2:23
+while all is round:
+ def f(x): return 2*x
+#:
diff --git a/third_party/pep8/testsuite/E71.py b/third_party/pep8/testsuite/E71.py
new file mode 100644
index 00000000000..ea870e54120
--- /dev/null
+++ b/third_party/pep8/testsuite/E71.py
@@ -0,0 +1,73 @@
+#: E711
+if res == None:
+ pass
+#: E711
+if res != None:
+ pass
+#: E711
+if None == res:
+ pass
+#: E711
+if None != res:
+ pass
+
+#
+#: E712
+if res == True:
+ pass
+#: E712
+if res != False:
+ pass
+#: E712
+if True != res:
+ pass
+#: E712
+if False == res:
+ pass
+
+#
+#: E713
+if not X in Y:
+ pass
+#: E713
+if not X.B in Y:
+ pass
+#: E713
+if not X in Y and Z == "zero":
+ pass
+#: E713
+if X == "zero" or not Y in Z:
+ pass
+
+#
+#: E714
+if not X is Y:
+ pass
+#: E714
+if not X.B is Y:
+ pass
+
+#
+#: Okay
+if x not in y:
+ pass
+
+if not (X in Y or X is Z):
+ pass
+
+if not (X in Y):
+ pass
+
+if x is not y:
+ pass
+
+if TrueElement.get_element(True) == TrueElement.get_element(False):
+ pass
+
+if (True) == TrueElement or x == TrueElement:
+ pass
+
+assert (not foo) in bar
+assert {'x': not foo} in bar
+assert [42, not foo] in bar
+#:
diff --git a/third_party/pep8/testsuite/E72.py b/third_party/pep8/testsuite/E72.py
new file mode 100644
index 00000000000..8eb34cb3991
--- /dev/null
+++ b/third_party/pep8/testsuite/E72.py
@@ -0,0 +1,51 @@
+#: E721
+if type(res) == type(42):
+ pass
+#: E721
+if type(res) != type(""):
+ pass
+#: E721
+import types
+
+if res == types.IntType:
+ pass
+#: E721
+import types
+
+if type(res) is not types.ListType:
+ pass
+#: E721
+assert type(res) == type(False) or type(res) == type(None)
+#: E721
+assert type(res) == type([])
+#: E721
+assert type(res) == type(())
+#: E721
+assert type(res) == type((0,))
+#: E721
+assert type(res) == type((0))
+#: E721
+assert type(res) != type((1, ))
+#: E721
+assert type(res) is type((1, ))
+#: E721
+assert type(res) is not type((1, ))
+#: E211 E721
+assert type(res) == type ([2, ])
+#: E201 E201 E202 E721
+assert type(res) == type( ( ) )
+#: E201 E202 E721
+assert type(res) == type( (0, ) )
+#:
+
+#: Okay
+import types
+
+if isinstance(res, int):
+ pass
+if isinstance(res, str):
+ pass
+if isinstance(res, types.MethodType):
+ pass
+if type(a) != type(b) or type(a) == type(ccc):
+ pass
diff --git a/third_party/pep8/testsuite/E73.py b/third_party/pep8/testsuite/E73.py
new file mode 100644
index 00000000000..60fcd239088
--- /dev/null
+++ b/third_party/pep8/testsuite/E73.py
@@ -0,0 +1,18 @@
+#: E731:1:1
+f = lambda x: 2 * x
+#: E731:1:1 E226:1:16
+f = lambda x: 2*x
+#: E731:2:5
+while False:
+ this = lambda y, z: 2 * x
+#: Okay
+f = object()
+f.method = lambda: 'Method'
+
+f = {}
+f['a'] = lambda x: x ** 2
+
+f = []
+f.append(lambda x: x ** 2)
+
+lambda: 'no-op'
diff --git a/third_party/pep8/testsuite/E90.py b/third_party/pep8/testsuite/E90.py
new file mode 100644
index 00000000000..3111c6833fe
--- /dev/null
+++ b/third_party/pep8/testsuite/E90.py
@@ -0,0 +1,26 @@
+#: E901
+}
+#: E901
+= [x
+#: E901 E101 W191
+while True:
+ try:
+ pass
+ except:
+ print 'Whoops'
+#: E122 E225 E251 E251 E701
+
+# Do not crash if code is invalid
+if msg:
+ errmsg = msg % progress.get(cr_dbname))
+
+def lasting(self, duration=300):
+ progress = self._progress.setdefault('foo', {}
+#: Okay
+
+# Issue #119
+# Do not crash with Python2 if the line endswith '\r\r\n'
+EMPTY_SET = set()
+SET_TYPE = type(EMPTY_SET)
+toto = 0 + 0
+#:
diff --git a/third_party/pep8/testsuite/W19.py b/third_party/pep8/testsuite/W19.py
new file mode 100644
index 00000000000..69db3065dbb
--- /dev/null
+++ b/third_party/pep8/testsuite/W19.py
@@ -0,0 +1,145 @@
+#: W191
+if False:
+ print # indented with 1 tab
+#:
+
+
+#: W191
+y = x == 2 \
+ or x == 3
+#: E101 W191
+if (
+ x == (
+ 3
+ ) or
+ y == 4):
+ pass
+#: E101 W191
+if x == 2 \
+ or y > 1 \
+ or x == 3:
+ pass
+#: E101 W191
+if x == 2 \
+ or y > 1 \
+ or x == 3:
+ pass
+#:
+
+#: E101 W191
+if (foo == bar and
+ baz == frop):
+ pass
+#: E101 W191
+if (
+ foo == bar and
+ baz == frop
+):
+ pass
+#:
+
+#: E101 E101 W191 W191
+if start[1] > end_col and not (
+ over_indent == 4 and indent_next):
+ return(0, "E121 continuation line over-"
+ "indented for visual indent")
+#:
+
+#: E101 W191
+
+
+def long_function_name(
+ var_one, var_two, var_three,
+ var_four):
+ print(var_one)
+#: E101 W191
+if ((row < 0 or self.moduleCount <= row or
+ col < 0 or self.moduleCount <= col)):
+ raise Exception("%s,%s - %s" % (row, col, self.moduleCount))
+#: E101 E101 E101 E101 W191 W191 W191 W191 W191 W191
+if bar:
+ return(
+ start, 'E121 lines starting with a '
+ 'closing bracket should be indented '
+ "to match that of the opening "
+ "bracket's line"
+ )
+#
+#: E101 W191
+# you want vertical alignment, so use a parens
+if ((foo.bar("baz") and
+ foo.bar("frop")
+ )):
+ print "yes"
+#: E101 W191
+# also ok, but starting to look like LISP
+if ((foo.bar("baz") and
+ foo.bar("frop"))):
+ print "yes"
+#: E101 W191
+if (a == 2 or
+ b == "abc def ghi"
+ "jkl mno"):
+ return True
+#: E101 W191
+if (a == 2 or
+ b == """abc def ghi
+jkl mno"""):
+ return True
+#: W191:2:1 W191:3:1 E101:3:2
+if length > options.max_line_length:
+ return options.max_line_length, \
+ "E501 line too long (%d characters)" % length
+
+
+#
+#: E101 W191 W191
+if os.path.exists(os.path.join(path, PEP8_BIN)):
+ cmd = ([os.path.join(path, PEP8_BIN)] +
+ self._pep8_options(targetfile))
+#: W191
+'''
+ multiline string with tab in it'''
+#: E101 W191
+'''multiline string
+ with tabs
+ and spaces
+'''
+#: Okay
+'''sometimes, you just need to go nuts in a multiline string
+ and allow all sorts of crap
+ like mixed tabs and spaces
+
+or trailing whitespace
+or long long long long long long long long long long long long long long long long long lines
+''' # nopep8
+#: Okay
+'''this one
+ will get no warning
+even though the noqa comment is not immediately after the string
+''' + foo # noqa
+#
+#: E101 W191
+if foo is None and bar is "frop" and \
+ blah == 'yeah':
+ blah = 'yeahnah'
+
+
+#
+#: W191 W191 W191
+if True:
+ foo(
+ 1,
+ 2)
+#: W191 W191 W191 W191 W191
+def test_keys(self):
+ """areas.json - All regions are accounted for."""
+ expected = set([
+ u'Norrbotten',
+ u'V\xe4sterbotten',
+ ])
+#: W191
+x = [
+ 'abc'
+]
+#:
diff --git a/third_party/pep8/testsuite/W29.py b/third_party/pep8/testsuite/W29.py
new file mode 100644
index 00000000000..1cdd84ff58d
--- /dev/null
+++ b/third_party/pep8/testsuite/W29.py
@@ -0,0 +1,21 @@
+#: Okay
+# 情
+#: W291:1:6
+print
+#: W293:2:1
+class Foo(object):
+
+ bang = 12
+#: W291:2:35
+'''multiline
+string with trailing whitespace'''
+#: W292:1:36 noeol
+# This line doesn't have a linefeed
+#: W292:1:5 E225:1:2 noeol
+1+ 1
+#: W292:1:27 E261:1:12 noeol
+import this # no line feed
+#: W292:3:22 noeol
+class Test(object):
+ def __repr__(self):
+ return 'test'
diff --git a/third_party/pep8/testsuite/W39.py b/third_party/pep8/testsuite/W39.py
new file mode 100644
index 00000000000..d4fe0a42f26
--- /dev/null
+++ b/third_party/pep8/testsuite/W39.py
@@ -0,0 +1,18 @@
+#: W391:2:1
+# The next line is blank
+
+#: W391:3:1
+# Two additional empty lines
+
+
+#: W391:4:1 W293:3:1 W293:4:1 noeol
+# The last lines contain space
+
+
+
+#: Okay
+'''there is nothing wrong
+with a multiline string at EOF
+
+that happens to have a blank line in it
+'''
diff --git a/third_party/pep8/testsuite/W60.py b/third_party/pep8/testsuite/W60.py
new file mode 100644
index 00000000000..973d22ff9e9
--- /dev/null
+++ b/third_party/pep8/testsuite/W60.py
@@ -0,0 +1,15 @@
+#: W601
+if a.has_key("b"):
+ print a
+#: W602
+raise DummyError, "Message"
+#: W602
+raise ValueError, "hello %s %s" % (1, 2)
+#: Okay
+raise type_, val, tb
+raise Exception, Exception("f"), t
+#: W603
+if x <> 0:
+ x = 0
+#: W604
+val = `1 + 2`
diff --git a/third_party/pep8/testsuite/__init__.py b/third_party/pep8/testsuite/__init__.py
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/third_party/pep8/testsuite/__init__.py
diff --git a/third_party/pep8/testsuite/latin-1.py b/third_party/pep8/testsuite/latin-1.py
new file mode 100644
index 00000000000..8328cfba9e7
--- /dev/null
+++ b/third_party/pep8/testsuite/latin-1.py
@@ -0,0 +1,6 @@
+# -*- coding: latin-1 -*-
+# Test non-UTF8 encoding
+latin1 = (''
+ '')
+
+c = ("w")
diff --git a/third_party/pep8/testsuite/noqa.py b/third_party/pep8/testsuite/noqa.py
new file mode 100644
index 00000000000..02fdd4f8251
--- /dev/null
+++ b/third_party/pep8/testsuite/noqa.py
@@ -0,0 +1,15 @@
+#: Okay
+# silence E501
+url = 'https://api.github.com/repos/sigmavirus24/Todo.txt-python/branches/master?client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxx&?client_secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' # noqa
+
+# silence E128
+from functools import (partial, reduce, wraps, # noqa
+ cmp_to_key)
+
+from functools import (partial, reduce, wraps,
+ cmp_to_key) # noqa
+
+a = 1
+if a == None: # noqa
+ pass
+#:
diff --git a/third_party/pep8/testsuite/python3.py b/third_party/pep8/testsuite/python3.py
new file mode 100644
index 00000000000..888188006f6
--- /dev/null
+++ b/third_party/pep8/testsuite/python3.py
@@ -0,0 +1,6 @@
+#!/usr/bin/env python3
+
+
+# Annotated function (Issue #29)
+def foo(x: int) -> int:
+ return x + 1
diff --git a/third_party/pep8/testsuite/support.py b/third_party/pep8/testsuite/support.py
new file mode 100644
index 00000000000..5185005750c
--- /dev/null
+++ b/third_party/pep8/testsuite/support.py
@@ -0,0 +1,197 @@
+# -*- coding: utf-8 -*-
+import os.path
+import re
+import sys
+
+from pep8 import Checker, BaseReport, StandardReport, readlines
+
+SELFTEST_REGEX = re.compile(r'\b(Okay|[EW]\d{3}):\s(.*)')
+ROOT_DIR = os.path.dirname(os.path.dirname(__file__))
+
+
+class PseudoFile(list):
+ """Simplified file interface."""
+ write = list.append
+
+ def getvalue(self):
+ return ''.join(self)
+
+
+class TestReport(StandardReport):
+ """Collect the results for the tests."""
+
+ def __init__(self, options):
+ options.benchmark_keys += ['test cases', 'failed tests']
+ super(TestReport, self).__init__(options)
+ self._verbose = options.verbose
+
+ def error(self, line_number, offset, text, check):
+ """Report an error, according to options."""
+ code = text[:4]
+ if code in self.counters:
+ self.counters[code] += 1
+ else:
+ self.counters[code] = 1
+ detailed_code = '%s:%s:%s' % (code, line_number, offset + 1)
+ # Don't care about expected errors or warnings
+ if code in self.expected or detailed_code in self.expected:
+ return
+ self._deferred_print.append(
+ (line_number, offset, detailed_code, text[5:], check.__doc__))
+ self.file_errors += 1
+ self.total_errors += 1
+ return code
+
+ def get_file_results(self):
+ # Check if the expected errors were found
+ label = '%s:%s:1' % (self.filename, self.line_offset)
+ for extended_code in self.expected:
+ code = extended_code.split(':')[0]
+ if not self.counters.get(code):
+ self.file_errors += 1
+ self.total_errors += 1
+ print('%s: error %s not found' % (label, extended_code))
+ else:
+ self.counters[code] -= 1
+ for code, extra in sorted(self.counters.items()):
+ if code not in self._benchmark_keys:
+ if extra and code in self.expected:
+ self.file_errors += 1
+ self.total_errors += 1
+ print('%s: error %s found too many times (+%d)' %
+ (label, code, extra))
+ # Reset counters
+ del self.counters[code]
+ if self._verbose and not self.file_errors:
+ print('%s: passed (%s)' %
+ (label, ' '.join(self.expected) or 'Okay'))
+ self.counters['test cases'] += 1
+ if self.file_errors:
+ self.counters['failed tests'] += 1
+ return super(TestReport, self).get_file_results()
+
+ def print_results(self):
+ results = ("%(physical lines)d lines tested: %(files)d files, "
+ "%(test cases)d test cases%%s." % self.counters)
+ if self.total_errors:
+ print(results % ", %s failures" % self.total_errors)
+ else:
+ print(results % "")
+ print("Test failed." if self.total_errors else "Test passed.")
+
+
+def selftest(options):
+ """
+ Test all check functions with test cases in docstrings.
+ """
+ count_failed = count_all = 0
+ report = BaseReport(options)
+ counters = report.counters
+ checks = options.physical_checks + options.logical_checks
+ for name, check, argument_names in checks:
+ for line in check.__doc__.splitlines():
+ line = line.lstrip()
+ match = SELFTEST_REGEX.match(line)
+ if match is None:
+ continue
+ code, source = match.groups()
+ lines = [part.replace(r'\t', '\t') + '\n'
+ for part in source.split(r'\n')]
+ checker = Checker(lines=lines, options=options, report=report)
+ checker.check_all()
+ error = None
+ if code == 'Okay':
+ if len(counters) > len(options.benchmark_keys):
+ codes = [key for key in counters
+ if key not in options.benchmark_keys]
+ error = "incorrectly found %s" % ', '.join(codes)
+ elif not counters.get(code):
+ error = "failed to find %s" % code
+ # Keep showing errors for multiple tests
+ for key in set(counters) - set(options.benchmark_keys):
+ del counters[key]
+ count_all += 1
+ if not error:
+ if options.verbose:
+ print("%s: %s" % (code, source))
+ else:
+ count_failed += 1
+ print("pep8.py: %s:" % error)
+ for line in checker.lines:
+ print(line.rstrip())
+ return count_failed, count_all
+
+
+def init_tests(pep8style):
+ """
+ Initialize testing framework.
+
+ A test file can provide many tests. Each test starts with a
+ declaration. This declaration is a single line starting with '#:'.
+ It declares codes of expected failures, separated by spaces or 'Okay'
+ if no failure is expected.
+ If the file does not contain such declaration, it should pass all
+ tests. If the declaration is empty, following lines are not checked,
+ until next declaration.
+
+ Examples:
+
+ * Only E224 and W701 are expected: #: E224 W701
+ * Following example is conform: #: Okay
+ * Don't check these lines: #:
+ """
+ report = pep8style.init_report(TestReport)
+ runner = pep8style.input_file
+
+ def run_tests(filename):
+ """Run all the tests from a file."""
+ lines = readlines(filename) + ['#:\n']
+ line_offset = 0
+ codes = ['Okay']
+ testcase = []
+ count_files = report.counters['files']
+ for index, line in enumerate(lines):
+ if not line.startswith('#:'):
+ if codes:
+ # Collect the lines of the test case
+ testcase.append(line)
+ continue
+ if codes and index:
+ if 'noeol' in codes:
+ testcase[-1] = testcase[-1].rstrip('\n')
+ codes = [c for c in codes
+ if c not in ('Okay', 'noeol')]
+ # Run the checker
+ runner(filename, testcase, expected=codes,
+ line_offset=line_offset)
+ # output the real line numbers
+ line_offset = index + 1
+ # configure the expected errors
+ codes = line.split()[1:]
+ # empty the test case buffer
+ del testcase[:]
+ report.counters['files'] = count_files + 1
+ return report.counters['failed tests']
+
+ pep8style.runner = run_tests
+
+
+def run_tests(style):
+ options = style.options
+ if options.doctest:
+ import doctest
+ fail_d, done_d = doctest.testmod(report=False, verbose=options.verbose)
+ fail_s, done_s = selftest(options)
+ count_failed = fail_s + fail_d
+ if not options.quiet:
+ count_passed = done_d + done_s - count_failed
+ print("%d passed and %d failed." % (count_passed, count_failed))
+ print("Test failed." if count_failed else "Test passed.")
+ if count_failed:
+ sys.exit(1)
+ if options.testsuite:
+ init_tests(style)
+ return style.check_files()
+
+# nose should not collect these functions
+init_tests.__test__ = run_tests.__test__ = False
diff --git a/third_party/pep8/testsuite/test_all.py b/third_party/pep8/testsuite/test_all.py
new file mode 100644
index 00000000000..50e2cb9fbde
--- /dev/null
+++ b/third_party/pep8/testsuite/test_all.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+import os.path
+import sys
+import unittest
+
+import pep8
+from testsuite.support import init_tests, selftest, ROOT_DIR
+
+# Note: please only use a subset of unittest methods which were present
+# in Python 2.5: assert(True|False|Equal|NotEqual|Raises)
+
+
+class Pep8TestCase(unittest.TestCase):
+ """Test the standard errors and warnings (E and W)."""
+
+ def setUp(self):
+ self._style = pep8.StyleGuide(
+ paths=[os.path.join(ROOT_DIR, 'testsuite')],
+ select='E,W', quiet=True)
+
+ def test_doctest(self):
+ import doctest
+ fail_d, done_d = doctest.testmod(pep8, verbose=False, report=False)
+ self.assertTrue(done_d, msg='tests not found')
+ self.assertFalse(fail_d, msg='%s failure(s)' % fail_d)
+
+ def test_selftest(self):
+ fail_s, done_s = selftest(self._style.options)
+ self.assertTrue(done_s, msg='tests not found')
+ self.assertFalse(fail_s, msg='%s failure(s)' % fail_s)
+
+ def test_checkers_testsuite(self):
+ init_tests(self._style)
+ report = self._style.check_files()
+ self.assertFalse(report.total_errors,
+ msg='%s failure(s)' % report.total_errors)
+
+ def test_own_dog_food(self):
+ files = [pep8.__file__.rstrip('oc'), __file__.rstrip('oc'),
+ os.path.join(ROOT_DIR, 'setup.py')]
+ report = self._style.init_report(pep8.StandardReport)
+ report = self._style.check_files(files)
+ self.assertFalse(report.total_errors,
+ msg='Failures: %s' % report.messages)
+
+
+def suite():
+ from testsuite import test_api, test_shell, test_util
+
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(Pep8TestCase))
+ suite.addTest(unittest.makeSuite(test_api.APITestCase))
+ suite.addTest(unittest.makeSuite(test_shell.ShellTestCase))
+ suite.addTest(unittest.makeSuite(test_util.UtilTestCase))
+ return suite
+
+
+def _main():
+ return unittest.TextTestRunner(verbosity=2).run(suite())
+
+if __name__ == '__main__':
+ sys.exit(not _main())
diff --git a/third_party/pep8/testsuite/test_api.py b/third_party/pep8/testsuite/test_api.py
new file mode 100644
index 00000000000..341fb34bbf9
--- /dev/null
+++ b/third_party/pep8/testsuite/test_api.py
@@ -0,0 +1,389 @@
+# -*- coding: utf-8 -*-
+import os.path
+import shlex
+import sys
+import unittest
+
+import pep8
+from testsuite.support import ROOT_DIR, PseudoFile
+
+E11 = os.path.join(ROOT_DIR, 'testsuite', 'E11.py')
+
+
+class DummyChecker(object):
+ def __init__(self, tree, filename):
+ pass
+
+ def run(self):
+ if False:
+ yield
+
+
+class APITestCase(unittest.TestCase):
+ """Test the public methods."""
+
+ def setUp(self):
+ self._saved_stdout = sys.stdout
+ self._saved_stderr = sys.stderr
+ self._saved_checks = pep8._checks
+ sys.stdout = PseudoFile()
+ sys.stderr = PseudoFile()
+ pep8._checks = dict((k, dict((f, (vals[0][:], vals[1]))
+ for (f, vals) in v.items()))
+ for (k, v) in self._saved_checks.items())
+
+ def tearDown(self):
+ sys.stdout = self._saved_stdout
+ sys.stderr = self._saved_stderr
+ pep8._checks = self._saved_checks
+
+ def reset(self):
+ del sys.stdout[:], sys.stderr[:]
+
+ def test_register_physical_check(self):
+ def check_dummy(physical_line, line_number):
+ if False:
+ yield
+ pep8.register_check(check_dummy, ['Z001'])
+
+ self.assertTrue(check_dummy in pep8._checks['physical_line'])
+ codes, args = pep8._checks['physical_line'][check_dummy]
+ self.assertTrue('Z001' in codes)
+ self.assertEqual(args, ['physical_line', 'line_number'])
+
+ options = pep8.StyleGuide().options
+ self.assertTrue(any(func == check_dummy
+ for name, func, args in options.physical_checks))
+
+ def test_register_logical_check(self):
+ def check_dummy(logical_line, tokens):
+ if False:
+ yield
+ pep8.register_check(check_dummy, ['Z401'])
+
+ self.assertTrue(check_dummy in pep8._checks['logical_line'])
+ codes, args = pep8._checks['logical_line'][check_dummy]
+ self.assertTrue('Z401' in codes)
+ self.assertEqual(args, ['logical_line', 'tokens'])
+
+ pep8.register_check(check_dummy, [])
+ pep8.register_check(check_dummy, ['Z402', 'Z403'])
+ codes, args = pep8._checks['logical_line'][check_dummy]
+ self.assertEqual(codes, ['Z401', 'Z402', 'Z403'])
+ self.assertEqual(args, ['logical_line', 'tokens'])
+
+ options = pep8.StyleGuide().options
+ self.assertTrue(any(func == check_dummy
+ for name, func, args in options.logical_checks))
+
+ def test_register_ast_check(self):
+ pep8.register_check(DummyChecker, ['Z701'])
+
+ self.assertTrue(DummyChecker in pep8._checks['tree'])
+ codes, args = pep8._checks['tree'][DummyChecker]
+ self.assertTrue('Z701' in codes)
+ self.assertTrue(args is None)
+
+ options = pep8.StyleGuide().options
+ self.assertTrue(any(cls == DummyChecker
+ for name, cls, args in options.ast_checks))
+
+ def test_register_invalid_check(self):
+ class InvalidChecker(DummyChecker):
+ def __init__(self, filename):
+ pass
+
+ def check_dummy(logical, tokens):
+ if False:
+ yield
+ pep8.register_check(InvalidChecker, ['Z741'])
+ pep8.register_check(check_dummy, ['Z441'])
+
+ for checkers in pep8._checks.values():
+ self.assertTrue(DummyChecker not in checkers)
+ self.assertTrue(check_dummy not in checkers)
+
+ self.assertRaises(TypeError, pep8.register_check)
+
+ def test_styleguide(self):
+ report = pep8.StyleGuide().check_files()
+ self.assertEqual(report.total_errors, 0)
+ self.assertFalse(sys.stdout)
+ self.assertFalse(sys.stderr)
+ self.reset()
+
+ report = pep8.StyleGuide().check_files(['missing-file'])
+ stdout = sys.stdout.getvalue().splitlines()
+ self.assertEqual(len(stdout), report.total_errors)
+ self.assertEqual(report.total_errors, 1)
+ # < 3.3 returns IOError; >= 3.3 returns FileNotFoundError
+ self.assertTrue(stdout[0].startswith("missing-file:1:1: E902 "))
+ self.assertFalse(sys.stderr)
+ self.reset()
+
+ report = pep8.StyleGuide().check_files([E11])
+ stdout = sys.stdout.getvalue().splitlines()
+ self.assertEqual(len(stdout), report.total_errors)
+ self.assertEqual(report.total_errors, 17)
+ self.assertFalse(sys.stderr)
+ self.reset()
+
+ # Passing the paths in the constructor gives same result
+ report = pep8.StyleGuide(paths=[E11]).check_files()
+ stdout = sys.stdout.getvalue().splitlines()
+ self.assertEqual(len(stdout), report.total_errors)
+ self.assertEqual(report.total_errors, 17)
+ self.assertFalse(sys.stderr)
+ self.reset()
+
+ def test_styleguide_options(self):
+ # Instanciate a simple checker
+ pep8style = pep8.StyleGuide(paths=[E11])
+
+ # Check style's attributes
+ self.assertEqual(pep8style.checker_class, pep8.Checker)
+ self.assertEqual(pep8style.paths, [E11])
+ self.assertEqual(pep8style.runner, pep8style.input_file)
+ self.assertEqual(pep8style.options.ignore_code, pep8style.ignore_code)
+ self.assertEqual(pep8style.options.paths, pep8style.paths)
+
+ # Check unset options
+ for o in ('benchmark', 'config', 'count', 'diff',
+ 'doctest', 'quiet', 'show_pep8', 'show_source',
+ 'statistics', 'testsuite', 'verbose'):
+ oval = getattr(pep8style.options, o)
+ self.assertTrue(oval in (None, False), msg='%s = %r' % (o, oval))
+
+ # Check default options
+ self.assertTrue(pep8style.options.repeat)
+ self.assertEqual(pep8style.options.benchmark_keys,
+ ['directories', 'files',
+ 'logical lines', 'physical lines'])
+ self.assertEqual(pep8style.options.exclude,
+ ['.svn', 'CVS', '.bzr', '.hg',
+ '.git', '__pycache__', '.tox'])
+ self.assertEqual(pep8style.options.filename, ['*.py'])
+ self.assertEqual(pep8style.options.format, 'default')
+ self.assertEqual(pep8style.options.select, ())
+ self.assertEqual(pep8style.options.ignore, ('E226', 'E24'))
+ self.assertEqual(pep8style.options.max_line_length, 79)
+
+ def test_styleguide_ignore_code(self):
+ def parse_argv(argstring):
+ _saved_argv = sys.argv
+ sys.argv = shlex.split('pep8 %s /dev/null' % argstring)
+ try:
+ return pep8.StyleGuide(parse_argv=True)
+ finally:
+ sys.argv = _saved_argv
+
+ options = parse_argv('').options
+ self.assertEqual(options.select, ())
+ self.assertEqual(
+ options.ignore,
+ ('E121', 'E123', 'E126', 'E226', 'E24', 'E704')
+ )
+
+ options = parse_argv('--doctest').options
+ self.assertEqual(options.select, ())
+ self.assertEqual(options.ignore, ())
+
+ options = parse_argv('--ignore E,W').options
+ self.assertEqual(options.select, ())
+ self.assertEqual(options.ignore, ('E', 'W'))
+
+ options = parse_argv('--select E,W').options
+ self.assertEqual(options.select, ('E', 'W'))
+ self.assertEqual(options.ignore, ('',))
+
+ options = parse_argv('--select E --ignore E24').options
+ self.assertEqual(options.select, ('E',))
+ self.assertEqual(options.ignore, ('',))
+
+ options = parse_argv('--ignore E --select E24').options
+ self.assertEqual(options.select, ('E24',))
+ self.assertEqual(options.ignore, ('',))
+
+ options = parse_argv('--ignore W --select E24').options
+ self.assertEqual(options.select, ('E24',))
+ self.assertEqual(options.ignore, ('',))
+
+ pep8style = pep8.StyleGuide(paths=[E11])
+ self.assertFalse(pep8style.ignore_code('E112'))
+ self.assertFalse(pep8style.ignore_code('W191'))
+ self.assertTrue(pep8style.ignore_code('E241'))
+
+ pep8style = pep8.StyleGuide(select='E', paths=[E11])
+ self.assertFalse(pep8style.ignore_code('E112'))
+ self.assertTrue(pep8style.ignore_code('W191'))
+ self.assertFalse(pep8style.ignore_code('E241'))
+
+ pep8style = pep8.StyleGuide(select='W', paths=[E11])
+ self.assertTrue(pep8style.ignore_code('E112'))
+ self.assertFalse(pep8style.ignore_code('W191'))
+ self.assertTrue(pep8style.ignore_code('E241'))
+
+ pep8style = pep8.StyleGuide(select=('F401',), paths=[E11])
+ self.assertEqual(pep8style.options.select, ('F401',))
+ self.assertEqual(pep8style.options.ignore, ('',))
+ self.assertFalse(pep8style.ignore_code('F'))
+ self.assertFalse(pep8style.ignore_code('F401'))
+ self.assertTrue(pep8style.ignore_code('F402'))
+
+ def test_styleguide_excluded(self):
+ pep8style = pep8.StyleGuide(paths=[E11])
+
+ self.assertFalse(pep8style.excluded('./foo/bar'))
+ self.assertFalse(pep8style.excluded('./foo/bar/main.py'))
+
+ self.assertTrue(pep8style.excluded('./CVS'))
+ self.assertTrue(pep8style.excluded('./.tox'))
+ self.assertTrue(pep8style.excluded('./subdir/CVS'))
+ self.assertTrue(pep8style.excluded('__pycache__'))
+ self.assertTrue(pep8style.excluded('./__pycache__'))
+ self.assertTrue(pep8style.excluded('subdir/__pycache__'))
+
+ self.assertFalse(pep8style.excluded('draftCVS'))
+ self.assertFalse(pep8style.excluded('./CVSoup'))
+ self.assertFalse(pep8style.excluded('./CVS/subdir'))
+
+ def test_styleguide_checks(self):
+ pep8style = pep8.StyleGuide(paths=[E11])
+
+ # Default lists of checkers
+ self.assertTrue(len(pep8style.options.physical_checks) > 4)
+ self.assertTrue(len(pep8style.options.logical_checks) > 10)
+ self.assertEqual(len(pep8style.options.ast_checks), 0)
+
+ # Sanity check
+ for name, check, args in pep8style.options.physical_checks:
+ self.assertEqual(check.__name__, name)
+ self.assertEqual(args[0], 'physical_line')
+ for name, check, args in pep8style.options.logical_checks:
+ self.assertEqual(check.__name__, name)
+ self.assertEqual(args[0], 'logical_line')
+
+ # Do run E11 checks
+ options = pep8.StyleGuide().options
+ self.assertTrue(any(func == pep8.indentation
+ for name, func, args in options.logical_checks))
+ options = pep8.StyleGuide(select=['E']).options
+ self.assertTrue(any(func == pep8.indentation
+ for name, func, args in options.logical_checks))
+ options = pep8.StyleGuide(ignore=['W']).options
+ self.assertTrue(any(func == pep8.indentation
+ for name, func, args in options.logical_checks))
+ options = pep8.StyleGuide(ignore=['E12']).options
+ self.assertTrue(any(func == pep8.indentation
+ for name, func, args in options.logical_checks))
+
+ # Do not run E11 checks
+ options = pep8.StyleGuide(select=['W']).options
+ self.assertFalse(any(func == pep8.indentation
+ for name, func, args in options.logical_checks))
+ options = pep8.StyleGuide(ignore=['E']).options
+ self.assertFalse(any(func == pep8.indentation
+ for name, func, args in options.logical_checks))
+ options = pep8.StyleGuide(ignore=['E11']).options
+ self.assertFalse(any(func == pep8.indentation
+ for name, func, args in options.logical_checks))
+
+ def test_styleguide_init_report(self):
+ pep8style = pep8.StyleGuide(paths=[E11])
+
+ self.assertEqual(pep8style.options.reporter, pep8.StandardReport)
+ self.assertEqual(type(pep8style.options.report), pep8.StandardReport)
+
+ class MinorityReport(pep8.BaseReport):
+ pass
+
+ report = pep8style.init_report(MinorityReport)
+ self.assertEqual(pep8style.options.report, report)
+ self.assertEqual(type(report), MinorityReport)
+
+ pep8style = pep8.StyleGuide(paths=[E11], reporter=MinorityReport)
+ self.assertEqual(type(pep8style.options.report), MinorityReport)
+ self.assertEqual(pep8style.options.reporter, MinorityReport)
+
+ def test_styleguide_check_files(self):
+ pep8style = pep8.StyleGuide(paths=[E11])
+
+ report = pep8style.check_files()
+ self.assertTrue(report.total_errors)
+
+ self.assertRaises(TypeError, pep8style.check_files, 42)
+ # < 3.3 raises TypeError; >= 3.3 raises AttributeError
+ self.assertRaises(Exception, pep8style.check_files, [42])
+
+ def test_check_unicode(self):
+ # Do not crash if lines are Unicode (Python 2.x)
+ pep8.register_check(DummyChecker, ['Z701'])
+ source = '#\n'
+ if hasattr(source, 'decode'):
+ source = source.decode('ascii')
+
+ pep8style = pep8.StyleGuide()
+ count_errors = pep8style.input_file('stdin', lines=[source])
+
+ self.assertFalse(sys.stdout)
+ self.assertFalse(sys.stderr)
+ self.assertEqual(count_errors, 0)
+
+ def test_check_nullbytes(self):
+ pep8.register_check(DummyChecker, ['Z701'])
+
+ pep8style = pep8.StyleGuide()
+ count_errors = pep8style.input_file('stdin', lines=['\x00\n'])
+
+ stdout = sys.stdout.getvalue()
+ if 'SyntaxError' in stdout:
+ # PyPy 2.2 returns a SyntaxError
+ expected = "stdin:1:2: E901 SyntaxError"
+ else:
+ expected = "stdin:1:1: E901 TypeError"
+ self.assertTrue(stdout.startswith(expected),
+ msg='Output %r does not start with %r' %
+ (stdout, expected))
+ self.assertFalse(sys.stderr)
+ self.assertEqual(count_errors, 1)
+
+ def test_styleguide_unmatched_triple_quotes(self):
+ pep8.register_check(DummyChecker, ['Z701'])
+ lines = [
+ 'def foo():\n',
+ ' """test docstring""\'\n',
+ ]
+
+ pep8style = pep8.StyleGuide()
+ pep8style.input_file('stdin', lines=lines)
+ stdout = sys.stdout.getvalue()
+
+ expected = 'stdin:2:5: E901 TokenError: EOF in multi-line string'
+ self.assertTrue(expected in stdout)
+
+ def test_styleguide_continuation_line_outdented(self):
+ pep8.register_check(DummyChecker, ['Z701'])
+ lines = [
+ 'def foo():\n',
+ ' pass\n',
+ '\n',
+ '\\\n',
+ '\n',
+ 'def bar():\n',
+ ' pass\n',
+ ]
+
+ pep8style = pep8.StyleGuide()
+ count_errors = pep8style.input_file('stdin', lines=lines)
+ self.assertEqual(count_errors, 2)
+ stdout = sys.stdout.getvalue()
+ expected = (
+ 'stdin:6:1: '
+ 'E122 continuation line missing indentation or outdented'
+ )
+ self.assertTrue(expected in stdout)
+ expected = 'stdin:6:1: E302 expected 2 blank lines, found 1'
+ self.assertTrue(expected in stdout)
+
+ # TODO: runner
+ # TODO: input_file
diff --git a/third_party/pep8/testsuite/test_shell.py b/third_party/pep8/testsuite/test_shell.py
new file mode 100644
index 00000000000..e536852f1b8
--- /dev/null
+++ b/third_party/pep8/testsuite/test_shell.py
@@ -0,0 +1,189 @@
+# -*- coding: utf-8 -*-
+import os.path
+import sys
+import unittest
+
+import pep8
+from testsuite.support import ROOT_DIR, PseudoFile
+
+
+class ShellTestCase(unittest.TestCase):
+ """Test the usual CLI options and output."""
+
+ def setUp(self):
+ self._saved_argv = sys.argv
+ self._saved_stdout = sys.stdout
+ self._saved_stderr = sys.stderr
+ self._saved_pconfig = pep8.PROJECT_CONFIG
+ self._saved_cpread = pep8.RawConfigParser._read
+ self._saved_stdin_get_value = pep8.stdin_get_value
+ self._config_filenames = []
+ self.stdin = ''
+ sys.argv = ['pep8']
+ sys.stdout = PseudoFile()
+ sys.stderr = PseudoFile()
+
+ def fake_config_parser_read(cp, fp, filename):
+ self._config_filenames.append(filename)
+ pep8.RawConfigParser._read = fake_config_parser_read
+ pep8.stdin_get_value = self.stdin_get_value
+
+ def tearDown(self):
+ sys.argv = self._saved_argv
+ sys.stdout = self._saved_stdout
+ sys.stderr = self._saved_stderr
+ pep8.PROJECT_CONFIG = self._saved_pconfig
+ pep8.RawConfigParser._read = self._saved_cpread
+ pep8.stdin_get_value = self._saved_stdin_get_value
+
+ def stdin_get_value(self):
+ return self.stdin
+
+ def pep8(self, *args):
+ del sys.stdout[:], sys.stderr[:]
+ sys.argv[1:] = args
+ try:
+ pep8._main()
+ errorcode = None
+ except SystemExit:
+ errorcode = sys.exc_info()[1].code
+ return sys.stdout.getvalue(), sys.stderr.getvalue(), errorcode
+
+ def test_print_usage(self):
+ stdout, stderr, errcode = self.pep8('--help')
+ self.assertFalse(errcode)
+ self.assertFalse(stderr)
+ self.assertTrue(stdout.startswith("Usage: pep8 [options] input"))
+
+ stdout, stderr, errcode = self.pep8('--version')
+ self.assertFalse(errcode)
+ self.assertFalse(stderr)
+ self.assertEqual(stdout.count('\n'), 1)
+
+ stdout, stderr, errcode = self.pep8('--obfuscated')
+ self.assertEqual(errcode, 2)
+ self.assertEqual(stderr.splitlines(),
+ ["Usage: pep8 [options] input ...", "",
+ "pep8: error: no such option: --obfuscated"])
+ self.assertFalse(stdout)
+
+ self.assertFalse(self._config_filenames)
+
+ def test_check_simple(self):
+ E11 = os.path.join(ROOT_DIR, 'testsuite', 'E11.py')
+ stdout, stderr, errcode = self.pep8(E11)
+ stdout = stdout.splitlines()
+ self.assertEqual(errcode, 1)
+ self.assertFalse(stderr)
+ self.assertEqual(len(stdout), 17)
+ for line, num, col in zip(stdout, (3, 6, 9, 12), (3, 6, 1, 5)):
+ path, x, y, msg = line.split(':')
+ self.assertTrue(path.endswith(E11))
+ self.assertEqual(x, str(num))
+ self.assertEqual(y, str(col))
+ self.assertTrue(msg.startswith(' E11'))
+ # Config file read from the pep8's setup.cfg
+ config_filenames = [os.path.basename(p)
+ for p in self._config_filenames]
+ self.assertTrue('setup.cfg' in config_filenames)
+
+ def test_check_stdin(self):
+ pep8.PROJECT_CONFIG = ()
+ stdout, stderr, errcode = self.pep8('-')
+ self.assertFalse(errcode)
+ self.assertFalse(stderr)
+ self.assertFalse(stdout)
+
+ self.stdin = 'import os, sys\n'
+ stdout, stderr, errcode = self.pep8('-')
+ stdout = stdout.splitlines()
+ self.assertEqual(errcode, 1)
+ self.assertFalse(stderr)
+ self.assertEqual(stdout,
+ ['stdin:1:10: E401 multiple imports on one line'])
+
+ def test_check_non_existent(self):
+ self.stdin = 'import os, sys\n'
+ stdout, stderr, errcode = self.pep8('fictitious.py')
+ self.assertEqual(errcode, 1)
+ self.assertFalse(stderr)
+ self.assertTrue(stdout.startswith('fictitious.py:1:1: E902 '))
+
+ def test_check_noarg(self):
+ # issue #170: do not read stdin by default
+ pep8.PROJECT_CONFIG = ()
+ stdout, stderr, errcode = self.pep8()
+ self.assertEqual(errcode, 2)
+ self.assertEqual(stderr.splitlines(),
+ ["Usage: pep8 [options] input ...", "",
+ "pep8: error: input not specified"])
+ self.assertFalse(self._config_filenames)
+
+ def test_check_diff(self):
+ pep8.PROJECT_CONFIG = ()
+ diff_lines = [
+ "--- testsuite/E11.py 2006-06-01 08:49:50 +0500",
+ "+++ testsuite/E11.py 2008-04-06 17:36:29 +0500",
+ "@@ -2,4 +2,7 @@",
+ " if x > 2:",
+ " print x",
+ "+#: E111",
+ "+if True:",
+ "+ print",
+ " #: E112",
+ " if False:",
+ "",
+ ]
+
+ self.stdin = '\n'.join(diff_lines)
+ stdout, stderr, errcode = self.pep8('--diff')
+ stdout = stdout.splitlines()
+ self.assertEqual(errcode, 1)
+ self.assertFalse(stderr)
+ for line, num, col in zip(stdout, (3, 6), (3, 6)):
+ path, x, y, msg = line.split(':')
+ self.assertEqual(x, str(num))
+ self.assertEqual(y, str(col))
+ self.assertTrue(msg.startswith(' E11'))
+
+ diff_lines[:2] = ["--- a/testsuite/E11.py 2006-06-01 08:49 +0400",
+ "+++ b/testsuite/E11.py 2008-04-06 17:36 +0400"]
+ self.stdin = '\n'.join(diff_lines)
+ stdout, stderr, errcode = self.pep8('--diff')
+ stdout = stdout.splitlines()
+ self.assertEqual(errcode, 1)
+ self.assertFalse(stderr)
+ for line, num, col in zip(stdout, (3, 6), (3, 6)):
+ path, x, y, msg = line.split(':')
+ self.assertEqual(x, str(num))
+ self.assertEqual(y, str(col))
+ self.assertTrue(msg.startswith(' E11'))
+
+ # issue #127, #137: one-line chunks
+ diff_lines[:-1] = ["diff --git a/testsuite/E11.py b/testsuite/E11.py",
+ "index 8735e25..2ecb529 100644",
+ "--- a/testsuite/E11.py",
+ "+++ b/testsuite/E11.py",
+ "@@ -5,0 +6 @@ if True:",
+ "+ print"]
+ self.stdin = '\n'.join(diff_lines)
+ stdout, stderr, errcode = self.pep8('--diff')
+ (stdout,) = stdout.splitlines()
+ self.assertEqual(errcode, 1)
+ self.assertFalse(stderr)
+ self.assertTrue('testsuite/E11.py:6:6: E111 ' in stdout)
+
+ # missing '--diff'
+ self.stdin = '\n'.join(diff_lines)
+ stdout, stderr, errcode = self.pep8()
+ self.assertEqual(errcode, 2)
+ self.assertFalse(stdout)
+ self.assertTrue(stderr.startswith('Usage: pep8 [options] input ...'))
+
+ # no matching file in the diff
+ diff_lines[3] = "+++ b/testsuite/lost/E11.py"
+ self.stdin = '\n'.join(diff_lines)
+ stdout, stderr, errcode = self.pep8('--diff')
+ self.assertFalse(errcode)
+ self.assertFalse(stdout)
+ self.assertFalse(stderr)
diff --git a/third_party/pep8/testsuite/test_util.py b/third_party/pep8/testsuite/test_util.py
new file mode 100644
index 00000000000..11395ccaa3d
--- /dev/null
+++ b/third_party/pep8/testsuite/test_util.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+import os
+import unittest
+
+import pep8
+
+
+class UtilTestCase(unittest.TestCase):
+ def test_normalize_paths(self):
+ cwd = os.getcwd()
+
+ self.assertEqual(pep8.normalize_paths(''), [])
+ self.assertEqual(pep8.normalize_paths([]), [])
+ self.assertEqual(pep8.normalize_paths(None), [])
+ self.assertEqual(pep8.normalize_paths(['foo']), ['foo'])
+ self.assertEqual(pep8.normalize_paths('foo'), ['foo'])
+ self.assertEqual(pep8.normalize_paths('foo,bar'), ['foo', 'bar'])
+ self.assertEqual(pep8.normalize_paths('foo, bar '), ['foo', 'bar'])
+ self.assertEqual(pep8.normalize_paths('/foo/bar,baz/../bat'),
+ ['/foo/bar', cwd + '/bat'])
+ self.assertEqual(pep8.normalize_paths(".pyc,\n build/*"),
+ ['.pyc', cwd + '/build/*'])
diff --git a/third_party/pep8/testsuite/utf-8-bom.py b/third_party/pep8/testsuite/utf-8-bom.py
new file mode 100644
index 00000000000..9c065c9494e
--- /dev/null
+++ b/third_party/pep8/testsuite/utf-8-bom.py
@@ -0,0 +1,6 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+hello = 'こんにちわ'
+
+# EOF
diff --git a/third_party/pep8/testsuite/utf-8.py b/third_party/pep8/testsuite/utf-8.py
new file mode 100644
index 00000000000..2cee57942f8
--- /dev/null
+++ b/third_party/pep8/testsuite/utf-8.py
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+
+
+class Rectangle(Blob):
+
+ def __init__(self, width, height,
+ color='black', emphasis=None, highlight=0):
+ if width == 0 and height == 0 and \
+ color == 'red' and emphasis == 'strong' or \
+ highlight > 100:
+ raise ValueError("sorry, you lose")
+ if width == 0 and height == 0 and (color == 'red' or
+ emphasis is None):
+ raise ValueError("I don't think so -- values are %s, %s" %
+ (width, height))
+ Blob.__init__(self, width, height,
+ color, emphasis, highlight)
+
+
+# Some random text with multi-byte characters (utf-8 encoded)
+#
+# Εδώ μάτσο κειμένων τη, τρόπο πιθανό διευθυντές ώρα μη. Νέων απλό παράγει ροή
+# κι, το επί δεδομένη καθορίζουν. Πάντως ζητήσεις περιβάλλοντος ένα με, τη
+# ξέχασε αρπάζεις φαινόμενο όλη. Τρέξει εσφαλμένη χρησιμοποίησέ νέα τι. Θα όρο
+# πετάνε φακέλους, άρα με διακοπής λαμβάνουν εφαμοργής. Λες κι μειώσει
+# καθυστερεί.
+
+# 79 narrow chars
+# 01 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 [79]
+
+# 78 narrow chars (Na) + 1 wide char (W)
+# 01 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8情
+
+# 3 narrow chars (Na) + 40 wide chars (W)
+# 情 情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情
+
+# 3 narrow chars (Na) + 76 wide chars (W)
+# 情 情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情
+
+#
+#: E501
+# 80 narrow chars (Na)
+# 01 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 [80]
+#
+#: E501
+# 78 narrow chars (Na) + 2 wide char (W)
+# 01 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8情情
+#
+#: E501
+# 3 narrow chars (Na) + 77 wide chars (W)
+# 情 情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情情
+#