mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-104783: locale.getencoding() fallback uses FS encoding (#105381)
The locale.getencoding() function now uses sys.getfilesystemencoding() if _locale.getencoding() is missing, instead of calling locale.getdefaultlocale().
This commit is contained in:
parent
3a975b5e92
commit
b1a91d26c6
2 changed files with 16 additions and 9 deletions
|
@ -1,6 +1,8 @@
|
|||
from decimal import Decimal
|
||||
from test.support import verbose, is_android, is_emscripten, is_wasi
|
||||
from test.support.warnings_helper import check_warnings
|
||||
from test.support.import_helper import import_fresh_module
|
||||
from unittest import mock
|
||||
import unittest
|
||||
import locale
|
||||
import sys
|
||||
|
@ -523,6 +525,15 @@ class TestMiscellaneous(unittest.TestCase):
|
|||
# make sure it is valid
|
||||
codecs.lookup(enc)
|
||||
|
||||
def test_getencoding_fallback(self):
|
||||
# When _locale.getencoding() is missing, locale.getencoding() uses
|
||||
# the Python filesystem
|
||||
encoding = 'FALLBACK_ENCODING'
|
||||
with mock.patch.object(sys, 'getfilesystemencoding',
|
||||
return_value=encoding):
|
||||
locale_fallback = import_fresh_module('locale', blocked=['_locale'])
|
||||
self.assertEqual(locale_fallback.getencoding(), encoding)
|
||||
|
||||
def test_getpreferredencoding(self):
|
||||
# Invoke getpreferredencoding to make sure it does not cause exceptions.
|
||||
enc = locale.getpreferredencoding()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue