summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_io.py
diff options
context:
space:
mode:
authorInada Naoki <songofacandy@gmail.com>2022-04-04 02:46:57 (GMT)
committerGitHub <noreply@github.com>2022-04-04 02:46:57 (GMT)
commit4216dce04b7d3f329beaaafc82a77c4ac6cf4d57 (patch)
treeb3ff3df025ddb3c383beb156fd150df62d40ac8e /Lib/test/test_io.py
parent6db2db91b96aaa1270c200ec931a2250fe2799c7 (diff)
downloadcpython-4216dce04b7d3f329beaaafc82a77c4ac6cf4d57.zip
cpython-4216dce04b7d3f329beaaafc82a77c4ac6cf4d57.tar.gz
cpython-4216dce04b7d3f329beaaafc82a77c4ac6cf4d57.tar.bz2
bpo-47000: Make `io.text_encoding()` respects UTF-8 mode (GH-32003)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r--Lib/test/test_io.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 2d0ca87..67be108 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -4289,6 +4289,17 @@ class MiscIOTest(unittest.TestCase):
self.assertTrue(
warnings[1].startswith(b"<string>:8: EncodingWarning: "))
+ def test_text_encoding(self):
+ # PEP 597, bpo-47000. io.text_encoding() returns "locale" or "utf-8"
+ # based on sys.flags.utf8_mode
+ code = "import io; print(io.text_encoding(None))"
+
+ proc = assert_python_ok('-X', 'utf8=0', '-c', code)
+ self.assertEqual(b"locale", proc.out.strip())
+
+ proc = assert_python_ok('-X', 'utf8=1', '-c', code)
+ self.assertEqual(b"utf-8", proc.out.strip())
+
@support.cpython_only
# Depending if OpenWrapper was already created or not, the warning is
# emitted or not. For example, the attribute is already created when this