diff options
author | Inada Naoki <songofacandy@gmail.com> | 2021-03-31 14:26:08 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-31 14:26:08 +0900 |
commit | ff3c9739bd69aa8b58007e63c9e40e6708b4761e (patch) | |
tree | 8f2b09f576e0f8ddb79d0a1e412363cff697ced7 /Lib/test/test_io.py | |
parent | 1b4a9c7956d5dc64f8002f62bf0faae2d1892f90 (diff) | |
download | cpython-git-ff3c9739bd69aa8b58007e63c9e40e6708b4761e.tar.gz |
bpo-43510: PEP 597: Accept `encoding="locale"` in binary mode (GH-25103)
It make `encoding="locale"` usable everywhere `encoding=None` is
allowed.
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r-- | Lib/test/test_io.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index c731302a9f..6a9ce39f08 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -531,6 +531,17 @@ class IOTest(unittest.TestCase): self.assertRaises(OSError, obj.truncate) self.assertRaises(OSError, obj.truncate, 0) + def test_open_binmode_encoding(self): + """open() raises ValueError when encoding is specified in bin mode""" + self.assertRaises(ValueError, self.open, os_helper.TESTFN, + "wb", encoding="utf-8") + + # encoding=None and encoding="locale" is allowed. + with self.open(os_helper.TESTFN, "wb", encoding=None): + pass + with self.open(os_helper.TESTFN, "wb", encoding="locale"): + pass + def test_open_handles_NUL_chars(self): fn_with_NUL = 'foo\0bar' self.assertRaises(ValueError, self.open, fn_with_NUL, 'w') |