summaryrefslogtreecommitdiff
path: root/Lib/test/test_fileinput.py
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2019-04-29 17:55:39 +0300
committerGitHub <noreply@github.com>2019-04-29 17:55:39 +0300
commitbe6dbfb43b89989ccc83fbc4c5234f50f44c47ad (patch)
tree421acfea7d743934f09a3ed793a49914ed05bb05 /Lib/test/test_fileinput.py
parent88c093705615c50c47fdd9ab976803f73de7e308 (diff)
downloadcpython-git-be6dbfb43b89989ccc83fbc4c5234f50f44c47ad.tar.gz
bpo-1613500: Don't hardcode output file mode in fileinput.FileInput (GH-12986)
Diffstat (limited to 'Lib/test/test_fileinput.py')
-rw-r--r--Lib/test/test_fileinput.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_fileinput.py b/Lib/test/test_fileinput.py
index 3857401ca6..8b7577b020 100644
--- a/Lib/test/test_fileinput.py
+++ b/Lib/test/test_fileinput.py
@@ -329,6 +329,16 @@ class FileInputTests(BaseTests, unittest.TestCase):
self.assertEqual(fi.readline(), b'')
self.assertEqual(fi.readline(), b'')
+ def test_inplace_binary_write_mode(self):
+ temp_file = self.writeTmp(b'Initial text.', mode='wb')
+ with FileInput(temp_file, mode='rb', inplace=True) as fobj:
+ line = fobj.readline()
+ self.assertEqual(line, b'Initial text.')
+ # print() cannot be used with files opened in binary mode.
+ sys.stdout.write(b'New line.')
+ with open(temp_file, 'rb') as f:
+ self.assertEqual(f.read(), b'New line.')
+
def test_context_manager(self):
t1 = self.writeTmp("A\nB\nC")
t2 = self.writeTmp("D\nE\nF")