aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_codecs.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-02-22 22:04:07 +0100
committerGitHub <noreply@github.com>2022-02-22 22:04:07 +0100
commitccbe8045faf6e63d36229ea4e1b9298572cda126 (patch)
tree398e7157040957ec220da5f8c7a00fd7fcad3c1b /Lib/test/test_codecs.py
parent8fb94893e4a870ed3533e80c4bc2f1ebf1cfa9e7 (diff)
downloadcpython-ccbe8045faf6e63d36229ea4e1b9298572cda126.tar.gz
cpython-ccbe8045faf6e63d36229ea4e1b9298572cda126.zip
bpo-46659: Fix the MBCS codec alias on Windows (GH-31218)
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r--Lib/test/test_codecs.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index d30ff8f82db..8118ec6f472 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -3191,13 +3191,16 @@ class CodePageTest(unittest.TestCase):
self.assertEqual(decoded, ('abc', 3))
def test_mbcs_alias(self):
- # On Windows, the encoding name must be the ANSI code page
- encoding = locale.getpreferredencoding(False)
- self.assertTrue(encoding.startswith('cp'), encoding)
-
- # The encodings module create a "mbcs" alias to the ANSI code page
- codec = codecs.lookup(encoding)
- self.assertEqual(codec.name, "mbcs")
+ # Check that looking up our 'default' codepage will return
+ # mbcs when we don't have a more specific one available
+ code_page = 99_999
+ name = f'cp{code_page}'
+ with mock.patch('_winapi.GetACP', return_value=code_page):
+ try:
+ codec = codecs.lookup(name)
+ self.assertEqual(codec.name, 'mbcs')
+ finally:
+ codecs.unregister(name)
@support.bigmemtest(size=2**31, memuse=7, dry_run=False)
def test_large_input(self, size):