mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #25510: fileinput.FileInput.readline() now returns b'' instead of ''
at the end if the FileInput was opened with binary mode. Patch by Ryosuke Ito.
This commit is contained in:
parent
1f1177d69a
commit
314464d0ab
3 changed files with 23 additions and 1 deletions
|
@ -288,6 +288,21 @@ class FileInputTests(unittest.TestCase):
|
|||
with self.assertRaises(UnicodeDecodeError):
|
||||
# Read to the end of file.
|
||||
list(fi)
|
||||
self.assertEqual(fi.readline(), '')
|
||||
self.assertEqual(fi.readline(), '')
|
||||
|
||||
def test_readline_binary_mode(self):
|
||||
with open(TESTFN, 'wb') as f:
|
||||
f.write(b'A\nB\r\nC\rD')
|
||||
self.addCleanup(safe_unlink, TESTFN)
|
||||
|
||||
with FileInput(files=TESTFN, mode='rb') as fi:
|
||||
self.assertEqual(fi.readline(), b'A\n')
|
||||
self.assertEqual(fi.readline(), b'B\r\n')
|
||||
self.assertEqual(fi.readline(), b'C\rD')
|
||||
# Read to the end of file.
|
||||
self.assertEqual(fi.readline(), b'')
|
||||
self.assertEqual(fi.readline(), b'')
|
||||
|
||||
def test_context_manager(self):
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue