summaryrefslogtreecommitdiff
path: root/Lib/test/test_fileinput.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-05-14 21:08:33 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2014-05-14 21:08:33 +0300
commit946cfc3e238bbd67ff436af5fd05414bbd2e5a08 (patch)
treeb8bc5c17edf6498d5f09253315b9a4e46d75c86c /Lib/test/test_fileinput.py
parente2d66903e8e336817702213f0cd8c3a24edf03ac (diff)
downloadcpython-git-946cfc3e238bbd67ff436af5fd05414bbd2e5a08.tar.gz
Issue #21075: fileinput.FileInput now reads bytes from standard stream if
binary mode is specified. Patch by Sam Kimbrel.
Diffstat (limited to 'Lib/test/test_fileinput.py')
-rw-r--r--Lib/test/test_fileinput.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/test/test_fileinput.py b/Lib/test/test_fileinput.py
index eba55c99a4..1d089f52b8 100644
--- a/Lib/test/test_fileinput.py
+++ b/Lib/test/test_fileinput.py
@@ -19,11 +19,12 @@ try:
except ImportError:
gzip = None
-from io import StringIO
+from io import BytesIO, StringIO
from fileinput import FileInput, hook_encoded
from test.support import verbose, TESTFN, run_unittest, check_warnings
from test.support import unlink as safe_unlink
+from unittest import mock
# The fileinput module has 2 interfaces: the FileInput class which does
@@ -232,6 +233,13 @@ class FileInputTests(unittest.TestCase):
finally:
remove_tempfiles(t1)
+ def test_stdin_binary_mode(self):
+ with mock.patch('sys.stdin') as m_stdin:
+ m_stdin.buffer = BytesIO(b'spam, bacon, sausage, and spam')
+ fi = FileInput(files=['-'], mode='rb')
+ lines = list(fi)
+ self.assertEqual(lines, [b'spam, bacon, sausage, and spam'])
+
def test_file_opening_hook(self):
try:
# cannot use openhook and inplace mode