|
10 | 10 |
|
11 | 11 | from test.support import (TESTFN, captured_output, check_impl_detail, |
12 | 12 | check_warnings, cpython_only, gc_collect, run_unittest, |
13 | | - no_tracing, unlink, get_attribute) |
| 13 | + no_tracing, unlink, import_module) |
14 | 14 |
|
15 | 15 | class NaiveException(Exception): |
16 | 16 | def __init__(self, x): |
@@ -246,12 +246,15 @@ def test_WindowsError(self): |
246 | 246 | self.assertEqual(w.strerror, 'foo') |
247 | 247 | self.assertEqual(w.filename, None) |
248 | 248 |
|
| 249 | + @unittest.skipUnless(sys.platform == 'win32', |
| 250 | + 'test specific to Windows') |
249 | 251 | def test_windows_message(self): |
250 | 252 | """Should fill in unknown error code in Windows error message""" |
251 | | - windll = get_attribute(ctypes, "windll") |
252 | | - code = int.from_bytes(b"\xE0msc", "big") |
253 | | - with self.assertRaisesRegex(OSError, hex(code)): |
254 | | - windll.kernel32.RaiseException(code, 0, 0, None) |
| 253 | + ctypes = import_module('ctypes') |
| 254 | + # this error code has no message, Python formats it as hexadecimal |
| 255 | + code = 3765269347 |
| 256 | + with self.assertRaisesRegex(OSError, 'Windows Error 0x%x' % code): |
| 257 | + ctypes.pythonapi.PyErr_SetFromWindowsErr(code) |
255 | 258 |
|
256 | 259 | def testAttributes(self): |
257 | 260 | # test that exception attributes are happy |
|
0 commit comments