mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +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
e8edbda897
commit
22f06d6ce3
3 changed files with 18 additions and 3 deletions
|
@ -326,6 +326,16 @@ class FileInputTests(BaseTests, unittest.TestCase):
|
|||
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