flake8/tests/unit/test_file_checker.py
Lukasz Langa 01c0c648e1 Only require Mock on Python 3.4 and older. Use the builtin one elsewhere.
Mock 2.0 is using pbr which is hostile to environments without network access.
It's not required on Python 3.5+ so I made it possible to use `unittest.mock`
on this version.

Updated tox.ini to reflect this. Tested with 2.7.11, 3.3.6, 3.4.5, and 3.5.2 on
macOS 10.12.1 with tox and pyenv.
2016-11-27 15:13:30 -08:00

28 lines
888 B
Python

"""Unit tests for the FileChecker class."""
try:
import mock
except ImportError:
from unittest import mock
from flake8 import checker
@mock.patch('flake8.processor.FileProcessor')
def test_run_ast_checks_handles_SyntaxErrors(FileProcessor):
"""Stress our SyntaxError handling.
Related to: https://gitlab.com/pycqa/flake8/issues/237
"""
processor = mock.Mock(lines=[])
FileProcessor.return_value = processor
processor.build_ast.side_effect = SyntaxError('Failed to build ast',
('', 1, 5, 'foo(\n'))
file_checker = checker.FileChecker(__file__, checks={}, options=object())
with mock.patch.object(file_checker, 'report') as report:
file_checker.run_ast_checks()
report.assert_called_once_with(
'E999', 1, 3,
'SyntaxError: Failed to build ast',
)