mirror of
https://github.com/python/cpython.git
synced 2025-10-06 23:21:06 +00:00
bpo-1613500: Don't hardcode output file mode in fileinput.FileInput (GH-12986)
This commit is contained in:
parent
88c0937056
commit
be6dbfb43b
3 changed files with 16 additions and 2 deletions
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue