File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,8 @@ Bug fixes:
2626
2727* Update ``--format`` documentation. (Issue #198 / Pull Request #310)
2828
29+ * Don't crash if Checker.build_tokens_line() returns None. (Issue #306)
30+
2931
30321.5.7 (2014-05-29)
3133------------------
Original file line number Diff line number Diff line change @@ -1346,6 +1346,10 @@ def check_logical(self):
13461346 """Build a line from tokens and run all logical checks on it."""
13471347 self .report .increment_logical_line ()
13481348 mapping = self .build_tokens_line ()
1349+
1350+ if not mapping :
1351+ return
1352+
13491353 (start_row , start_col ) = mapping [0 ][1 ]
13501354 start_line = self .lines [start_row - 1 ]
13511355 self .indent_level = expand_indent (start_line [:start_col ])
Original file line number Diff line number Diff line change @@ -342,5 +342,43 @@ def test_check_nullbytes(self):
342342 self .assertFalse (sys .stderr )
343343 self .assertEqual (count_errors , 1 )
344344
345+ def test_styleguide_unmatched_triple_quotes (self ):
346+ pep8 .register_check (DummyChecker , ['Z701' ])
347+ lines = [
348+ 'def foo():\n ' ,
349+ ' """test docstring""\' \n ' ,
350+ ]
351+
352+ pep8style = pep8 .StyleGuide ()
353+ pep8style .input_file ('stdin' , lines = lines )
354+ stdout = sys .stdout .getvalue ()
355+
356+ expected = 'stdin:2:5: E901 TokenError: EOF in multi-line string'
357+ self .assertTrue (expected in stdout )
358+
359+ def test_styleguide_continuation_line_outdented (self ):
360+ pep8 .register_check (DummyChecker , ['Z701' ])
361+ lines = [
362+ 'def foo():\n ' ,
363+ ' pass\n ' ,
364+ '\n ' ,
365+ '\\ \n ' ,
366+ '\n ' ,
367+ 'def bar():\n ' ,
368+ ' pass\n ' ,
369+ ]
370+
371+ pep8style = pep8 .StyleGuide ()
372+ count_errors = pep8style .input_file ('stdin' , lines = lines )
373+ self .assertEqual (count_errors , 2 )
374+ stdout = sys .stdout .getvalue ()
375+ expected = (
376+ 'stdin:6:1: '
377+ 'E122 continuation line missing indentation or outdented'
378+ )
379+ self .assertTrue (expected in stdout )
380+ expected = 'stdin:6:1: E302 expected 2 blank lines, found 1'
381+ self .assertTrue (expected in stdout )
382+
345383 # TODO: runner
346384 # TODO: input_file
You can’t perform that action at this time.
0 commit comments