|
6 | 6 | import io |
7 | 7 | import pickle |
8 | 8 | import os |
| 9 | +import subprocess |
9 | 10 | import sys |
| 11 | +import textwrap |
10 | 12 | import unittest |
11 | 13 | import encodings |
12 | 14 | from unittest import mock |
@@ -3772,6 +3774,41 @@ def iconv_encoding_available(name): |
3772 | 3774 | 'the iconv codec is not available') |
3773 | 3775 | class IconvTest(unittest.TestCase): |
3774 | 3776 |
|
| 3777 | + @support.requires_subprocess() |
| 3778 | + @unittest.skipIf(sys.platform == 'darwin', 'macOS uses UTF-8 for paths') |
| 3779 | + @support.run_with_locale('LC_CTYPE', 'hy_AM.armscii8', 'hy_AM.ARMSCII-8') |
| 3780 | + def test_filesystem_encoding_after_cache_clear(self): |
| 3781 | + import locale |
| 3782 | + |
| 3783 | + self.require('ARMSCII-8') |
| 3784 | + code = textwrap.dedent(r""" |
| 3785 | + import codecs |
| 3786 | + import encodings |
| 3787 | + import os |
| 3788 | + import sys |
| 3789 | +
|
| 3790 | + assert sys.getfilesystemencoding() == 'armscii-8' |
| 3791 | + path = '\u0531' |
| 3792 | + encoded = os.fsencode(path) |
| 3793 | +
|
| 3794 | + def search(name): |
| 3795 | + return None |
| 3796 | +
|
| 3797 | + encodings._cache.clear() |
| 3798 | + codecs.register(search) |
| 3799 | + codecs.unregister(search) |
| 3800 | +
|
| 3801 | + assert os.fsencode(path) == encoded |
| 3802 | + assert os.fsdecode(encoded) == path |
| 3803 | + """) |
| 3804 | + result = subprocess.run( |
| 3805 | + [sys.executable, '-I', '-X', 'utf8=0', '-c', code], |
| 3806 | + env={**os.environ, 'LC_ALL': locale.setlocale(locale.LC_CTYPE)}, |
| 3807 | + capture_output=True, timeout=support.SHORT_TIMEOUT, |
| 3808 | + ) |
| 3809 | + self.assertEqual(result.returncode, 0, |
| 3810 | + result.stderr[-1500:].decode(errors='replace')) |
| 3811 | + |
3775 | 3812 | def require(self, *names): |
3776 | 3813 | for name in names: |
3777 | 3814 | if iconv_encoding_available(name): |
|
0 commit comments