mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-93157: Fix fileinput didn't support errors in inplace mode (GH-95128)
(cherry picked from commit 5c7f3bcdaf)
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
This commit is contained in:
parent
e71e6e2ce5
commit
4a682b4f1a
3 changed files with 18 additions and 3 deletions
|
|
@ -336,6 +336,16 @@ def test_inplace_binary_write_mode(self):
|
|||
with open(temp_file, 'rb') as f:
|
||||
self.assertEqual(f.read(), b'New line.')
|
||||
|
||||
def test_inplace_encoding_errors(self):
|
||||
temp_file = self.writeTmp(b'Initial text \x88', mode='wb')
|
||||
with FileInput(temp_file, inplace=True,
|
||||
encoding="ascii", errors="replace") as fobj:
|
||||
line = fobj.readline()
|
||||
self.assertEqual(line, 'Initial text \ufffd')
|
||||
print("New line \x88")
|
||||
with open(temp_file, 'rb') as f:
|
||||
self.assertEqual(f.read().rstrip(b'\r\n'), b'New line ?')
|
||||
|
||||
def test_file_hook_backward_compatibility(self):
|
||||
def old_hook(filename, mode):
|
||||
return io.StringIO("I used to receive only filename and mode")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue