mirror of
https://github.com/python/cpython.git
synced 2025-09-20 07:31:10 +00:00
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.
This commit is contained in:
parent
3da5526136
commit
04dd60e50c
3 changed files with 15 additions and 19 deletions
|
@ -152,9 +152,6 @@ def search_function(encoding):
|
||||||
# Return the registry entry
|
# Return the registry entry
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
# Register the search_function in the Python codec registry
|
|
||||||
codecs.register(search_function)
|
|
||||||
|
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
def _alias_mbcs(encoding):
|
def _alias_mbcs(encoding):
|
||||||
try:
|
try:
|
||||||
|
@ -167,4 +164,8 @@ if sys.platform == 'win32':
|
||||||
# Imports may fail while we are shutting down
|
# Imports may fail while we are shutting down
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# It must be registered before search_function()
|
||||||
codecs.register(_alias_mbcs)
|
codecs.register(_alias_mbcs)
|
||||||
|
|
||||||
|
# Register the search_function in the Python codec registry
|
||||||
|
codecs.register(search_function)
|
||||||
|
|
|
@ -1904,7 +1904,10 @@ class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
|
||||||
name += "_codec"
|
name += "_codec"
|
||||||
elif encoding == "latin_1":
|
elif encoding == "latin_1":
|
||||||
name = "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)
|
(b, size) = codecs.getencoder(encoding)(s)
|
||||||
self.assertEqual(size, len(s), "encoding=%r" % encoding)
|
self.assertEqual(size, len(s), "encoding=%r" % encoding)
|
||||||
|
@ -3188,11 +3191,13 @@ class CodePageTest(unittest.TestCase):
|
||||||
self.assertEqual(decoded, ('abc', 3))
|
self.assertEqual(decoded, ('abc', 3))
|
||||||
|
|
||||||
def test_mbcs_alias(self):
|
def test_mbcs_alias(self):
|
||||||
# Check that looking up our 'default' codepage will return
|
# On Windows, the encoding name must be the ANSI code page
|
||||||
# mbcs when we don't have a more specific one available
|
encoding = locale.getpreferredencoding(False)
|
||||||
with mock.patch('_winapi.GetACP', return_value=123):
|
self.assertTrue(encoding.startswith('cp'), encoding)
|
||||||
codec = codecs.lookup('cp123')
|
|
||||||
self.assertEqual(codec.name, 'mbcs')
|
# 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)
|
@support.bigmemtest(size=2**31, memuse=7, dry_run=False)
|
||||||
def test_large_input(self, size):
|
def test_large_input(self, size):
|
||||||
|
|
|
@ -456,16 +456,6 @@ class ImportSideEffectTests(unittest.TestCase):
|
||||||
# 'help' should be set in builtins
|
# 'help' should be set in builtins
|
||||||
self.assertTrue(hasattr(builtins, "help"))
|
self.assertTrue(hasattr(builtins, "help"))
|
||||||
|
|
||||||
def test_aliasing_mbcs(self):
|
|
||||||
if sys.platform == "win32":
|
|
||||||
import locale
|
|
||||||
if locale.getdefaultlocale()[1].startswith('cp'):
|
|
||||||
for value in encodings.aliases.aliases.values():
|
|
||||||
if value == "mbcs":
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
self.fail("did not alias mbcs")
|
|
||||||
|
|
||||||
def test_sitecustomize_executed(self):
|
def test_sitecustomize_executed(self):
|
||||||
# If sitecustomize is available, it should have been imported.
|
# If sitecustomize is available, it should have been imported.
|
||||||
if "sitecustomize" not in sys.modules:
|
if "sitecustomize" not in sys.modules:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue