diff options
author | Victor Stinner <vstinner@python.org> | 2020-10-31 00:32:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-31 00:32:11 (GMT) |
commit | b62bdf71ea0cd52041d49691d8ae3dc645bd48e1 (patch) | |
tree | 376fe1864673d8de21c8621629765cd1a28cdb1b /Lib/test | |
parent | 710e82630775774dceba5e8f24b1b10e6dfaf9b7 (diff) | |
download | cpython-b62bdf71ea0cd52041d49691d8ae3dc645bd48e1.zip cpython-b62bdf71ea0cd52041d49691d8ae3dc645bd48e1.tar.gz cpython-b62bdf71ea0cd52041d49691d8ae3dc645bd48e1.tar.bz2 |
bpo-42208: Add _locale._get_locale_encoding() (GH-23052)
* Add a new _locale._get_locale_encoding() function to get the
current locale encoding.
* Modify locale.getpreferredencoding() to use it.
* Remove the _bootlocale module.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_mimetypes.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/Lib/test/test_mimetypes.py b/Lib/test/test_mimetypes.py index ddeae38..d63f6b6 100644 --- a/Lib/test/test_mimetypes.py +++ b/Lib/test/test_mimetypes.py @@ -3,7 +3,7 @@ import locale import mimetypes import pathlib import sys -import unittest +import unittest.mock from test import support from test.support import os_helper @@ -71,14 +71,14 @@ class MimeTypesTestCase(unittest.TestCase): # bpo-41048: read_mime_types should read the rule file with 'utf-8' encoding. # Not with locale encoding. _bootlocale has been imported because io.open(...) # uses it. - with os_helper.temp_dir() as directory: - data = "application/no-mans-land Fran\u00E7ais" - file = pathlib.Path(directory, "sample.mimetype") - file.write_text(data, encoding='utf-8') - import _bootlocale - with support.swap_attr(_bootlocale, 'getpreferredencoding', lambda do_setlocale=True: 'ASCII'): - mime_dict = mimetypes.read_mime_types(file) - eq(mime_dict[".Français"], "application/no-mans-land") + data = "application/no-mans-land Fran\u00E7ais" + filename = "filename" + fp = io.StringIO(data) + with unittest.mock.patch.object(mimetypes, 'open', + return_value=fp) as mock_open: + mime_dict = mimetypes.read_mime_types(filename) + mock_open.assert_called_with(filename, encoding='utf-8') + eq(mime_dict[".Français"], "application/no-mans-land") def test_non_standard_types(self): eq = self.assertEqual |