ยปCore Development>Code coverage>Lib/ctypes/test/test_wintypes.py

Python code coverage for Lib/ctypes/test/test_wintypes.py

#countcontent
1n/aimport sys
2n/aimport unittest
3n/a
4n/afrom ctypes import *
5n/a
6n/a@unittest.skipUnless(sys.platform.startswith('win'), 'Windows-only test')
7n/aclass WinTypesTest(unittest.TestCase):
8n/a def test_variant_bool(self):
9n/a from ctypes import wintypes
10n/a # reads 16-bits from memory, anything non-zero is True
11n/a for true_value in (1, 32767, 32768, 65535, 65537):
12n/a true = POINTER(c_int16)(c_int16(true_value))
13n/a value = cast(true, POINTER(wintypes.VARIANT_BOOL))
14n/a self.assertEqual(repr(value.contents), 'VARIANT_BOOL(True)')
15n/a
16n/a vb = wintypes.VARIANT_BOOL()
17n/a self.assertIs(vb.value, False)
18n/a vb.value = True
19n/a self.assertIs(vb.value, True)
20n/a vb.value = true_value
21n/a self.assertIs(vb.value, True)
22n/a
23n/a for false_value in (0, 65536, 262144, 2**33):
24n/a false = POINTER(c_int16)(c_int16(false_value))
25n/a value = cast(false, POINTER(wintypes.VARIANT_BOOL))
26n/a self.assertEqual(repr(value.contents), 'VARIANT_BOOL(False)')
27n/a
28n/a # allow any bool conversion on assignment to value
29n/a for set_value in (65536, 262144, 2**33):
30n/a vb = wintypes.VARIANT_BOOL()
31n/a vb.value = set_value
32n/a self.assertIs(vb.value, True)
33n/a
34n/a vb = wintypes.VARIANT_BOOL()
35n/a vb.value = [2, 3]
36n/a self.assertIs(vb.value, True)
37n/a vb.value = []
38n/a self.assertIs(vb.value, False)
39n/a
40n/aif __name__ == "__main__":
41n/a unittest.main()