mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-02 03:46:53 +00:00
Merge branch 'issue-662' into 'master'
processor: Catch SyntaxError also when generating tokens for a file Closes #662 See merge request pycqa/flake8!433
This commit is contained in:
commit
94304de684
2 changed files with 12 additions and 1 deletions
|
|
@ -125,7 +125,7 @@ class FileProcessor(object):
|
|||
self._file_tokens = list(
|
||||
tokenize.generate_tokens(lambda: next(line_iter))
|
||||
)
|
||||
except tokenize.TokenError as exc:
|
||||
except (tokenize.TokenError, SyntaxError) as exc:
|
||||
raise exceptions.InvalidSyntax(exception=exc)
|
||||
|
||||
return self._file_tokens
|
||||
|
|
|
|||
|
|
@ -162,6 +162,17 @@ def test_tokenization_error_but_not_syntax_error(tmpdir, capsys):
|
|||
assert err == ''
|
||||
|
||||
|
||||
def test_tokenization_error_is_a_syntax_error(tmpdir, capsys):
|
||||
"""Test when tokenize raises a SyntaxError."""
|
||||
with tmpdir.as_cwd():
|
||||
tmpdir.join('t.py').write('if True:\n pass\n pass\n')
|
||||
_call_main(['t.py'], retv=1)
|
||||
|
||||
out, err = capsys.readouterr()
|
||||
assert out == 't.py:1:1: E902 IndentationError: unindent does not match any outer indentation level\n' # noqa: E501
|
||||
assert err == ''
|
||||
|
||||
|
||||
def test_bug_report_successful(capsys):
|
||||
"""Test that --bug-report does not crash."""
|
||||
_call_main(['--bug-report'])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue