|
1 | | -import _ctypes |
2 | 1 | import os |
3 | 2 | import platform |
4 | 3 | import re |
@@ -123,16 +122,27 @@ def test_null_dlsym(self): |
123 | 122 | self.assertEqual(os.read(pipe_r, 2), b'OK') |
124 | 123 |
|
125 | 124 |
|
126 | | -class TestCAPI(unittest.TestCase): |
127 | | - |
128 | | - @unittest.skipUnless(hasattr(_ctypes, 'dlopen'), 'require ctypes.dlopen()') |
129 | | - @test.support.run_with_locales('LC_ALL', 'fr_FR.utf8', 'fr_FR.iso88591') |
| 125 | +@unittest.skipUnless(sys.platform.startswith('linux'), |
| 126 | + 'test requires _ctypes.dlopen()') |
| 127 | +class TestLinuxLocalization(unittest.TestCase): |
| 128 | + |
| 129 | + @test.support.run_with_locale( |
| 130 | + 'LC_ALL', |
| 131 | + 'fr_FR.iso88591', 'ja_JP.sjis', 'zh_CN.gbk', |
| 132 | + '', |
| 133 | + ) |
130 | 134 | def test_localized_error(self): |
131 | | - with self.assertRaisesRegex( |
132 | | - OSError, |
133 | | - re.escape("foo.so: Ne peut ouvrir le fichier d'objet partagé"), |
134 | | - ): |
135 | | - _ctypes.dlopen('foo.so', 2) |
| 135 | + # An ImportError would be propagated and would be unexpected on Linux. |
| 136 | + from _ctypes import dlopen |
| 137 | + |
| 138 | + missing_filename = b'missing\xff.so' |
| 139 | + # Depending whether the locale is ISO-88591 or not, we may either |
| 140 | + # encode '\xff' as '\udcff' or 'ÿ', but we are only interested in |
| 141 | + # avoiding a UnicodeDecodeError when reporting the dlerror() error |
| 142 | + # message which contains the localized filename. |
| 143 | + filename_pattern = r'missing[ÿ|\udcff].so:.+' |
| 144 | + with self.assertRaisesRegex(OSError, filename_pattern): |
| 145 | + dlopen(missing_filename, 2) |
136 | 146 |
|
137 | 147 |
|
138 | 148 | if __name__ == "__main__": |
|
0 commit comments