Issue #22977: Fix test_exceptions
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 2 Apr 2015 12:17:38 +0000 (14:17 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 2 Apr 2015 12:17:38 +0000 (14:17 +0200)
Lib/test/test_exceptions.py

index 493cd2f83e3d94a9ca0b84b686686adcb115645d..a7f19cbddb2ef50bf40e863e557c15bf37e05cef 100644 (file)
@@ -10,7 +10,7 @@ import ctypes
 
 from test.support import (TESTFN, captured_output, check_impl_detail,
                           check_warnings, cpython_only, gc_collect, run_unittest,
-                          no_tracing, unlink, get_attribute)
+                          no_tracing, unlink, import_module)
 
 class NaiveException(Exception):
     def __init__(self, x):
@@ -246,12 +246,15 @@ class ExceptionTests(unittest.TestCase):
             self.assertEqual(w.strerror, 'foo')
             self.assertEqual(w.filename, None)
 
+    @unittest.skipUnless(sys.platform == 'win32',
+                         'test specific to Windows')
     def test_windows_message(self):
         """Should fill in unknown error code in Windows error message"""
-        windll = get_attribute(ctypes, "windll")
-        code = int.from_bytes(b"\xE0msc", "big")
-        with self.assertRaisesRegex(OSError, hex(code)):
-            windll.kernel32.RaiseException(code, 0, 0, None)
+        ctypes = import_module('ctypes')
+        # this error code has no message, Python formats it as hexadecimal
+        code = 3765269347
+        with self.assertRaisesRegex(OSError, 'Windows Error 0x%x' % code):
+            ctypes.pythonapi.PyErr_SetFromWindowsErr(code)
 
     def testAttributes(self):
         # test that exception attributes are happy