]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
#7855: Add tests for ctypes/winreg for issues found in IronPython. Initial patch...
authorEzio Melotti <ezio.melotti@gmail.com>
Sat, 4 May 2013 14:59:03 +0000 (17:59 +0300)
committerEzio Melotti <ezio.melotti@gmail.com>
Sat, 4 May 2013 14:59:03 +0000 (17:59 +0300)
Lib/ctypes/test/__init__.py
Lib/ctypes/test/test_wintypes.py [new file with mode: 0644]
Lib/test/test_winreg.py
Misc/ACKS
Misc/NEWS

index 52230928ba5b5cec72ef412dccfbd3d3e2777306..808e4185ef0a25f53d9eb348d4da5a079c6e8d3b 100644 (file)
@@ -62,7 +62,7 @@ def get_tests(package, mask, verbosity, exclude=()):
             continue
         try:
             mod = __import__(modname, globals(), locals(), ['*'])
-        except ResourceDenied, detail:
+        except (ResourceDenied, unittest.SkipTest) as detail:
             skipped.append(modname)
             if verbosity > 1:
                 print >> sys.stderr, "Skipped %s: %s" % (modname, detail)
diff --git a/Lib/ctypes/test/test_wintypes.py b/Lib/ctypes/test/test_wintypes.py
new file mode 100644 (file)
index 0000000..806fcce
--- /dev/null
@@ -0,0 +1,43 @@
+import sys
+import unittest
+
+if not sys.platform.startswith('win'):
+    raise unittest.SkipTest('Windows-only test')
+
+from ctypes import *
+from ctypes import wintypes
+
+class WinTypesTest(unittest.TestCase):
+    def test_variant_bool(self):
+        # reads 16-bits from memory, anything non-zero is True
+        for true_value in (1, 32767, 32768, 65535, 65537):
+            true = POINTER(c_int16)(c_int16(true_value))
+            value = cast(true, POINTER(wintypes.VARIANT_BOOL))
+            self.assertEqual(repr(value.contents), 'VARIANT_BOOL(True)')
+
+            vb = wintypes.VARIANT_BOOL()
+            self.assertIs(vb.value, False)
+            vb.value = True
+            self.assertIs(vb.value, True)
+            vb.value = true_value
+            self.assertIs(vb.value, True)
+
+        for false_value in (0, 65536, 262144, 2**33):
+            false = POINTER(c_int16)(c_int16(false_value))
+            value = cast(false, POINTER(wintypes.VARIANT_BOOL))
+            self.assertEqual(repr(value.contents), 'VARIANT_BOOL(False)')
+
+        # allow any bool conversion on assignment to value
+        for set_value in (65536, 262144, 2**33):
+            vb = wintypes.VARIANT_BOOL()
+            vb.value = set_value
+            self.assertIs(vb.value, True)
+
+        vb = wintypes.VARIANT_BOOL()
+        vb.value = [2, 3]
+        self.assertIs(vb.value, True)
+        vb.value = []
+        self.assertIs(vb.value, False)
+
+if __name__ == "__main__":
+    unittest.main()
index 683938acd4577b394894d684dd521209bfe2062e..e05d040998bc83729dcc35800c8aec8d44babec3 100644 (file)
@@ -442,6 +442,11 @@ class Win64WinregTests(BaseWinregTests):
             DeleteKeyEx(HKEY_CURRENT_USER, test_reflect_key_name,
                         KEY_WOW64_32KEY, 0)
 
+    def test_exception_numbers(self):
+        with self.assertRaises(WindowsError) as ctx:
+            QueryValue(HKEY_CLASSES_ROOT, 'some_value_that_does_not_exist')
+
+        self.assertEqual(ctx.exception.errno, 2)
 
 def test_main():
     test_support.run_unittest(LocalWinregTests, RemoteWinregTests,
index 9f50b4c5dca8894345df2b374ce5577d888cbbf2..660f52ce145996629856f0c7703871e4ac98ce4d 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1050,6 +1050,7 @@ Jaap Vermeulen
 Al Vezza
 Jacques A. Vidrine
 John Viega
+Dino Viehland
 Kannan Vijayan
 Kurt Vile
 Norman Vine
index f4387940c61f846e946b1e9b6c2a9f8ead611899..628ad7653864570a733a73e96d09e12a9b3fc182 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -81,6 +81,9 @@ Library
 Tests
 -----
 
+- Issue #7855: Add tests for ctypes/winreg for issues found in IronPython.
+  Initial patch by Dino Viehland.
+
 - Issue #17712: Fix test_gdb failures on Ubuntu 13.04.
 
 - Issue #17065: Use process-unique key for winreg tests to avoid failures if