summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_capi/test_misc.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_capi/test_misc.py')
-rw-r--r--Lib/test/test_capi/test_misc.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/Lib/test/test_capi/test_misc.py b/Lib/test/test_capi/test_misc.py
index ada3018..b62bc4c 100644
--- a/Lib/test/test_capi/test_misc.py
+++ b/Lib/test/test_capi/test_misc.py
@@ -3335,6 +3335,49 @@ class TestPyThreadId(unittest.TestCase):
self.assertEqual(len(set(py_thread_ids)), len(py_thread_ids),
py_thread_ids)
+class TestVersions(unittest.TestCase):
+ full_cases = (
+ (3, 4, 1, 0xA, 2, 0x030401a2),
+ (3, 10, 0, 0xF, 0, 0x030a00f0),
+ (0x103, 0x10B, 0xFF00, -1, 0xF0, 0x030b00f0), # test masking
+ )
+ xy_cases = (
+ (3, 4, 0x03040000),
+ (3, 10, 0x030a0000),
+ (0x103, 0x10B, 0x030b0000), # test masking
+ )
+
+ def test_pack_full_version(self):
+ for *args, expected in self.full_cases:
+ with self.subTest(hexversion=hex(expected)):
+ result = _testlimitedcapi.pack_full_version(*args)
+ self.assertEqual(result, expected)
+
+ def test_pack_version(self):
+ for *args, expected in self.xy_cases:
+ with self.subTest(hexversion=hex(expected)):
+ result = _testlimitedcapi.pack_version(*args)
+ self.assertEqual(result, expected)
+
+ def test_pack_full_version_ctypes(self):
+ ctypes = import_helper.import_module('ctypes')
+ ctypes_func = ctypes.pythonapi.Py_PACK_FULL_VERSION
+ ctypes_func.restype = ctypes.c_uint32
+ ctypes_func.argtypes = [ctypes.c_int] * 5
+ for *args, expected in self.full_cases:
+ with self.subTest(hexversion=hex(expected)):
+ result = ctypes_func(*args)
+ self.assertEqual(result, expected)
+
+ def test_pack_version_ctypes(self):
+ ctypes = import_helper.import_module('ctypes')
+ ctypes_func = ctypes.pythonapi.Py_PACK_VERSION
+ ctypes_func.restype = ctypes.c_uint32
+ ctypes_func.argtypes = [ctypes.c_int] * 2
+ for *args, expected in self.xy_cases:
+ with self.subTest(hexversion=hex(expected)):
+ result = ctypes_func(*args)
+ self.assertEqual(result, expected)
if __name__ == "__main__":
unittest.main()