|
4 | 4 | # Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 |
5 | 5 | import importlib |
6 | 6 | import sys |
| 7 | +from pathlib import Path |
7 | 8 |
|
8 | 9 |
|
9 | 10 | def coding_checker(self, coder): |
@@ -893,12 +894,31 @@ def test_encode_dict_err_xmlcharrefreplace(self): |
893 | 894 |
|
894 | 895 | class MultibyteCodecTest(unittest.TestCase): |
895 | 896 |
|
896 | | - def test_missing_multibyte_codecs_raise_import_error(self): |
897 | | - expected_exc = ImportError if sys.implementation.name == 'graalpy' else LookupError |
| 897 | + def test_missing_multibyte_codecs_raise_lookup_error(self): |
898 | 898 | for module_name in ('_codecs_cn', '_codecs_hk', '_codecs_iso2022', '_codecs_jp', '_codecs_kr', '_codecs_tw'): |
899 | 899 | with self.subTest(module_name=module_name): |
900 | 900 | module = importlib.import_module(module_name) |
901 | | - self.assertRaises(expected_exc, module.getcodec, '__missing_codec__') |
| 901 | + self.assertRaises(LookupError, module.getcodec, '__missing_codec__') |
| 902 | + |
| 903 | + def test_unsupported_multibyte_codec_modules_raise_import_error_on_graalpy(self): |
| 904 | + encodings_dir = Path(__file__).resolve().parents[3] / 'lib-python' / '3' / 'encodings' |
| 905 | + for module_name in ( |
| 906 | + 'encodings.euc_jis_2004', |
| 907 | + 'encodings.euc_jisx0213', |
| 908 | + 'encodings.iso2022_jp_1', |
| 909 | + 'encodings.iso2022_jp_2004', |
| 910 | + 'encodings.iso2022_jp_3', |
| 911 | + 'encodings.iso2022_jp_ext', |
| 912 | + 'encodings.shift_jis_2004', |
| 913 | + ): |
| 914 | + with self.subTest(module_name=module_name): |
| 915 | + module_path = encodings_dir / f'{module_name.rsplit(".", 1)[1]}.py' |
| 916 | + spec = importlib.util.spec_from_file_location(f'test_{module_name.replace(".", "_")}', module_path) |
| 917 | + module = importlib.util.module_from_spec(spec) |
| 918 | + if sys.implementation.name == 'graalpy': |
| 919 | + self.assertRaises(ImportError, spec.loader.exec_module, module) |
| 920 | + else: |
| 921 | + spec.loader.exec_module(module) |
902 | 922 |
|
903 | 923 | # just a smoke test |
904 | 924 | def test_encode(self): |
|
0 commit comments