summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_codecs.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-02-06 20:50:09 (GMT)
committerGitHub <noreply@github.com>2022-02-06 20:50:09 (GMT)
commit04dd60e50cd3da48fd19cdab4c0e4cc600d6af30 (patch)
tree81f316a4d68d61647d0bc91ba6e44759996e247a /Lib/test/test_codecs.py
parent3da5526136034188185d6a3fdba71e2b56577ee2 (diff)
downloadcpython-04dd60e50cd3da48fd19cdab4c0e4cc600d6af30.zip
cpython-04dd60e50cd3da48fd19cdab4c0e4cc600d6af30.tar.gz
cpython-04dd60e50cd3da48fd19cdab4c0e4cc600d6af30.tar.bz2
bpo-46659: Update the test on the mbcs codec alias (GH-31168)
encodings registers the _alias_mbcs() codec search function before the search_function() codec search function. Previously, the _alias_mbcs() was never used. Fix the test_codecs.test_mbcs_alias() test: use the current ANSI code page, not a fake ANSI code page number. Remove the test_site.test_aliasing_mbcs() test: the alias is now implemented in the encodings module, no longer in the site module.
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r--Lib/test/test_codecs.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 4ad24db..d30ff8f 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -1904,7 +1904,10 @@ class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
name += "_codec"
elif encoding == "latin_1":
name = "latin_1"
- self.assertEqual(encoding.replace("_", "-"), name.replace("_", "-"))
+ # Skip the mbcs alias on Windows
+ if name != "mbcs":
+ self.assertEqual(encoding.replace("_", "-"),
+ name.replace("_", "-"))
(b, size) = codecs.getencoder(encoding)(s)
self.assertEqual(size, len(s), "encoding=%r" % encoding)
@@ -3188,11 +3191,13 @@ class CodePageTest(unittest.TestCase):
self.assertEqual(decoded, ('abc', 3))
def test_mbcs_alias(self):
- # Check that looking up our 'default' codepage will return
- # mbcs when we don't have a more specific one available
- with mock.patch('_winapi.GetACP', return_value=123):
- codec = codecs.lookup('cp123')
- self.assertEqual(codec.name, 'mbcs')
+ # 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")
@support.bigmemtest(size=2**31, memuse=7, dry_run=False)
def test_large_input(self, size):