Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit04dd60e

Browse files
authored
bpo-46659: Update the test on the mbcs codec alias (GH-31168)
encodings registers the _alias_mbcs() codec search function beforethe search_function() codec search function. Previously, the_alias_mbcs() was never used.Fix the test_codecs.test_mbcs_alias() test: use the current ANSI codepage, not a fake ANSI code page number.Remove the test_site.test_aliasing_mbcs() test: the alias is nowimplemented in the encodings module, no longer in the site module.
1 parent3da5526 commit04dd60e

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

‎Lib/encodings/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,6 @@ def search_function(encoding):
152152
# Return the registry entry
153153
returnentry
154154

155-
# Register the search_function in the Python codec registry
156-
codecs.register(search_function)
157-
158155
ifsys.platform=='win32':
159156
def_alias_mbcs(encoding):
160157
try:
@@ -167,4 +164,8 @@ def _alias_mbcs(encoding):
167164
# Imports may fail while we are shutting down
168165
pass
169166

167+
# It must be registered before search_function()
170168
codecs.register(_alias_mbcs)
169+
170+
# Register the search_function in the Python codec registry
171+
codecs.register(search_function)

‎Lib/test/test_codecs.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,7 +1904,10 @@ def test_basics(self):
19041904
name+="_codec"
19051905
elifencoding=="latin_1":
19061906
name="latin_1"
1907-
self.assertEqual(encoding.replace("_","-"),name.replace("_","-"))
1907+
# Skip the mbcs alias on Windows
1908+
ifname!="mbcs":
1909+
self.assertEqual(encoding.replace("_","-"),
1910+
name.replace("_","-"))
19081911

19091912
(b,size)=codecs.getencoder(encoding)(s)
19101913
self.assertEqual(size,len(s),"encoding=%r"%encoding)
@@ -3188,11 +3191,13 @@ def test_incremental(self):
31883191
self.assertEqual(decoded, ('abc',3))
31893192

31903193
deftest_mbcs_alias(self):
3191-
# Check that looking up our 'default' codepage will return
3192-
# mbcs when we don't have a more specific one available
3193-
withmock.patch('_winapi.GetACP',return_value=123):
3194-
codec=codecs.lookup('cp123')
3195-
self.assertEqual(codec.name,'mbcs')
3194+
# On Windows, the encoding name must be the ANSI code page
3195+
encoding=locale.getpreferredencoding(False)
3196+
self.assertTrue(encoding.startswith('cp'),encoding)
3197+
3198+
# The encodings module create a "mbcs" alias to the ANSI code page
3199+
codec=codecs.lookup(encoding)
3200+
self.assertEqual(codec.name,"mbcs")
31963201

31973202
@support.bigmemtest(size=2**31,memuse=7,dry_run=False)
31983203
deftest_large_input(self,size):

‎Lib/test/test_site.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -456,16 +456,6 @@ def test_setting_help(self):
456456
# 'help' should be set in builtins
457457
self.assertTrue(hasattr(builtins,"help"))
458458

459-
deftest_aliasing_mbcs(self):
460-
ifsys.platform=="win32":
461-
importlocale
462-
iflocale.getdefaultlocale()[1].startswith('cp'):
463-
forvalueinencodings.aliases.aliases.values():
464-
ifvalue=="mbcs":
465-
break
466-
else:
467-
self.fail("did not alias mbcs")
468-
469459
deftest_sitecustomize_executed(self):
470460
# If sitecustomize is available, it should have been imported.
471461
if"sitecustomize"notinsys.modules:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp