summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lee <IanLee1521@gmail.com>2014-12-13 19:47:23 -0800
committerIan Lee <IanLee1521@gmail.com>2014-12-13 19:47:23 -0800
commit79c1fb7b0efcc38dfa42265ee6769eaaf252d551 (patch)
tree629f6d6d29140ad8729d850ecf23890b8ce7d34e
parent9ccac78662eacd56963f9b08cf7c33fa7ef36947 (diff)
parent866619420158180a1e44de1eeb35c01a5d1a5902 (diff)
downloadpep8-79c1fb7b0efcc38dfa42265ee6769eaaf252d551.tar.gz
Merge branch 'issue306'
-rw-r--r--CHANGES.txt2
-rwxr-xr-xpep8.py4
-rw-r--r--testsuite/test_api.py38
3 files changed, 44 insertions, 0 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index fc4f984..72072ca 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -26,6 +26,8 @@ Bug fixes:
* Update ``--format`` documentation. (Issue #198 / Pull Request #310)
+* Don't crash if Checker.build_tokens_line() returns None. (Issue #306)
+
1.5.7 (2014-05-29)
------------------
diff --git a/pep8.py b/pep8.py
index d638388..0fbe22d 100755
--- a/pep8.py
+++ b/pep8.py
@@ -1346,6 +1346,10 @@ class Checker(object):
"""Build a line from tokens and run all logical checks on it."""
self.report.increment_logical_line()
mapping = self.build_tokens_line()
+
+ if not mapping:
+ return
+
(start_row, start_col) = mapping[0][1]
start_line = self.lines[start_row - 1]
self.indent_level = expand_indent(start_line[:start_col])
diff --git a/testsuite/test_api.py b/testsuite/test_api.py
index 672f202..f38b101 100644
--- a/testsuite/test_api.py
+++ b/testsuite/test_api.py
@@ -342,5 +342,43 @@ class APITestCase(unittest.TestCase):
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