summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2020-01-16 14:06:37 -0800
committerAnthony Sottile <asottile@umich.edu>2020-01-16 14:10:33 -0800
commit32c7ebcd7b527a70e96906e3d995ab79a5c39464 (patch)
treed0c64c175a230767361002e651f631da716c2887 /tests
parentb56c88fe654af09161a66bf81e00481fa5d2d8c5 (diff)
downloadflake8-32c7ebcd7b527a70e96906e3d995ab79a5c39464.tar.gz
split lines the same when read from stdin
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/test_main.py23
-rw-r--r--tests/unit/test_file_processor.py17
2 files changed, 27 insertions, 13 deletions
diff --git a/tests/integration/test_main.py b/tests/integration/test_main.py
index 42ad76c..9193071 100644
--- a/tests/integration/test_main.py
+++ b/tests/integration/test_main.py
@@ -51,6 +51,29 @@ index d64ac39..7d943de 100644
assert err == ''
+def test_form_feed_line_split(tmpdir, capsys):
+ """Test that form feed is treated the same for stdin."""
+ src = 'x=1\n\f\ny=1\n'
+ expected_out = '''\
+t.py:1:2: E225 missing whitespace around operator
+t.py:3:2: E225 missing whitespace around operator
+'''
+
+ with tmpdir.as_cwd():
+ tmpdir.join('t.py').write(src)
+
+ with mock.patch.object(utils, 'stdin_get_value', return_value=src):
+ _call_main(['-', '--stdin-display-name=t.py'], retv=1)
+ out, err = capsys.readouterr()
+ assert out == expected_out
+ assert err == ''
+
+ _call_main(['t.py'], retv=1)
+ out, err = capsys.readouterr()
+ assert out == expected_out
+ assert err == ''
+
+
def test_e101_indent_char_does_not_reset(tmpdir, capsys):
"""Ensure that E101 with an existing indent_char does not reset it."""
t_py_contents = """\
diff --git a/tests/unit/test_file_processor.py b/tests/unit/test_file_processor.py
index f38568c..e5367a8 100644
--- a/tests/unit/test_file_processor.py
+++ b/tests/unit/test_file_processor.py
@@ -89,20 +89,15 @@ def test_should_ignore_file_to_handle_disable_noqa(default_options):
@mock.patch('flake8.utils.stdin_get_value')
def test_read_lines_from_stdin(stdin_get_value, default_options):
"""Verify that we use our own utility function to retrieve stdin."""
- stdin_value = mock.Mock()
- stdin_value.splitlines.return_value = []
- stdin_get_value.return_value = stdin_value
+ stdin_get_value.return_value = ''
processor.FileProcessor('-', default_options)
stdin_get_value.assert_called_once_with()
- stdin_value.splitlines.assert_called_once_with(True)
@mock.patch('flake8.utils.stdin_get_value')
def test_stdin_filename_attribute(stdin_get_value, default_options):
"""Verify that we update the filename attribute."""
- stdin_value = mock.Mock()
- stdin_value.splitlines.return_value = []
- stdin_get_value.return_value = stdin_value
+ stdin_get_value.return_value = ''
file_processor = processor.FileProcessor('-', default_options)
assert file_processor.filename == 'stdin'
@@ -111,9 +106,7 @@ def test_stdin_filename_attribute(stdin_get_value, default_options):
def test_read_lines_uses_display_name(stdin_get_value, default_options):
"""Verify that when processing stdin we use a display name if present."""
default_options.stdin_display_name = 'display_name.py'
- stdin_value = mock.Mock()
- stdin_value.splitlines.return_value = []
- stdin_get_value.return_value = stdin_value
+ stdin_get_value.return_value = ''
file_processor = processor.FileProcessor('-', default_options)
assert file_processor.filename == 'display_name.py'
@@ -123,9 +116,7 @@ def test_read_lines_ignores_empty_display_name(
stdin_get_value, default_options,
):
"""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
+ stdin_get_value.return_value = ''
default_options.stdin_display_name = ''
file_processor = processor.FileProcessor('-', default_options)
assert file_processor.filename == 'stdin'