File size: 3,072 Bytes
a4edccc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
diff --git a/Lib/test/test_capi/test_slots_aug.py b/Lib/test/test_capi/test_slots_aug.py
new file mode 100644
index 0000000..cc199a7
--- /dev/null
+++ b/Lib/test/test_capi/test_slots_aug.py
@@ -0,0 +1,52 @@
+from test.support import import_helper
+import unittest
+
+# See Modules/_testlimitedcapi/slots.c for the C definitions these tests drive.
+# The augmented cases/helpers (token_use_spec, type_from_base_and_bases,
+# module_from_slots_no_abi) are added by eval_tests_aug_helpers.patch.
+_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
+
+
+class FakeSpec:
+    name = 'module'
+
+
+class SlotsAugTests(unittest.TestCase):
+    """LoLBench augmented tests for PySlot behaviors not exercised by the
+    original test_slots suite. Each drives the public PySlot construction
+    surface (PyType_FromSlots / PyModule_FromSlotsAndSpec) through the
+    ``_testlimitedcapi`` helpers, asserting the documented validation rules.
+    """
+
+    def test_token_use_spec_requires_pytype_spec(self):
+        # PEP 820: with PyType_FromSlots the Py_tp_token slot may not be set to
+        # Py_TP_USE_SPEC (NULL) -- that sentinel only resolves under a
+        # PyType_Spec. The slots-only path must raise rather than silently
+        # build a type with a NULL token.
+        with self.assertRaisesRegex(
+                SystemError, "Py_TP_USE_SPEC"):
+            _testlimitedcapi.type_from_slots("token_use_spec")
+
+    def test_tp_bases_overrides_tp_base(self):
+        # When both Py_tp_bases and Py_tp_base are supplied, Py_tp_bases wins
+        # (Py_tp_base is ignored once Py_tp_bases has been seen).
+        class A:
+            pass
+
+        class B:
+            pass
+
+        cls = _testlimitedcapi.type_from_base_and_bases((A,), B)
+        self.assertEqual(cls.__bases__, (A,))
+
+    def test_slots_only_module_requires_mod_abi(self):
+        # A module defined from slots only (no backing PyModuleDef) must declare
+        # Py_mod_abi; omitting it is a mandatory-slot SystemError.
+        with self.assertRaisesRegex(
+                SystemError,
+                ""):
+            _testlimitedcapi.module_from_slots_no_abi(FakeSpec())
+
+
+if __name__ == "__main__":
+    unittest.main()
diff --git a/Lib/test/test_capi/test_slots_compat_aug.py b/Lib/test/test_capi/test_slots_compat_aug.py
new file mode 100644
index 0000000..33060d6
--- /dev/null
+++ b/Lib/test/test_capi/test_slots_compat_aug.py
@@ -0,0 +1,18 @@
+import unittest
+
+
+class SlotsCompatAugTests(unittest.TestCase):
+    """Augmented pass-to-pass guard: a stable type-construction contract that
+    is independent of the PySlot feature, so it passes both before and after
+    the solution is applied."""
+
+    def test_three_arg_type_construction_contract(self):
+        cls = type("C", (object,), {"x": 1})
+        self.assertEqual(cls.__name__, "C")
+        self.assertEqual(cls.__bases__, (object,))
+        self.assertEqual(cls().x, 1)
+        self.assertTrue(issubclass(cls, object))
+
+
+if __name__ == "__main__":
+    unittest.main()