diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-07-24 03:05:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-24 03:05:10 (GMT) |
commit | 22f06d6ce344ba80f2213fbe12fe951ca77cab4e (patch) | |
tree | 570a7b688d7150d242159d6a55576e13696dd45a /Lib/test/test_fileinput.py | |
parent | e8edbda8972e83c86db1cb5b51ba9002c4923b6e (diff) | |
download | cpython-22f06d6ce344ba80f2213fbe12fe951ca77cab4e.zip cpython-22f06d6ce344ba80f2213fbe12fe951ca77cab4e.tar.gz cpython-22f06d6ce344ba80f2213fbe12fe951ca77cab4e.tar.bz2 |
gh-93157: Fix fileinput didn't support `errors` in `inplace` mode (GH-95128)
(cherry picked from commit 5c7f3bcdafedd60a385e8ca5403bc6b0b7a862b3)
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
Diffstat (limited to 'Lib/test/test_fileinput.py')
-rw-r--r-- | Lib/test/test_fileinput.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_fileinput.py b/Lib/test/test_fileinput.py index 8192000..ac20c74 100644 --- a/Lib/test/test_fileinput.py +++ b/Lib/test/test_fileinput.py @@ -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") |