mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-14 08:24:46 +00:00
Handle empty stdin-display-name values
Apparently, some folks pass an empty string to --stdin-display-name. To avoid the errors this causes, we need to handle it appropriately. Closes #235
This commit is contained in:
parent
185a073c29
commit
352a7250b7
2 changed files with 13 additions and 1 deletions
|
|
@ -288,7 +288,7 @@ class FileProcessor(object):
|
||||||
# type: () -> List[str]
|
# type: () -> List[str]
|
||||||
"""Read the lines for this file checker."""
|
"""Read the lines for this file checker."""
|
||||||
if self.filename is None or self.filename == '-':
|
if self.filename is None or self.filename == '-':
|
||||||
self.filename = self.options.stdin_display_name
|
self.filename = self.options.stdin_display_name or 'stdin'
|
||||||
lines = self.read_lines_from_stdin()
|
lines = self.read_lines_from_stdin()
|
||||||
else:
|
else:
|
||||||
lines = self.read_lines_from_filename()
|
lines = self.read_lines_from_filename()
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,18 @@ def test_read_lines_uses_display_name(stdin_get_value):
|
||||||
assert file_processor.filename == 'display_name.py'
|
assert file_processor.filename == 'display_name.py'
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch('flake8.utils.stdin_get_value')
|
||||||
|
def test_read_lines_ignores_empty_display_name(stdin_get_value):
|
||||||
|
"""Verify that when processing stdin we use a display name if present."""
|
||||||
|
stdin_value = mock.Mock()
|
||||||
|
stdin_value.splitlines.return_value = []
|
||||||
|
stdin_get_value.return_value = stdin_value
|
||||||
|
file_processor = processor.FileProcessor('-', options_from(
|
||||||
|
stdin_display_name=''
|
||||||
|
))
|
||||||
|
assert file_processor.filename == 'stdin'
|
||||||
|
|
||||||
|
|
||||||
def test_line_for():
|
def test_line_for():
|
||||||
"""Verify we grab the correct line from the cached lines."""
|
"""Verify we grab the correct line from the cached lines."""
|
||||||
file_processor = processor.FileProcessor('-', options_from(), lines=[
|
file_processor = processor.FileProcessor('-', options_from(), lines=[
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue