8000 gh-110525: Delete `test_c_api` method from `set` object (#110688) · python/cpython@989a253 · GitHub
[go: up one dir, main page]

Skip to content

Commit 989a253

Browse files
authored
gh-110525: Delete test_c_api method from set object (#110688)
1 parent 05439d3 commit 989a253

File tree

4 files changed

+4
-158
lines changed

4 files changed

+4
-158
lines changed

Lib/test/test_set.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,10 +635,6 @@ def __le__(self, some_set):
635635
myset >= myobj
636636
self.assertTrue(myobj.le_called)
637637

638-
@unittest.skipUnless(hasattr(set, "test_c_api"),
639-
'C API test only available in a debug build')
640-
def test_c_api(self):
641-
self.assertEqual(set().test_c_api(), True)
642638

643639
class SetSubclass(set):
644640
pass

Lib/test/test_weakset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def setUp(self):
4444
def test_methods(self):
4545
weaksetmethods = dir(WeakSet)
4646
for method in dir(set):
47-
if method == 'test_c_api' or method.startswith('_'):
47+
if method.startswith('_'):
4848
continue
4949
self.assertIn(method, weaksetmethods,
5050
"WeakSet missing method " + method)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Remove undocumented ``test_c_api`` method from :class:`set`, which was only
2+
defined for testing purposes under ``Py_DEBUG``. Now we have proper CAPI
3+
tests.

Objects/setobject.c

Lines changed: 0 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,13 +2022,6 @@ static PySequenceMethods set_as_sequence = {
20222022

20232023
/* set object ********************************************************/
20242024

2025-
#ifdef Py_DEBUG
2026-
static PyObject *test_c_api(PySetObject *so, PyObject *Py_UNUSED(ignored));
2027-
2028-
PyDoc_STRVAR(test_c_api_doc, "Exercises C API. Returns True.\n\
2029-
All is well if assertions don't fail.");
2030-
#endif
2031-
20322025
static PyMethodDef set_methods[] = {
20332026
{"add", (PyCFunction)set_add, METH_O,
20342027
add_doc},
@@ -2066,10 +2059,6 @@ static PyMethodDef set_methods[] = {
20662059
symmetric_difference_doc},
20672060
{"symmetric_difference_update",(PyCFunction)set_symmetric_difference_update, METH_O,
20682061
symmetric_difference_update_doc},
2069-
#ifdef Py_DEBUG
2070-
{"test_c_api", (PyCFunction)test_c_api, METH_NOARGS,
2071-
test_c_api_doc},
2072-
#endif
20732062
{"union", (PyCFunction)set_union, METH_VARARGS,
20742063
union_doc},
20752064
{"update", (PyCFunction)set_update, METH_VARARGS,
@@ -2368,148 +2357,6 @@ _PySet_Update(PyObject *set, PyObject *iterable)
23682357
/* Exported for the gdb plugin's benefit. */
23692358
PyObject *_PySet_Dummy = dummy;
23702359

2371-
#ifdef Py_DEBUG
2372-
2373-
/* Test code to be called with any three element set.
2374-
Returns True and original set is restored. */
2375-
2376-
#define assertRaises(call_return_value, exception) \
2377-
do { \
2378-
assert(call_return_value); \
2379-
assert(PyErr_ExceptionMatches(exception)); \
2380-
PyErr_Clear(); \
2381-
} while(0)
2382-
2383-
static PyObject *
2384-
test_c_api(PySetObject *so, PyObject *Py_UNUSED(ignored))
2385-
{
2386-
Py_ssize_t count;
2387-
const char *s;
2388-
Py_ssize_t i;
2389-
PyObject *elem=NULL, *dup=NULL, *t, *f, *dup2, *x=NULL;
2390-
PyObject *ob = (PyObject *)so;
2391-
Py_hash_t hash;
2392-
PyObject *str;
2393-
2394-
/* Verify preconditions */
2395-
assert(PyAnySet_Check(ob));
2396-
assert(PyAnySet_CheckExact(ob));
2397-
assert(!PyFrozenSet_CheckExact(ob));
2398-
2399-
/* so.clear(); so |= set("abc"); */
2400-
str = PyUnicode_FromString("abc");
2401-
if (str == NULL)
2402-
return NULL;
2403-
set_clear_internal(so);
2404-
if (set_update_internal(so, str)) {
2405-
Py_DECREF(str);
2406-
return NULL;
2407-
}
2408-
Py_DECREF(str);
2409-
2410-
/* Exercise type/size checks */
2411-
assert(PySet_Size(ob) == 3);
2412-
assert(PySet_GET_SIZE(ob) == 3);
2413-
2414-
/* Raise TypeError for non-iterable constructor arguments */
2415-
assertRaises(PySet_New(Py_None) == NULL, PyExc_TypeError);
2416-
assertRaises(PyFrozenSet_New(Py_None) == NULL, PyExc_TypeError);
2417-
2418-
/* Raise TypeError for unhashable key */
2419-
dup = PySet_New(ob);
2420-
assertRaises(PySet_Discard(ob, dup) == -1, PyExc_TypeError);
2421-
assertRaises(PySet_Contains(ob, dup) == -1, PyExc_TypeError);
2422-
assertRaises(PySet_Add(ob, dup) == -1, PyExc_TypeError);
2423-
2424-
/* Exercise successful pop, contains, add, and discard */
2425-
elem = PySet_Pop(ob);
2426-
assert(PySet_Contains(ob, elem) == 0);
2427-
assert(PySet_GET_SIZE(ob) == 2);
2428-
assert(PySet_Add(ob, elem) == 0);
2429-
assert(PySet_Contains(ob, elem) == 1);
2430-
assert(PySet_GET_SIZE(ob) == 3);
2431-
assert(PySet_Discard(ob, elem) == 1);
2432-
assert(PySet_GET_SIZE(ob) == 2);
2433-
assert(PySet_Discard(ob, elem) == 0);
2434-
assert(PySet_GET_SIZE(ob) == 2);
2435-
2436-
/* Exercise clear */
2437-
dup2 = PySet_New(dup);
2438-
assert(PySet_Clear(dup2) == 0);
2439-
assert(PySet_Size(dup2) == 0);
2440-
Py_DECREF(dup2);
2441-
2442-
/* Raise SystemError on clear or update of frozen set */
2443-
f = PyFrozenSet_New(dup);
2444-
assertRaises(PySet_Clear(f) == -1, PyExc_SystemError);
2445-
assertRaises(_PySet_Update(f, dup) == -1, PyExc_SystemError);
2446-
assert(PySet_Add(f, elem) == 0);
2447-
Py_INCREF(f);
2448-
assertRaises(PySet_Add(f, elem) == -1, PyExc_SystemError);
2449-
Py_DECREF(f);
2450-
Py_DECREF(f);
2451-
2452-
/* Exercise direct iteration */
2453-
i = 0, count = 0;
2454-
while (_PySet_NextEntry((PyObject *)dup, &i, &x, &hash)) {
2455-
s = PyUnicode_AsUTF8(x);
2456-
assert(s && (s[0] == 'a' || s[0] == 'b' || s[0] == 'c'));
2457-
count++;
2458-
}
2459-
assert(count == 3);
2460-
2461-
/* Exercise updates */
2462-
dup2 = PySet_New(NULL);
2463-
assert(_PySet_Update(dup2, dup) == 0);
2464-
assert(PySet_Size(dup2) == 3);
2465-
assert(_PySet_Update(dup2, dup) == 0);
2466-
assert(PySet_Size(dup2) == 3);
2467-
Py_DECREF(dup2);
2468-
2469-
/* Raise SystemError when self argument is not a set or frozenset. */
2470-
t = PyTuple_New(0);
2471-
assertRaises(PySet_Size(t) == -1, PyExc_SystemError);
2472-
assertRaises(PySet_Contains(t, elem) == -1, PyExc_SystemError);
2473-
Py_DECREF(t);
2474-
2475-
/* Raise SystemError when self argument is not a set. */
2476-
f = PyFrozenSet_New(dup);
2477-
assert(PySet_Size(f) == 3);
2478-
assert(PyFrozenSet_CheckExact(f));
2479-
assertRaises(PySet_Discard(f, elem) == -1, PyExc_SystemError);
2480-
assertRaises(PySet_Pop(f) == NULL, PyExc_SystemError);
2481-
Py_DECREF(f);
2482-
2483-
/* Raise KeyError when popping from an empty set */
2484-
assert(PyNumber_InPlaceSubtract(ob, ob) == ob);
2485-
Py_DECREF(ob);
2486-
assert(PySet_GET_SIZE(ob) == 0);
2487-
assertRaises(PySet_Pop(ob) == NULL, PyExc_KeyError);
2488-
2489-
/* Restore the set from the copy using the PyNumber API */
2490-
assert(PyNumber_InPlaceOr(ob, dup) == ob);
2491-
Py_DECREF(ob);
2492-
2493-
/* Verify constructors accept NULL arguments */
2494-
f = PySet_New(NULL);
2495-
assert(f != NULL);
2496-
assert(PySet_GET_SIZE(f) == 0);
2497-
Py_DECREF(f);
2498-
f = PyFrozenSet_New(NULL);
2499-
assert(f != NULL);
2500-
assert(PyFrozenSet_CheckExact(f));
2501-
assert(PySet_GET_SIZE(f) == 0);
2502-
Py_DECREF(f);
2503-
2504-
Py_DECREF(elem);
2505-
Py_DECREF(dup);
2506-
Py_RETURN_TRUE;
2507-
}
2508-
2509-
#undef assertRaises
2510-
2511-
#endif
2512-
25132360
/***** Dummy Struct *************************************************/
25142361

25152362
static PyObject *

0 commit comments

Comments
 (0)
0