mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-14 00:14:46 +00:00
Be explicit about the bytes put into test files
This commit is contained in:
parent
42590a68a5
commit
308a0bdb50
1 changed files with 6 additions and 5 deletions
|
|
@ -27,15 +27,16 @@ def test_read_lines_splits_lines():
|
||||||
for line in lines)
|
for line in lines)
|
||||||
|
|
||||||
|
|
||||||
def lines_from_file(tmpdir, lines):
|
def lines_from_file(tmpdir, contents):
|
||||||
f = tmpdir.join('f.py')
|
f = tmpdir.join('f.py')
|
||||||
f.write(''.join(lines))
|
# be careful to write the bytes exactly to avoid newline munging
|
||||||
|
f.write_binary(contents)
|
||||||
return processor.FileProcessor(f.strpath, options_from()).lines
|
return processor.FileProcessor(f.strpath, options_from()).lines
|
||||||
|
|
||||||
|
|
||||||
def test_read_lines_universal_newlines(tmpdir):
|
def test_read_lines_universal_newlines(tmpdir):
|
||||||
r"""Verify that line endings are translated to \n."""
|
r"""Verify that line endings are translated to \n."""
|
||||||
lines = lines_from_file(tmpdir, ['# coding: utf-8\r\n', 'x = 1\r\n'])
|
lines = lines_from_file(tmpdir, b'# coding: utf-8\r\nx = 1\r\n')
|
||||||
assert lines == ['# coding: utf-8\n', 'x = 1\n']
|
assert lines == ['# coding: utf-8\n', 'x = 1\n']
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -43,13 +44,13 @@ def test_read_lines_incorrect_utf_16(tmpdir):
|
||||||
"""Verify that a file which incorrectly claims it is utf16 is still read
|
"""Verify that a file which incorrectly claims it is utf16 is still read
|
||||||
as latin-1.
|
as latin-1.
|
||||||
"""
|
"""
|
||||||
lines = lines_from_file(tmpdir, ['# coding: utf16\n', 'x = 1\n'])
|
lines = lines_from_file(tmpdir, b'# coding: utf16\nx = 1\n')
|
||||||
assert lines == ['# coding: utf16\n', 'x = 1\n']
|
assert lines == ['# coding: utf16\n', 'x = 1\n']
|
||||||
|
|
||||||
|
|
||||||
def test_read_lines_unknown_encoding(tmpdir):
|
def test_read_lines_unknown_encoding(tmpdir):
|
||||||
"""Verify that an unknown encoding is still read as latin-1."""
|
"""Verify that an unknown encoding is still read as latin-1."""
|
||||||
lines = lines_from_file(tmpdir, ['# coding: fake-encoding\n', 'x = 1\n'])
|
lines = lines_from_file(tmpdir, b'# coding: fake-encoding\nx = 1\n')
|
||||||
assert lines == ['# coding: fake-encoding\n', 'x = 1\n']
|
assert lines == ['# coding: fake-encoding\n', 'x = 1\n']
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue