diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-11-01 16:45:54 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-11-01 16:45:54 +0200 |
commit | 17bdf2015d8c46d6418ad7b8742a4fb0d277a642 (patch) | |
tree | 52b5aada60471174cf331f2f5ea594354cea54b8 /Lib/test/test_fileinput.py | |
parent | 9b69491901045bcaff15fd9de9eb4c888cc5a3bd (diff) | |
parent | 56275dc1e2a2f354620189efd751fa90af2118e1 (diff) | |
download | cpython-git-17bdf2015d8c46d6418ad7b8742a4fb0d277a642.tar.gz |
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.
Diffstat (limited to 'Lib/test/test_fileinput.py')
-rw-r--r-- | Lib/test/test_fileinput.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_fileinput.py b/Lib/test/test_fileinput.py index 1d089f52b8..4765a056f6 100644 --- a/Lib/test/test_fileinput.py +++ b/Lib/test/test_fileinput.py @@ -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: |