Skip to content

Commit 71b126d

Browse files
committed
pythongh-107178: Remove _testcapi.test_dict_capi()
The new _testcapi.test_dict tests are more complete, _testcapi.test_dict_capi() became redundant.
1 parent b780882 commit 71b126d

File tree

1 file changed

+0
-191
lines changed

1 file changed

+0
-191
lines changed

Modules/_testcapimodule.c

-191
Original file line numberDiff line numberDiff line change
@@ -3325,196 +3325,6 @@ test_weakref_capi(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
33253325
}
33263326

33273327

3328-
static PyObject *
3329-
test_dict_capi(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
3330-
{
3331-
assert(!PyErr_Occurred());
3332-
3333-
PyObject *dict= NULL, *key = NULL, *missing_key = NULL, *value = NULL;
3334-
PyObject *invalid_key = NULL;
3335-
int res;
3336-
3337-
// test PyDict_New()
3338-
dict = PyDict_New();
3339-
if (dict == NULL) {
3340-
goto error;
3341-
}
3342-
3343-
key = PyUnicode_FromString("key");
3344-
if (key == NULL) {
3345-
goto error;
3346-
}
3347-
3348-
missing_key = PyUnicode_FromString("missing_key");
3349-
if (missing_key == NULL) {
3350-
goto error;
3351-
}
3352-
3353-
value = PyUnicode_FromString("value");
3354-
if (value == NULL) {
3355-
goto error;
3356-
}
3357-
3358-
// test PyDict_SetItem()
3359-
Py_ssize_t key_refcnt = Py_REFCNT(key);
3360-
Py_ssize_t value_refcnt = Py_REFCNT(value);
3361-
res = PyDict_SetItem(dict, key, value);
3362-
if (res < 0) {
3363-
goto error;
3364-
}
3365-
assert(res == 0);
3366-
assert(Py_REFCNT(key) == (key_refcnt + 1));
3367-
assert(Py_REFCNT(value) == (value_refcnt + 1));
3368-
3369-
// test PyDict_SetItemString()
3370-
res = PyDict_SetItemString(dict, "key", value);
3371-
if (res < 0) {
3372-
goto error;
3373-
}
3374-
assert(res == 0);
3375-
assert(Py_REFCNT(key) == (key_refcnt + 1));
3376-
assert(Py_REFCNT(value) == (value_refcnt + 1));
3377-
3378-
// test PyDict_Size()
3379-
assert(PyDict_Size(dict) == 1);
3380-
3381-
// test PyDict_Contains(), key is present
3382-
assert(PyDict_Contains(dict, key) == 1);
3383-
3384-
// test PyDict_GetItem(), key is present
3385-
assert(PyDict_GetItem(dict, key) == value);
3386-
3387-
// test PyDict_GetItemString(), key is present
3388-
assert(PyDict_GetItemString(dict, "key") == value);
3389-
3390-
// test PyDict_GetItemWithError(), key is present
3391-
assert(PyDict_GetItemWithError(dict, key) == value);
3392-
assert(!PyErr_Occurred());
3393-
3394-
// test PyDict_GetItemRef(), key is present
3395-
PyObject *get_value = Py_Ellipsis; // marker value
3396-
assert(PyDict_GetItemRef(dict, key, &get_value) == 1);
3397-
assert(get_value == value);
3398-
Py_DECREF(get_value);
3399-
3400-
// test PyDict_GetItemStringRef(), key is present
3401-
get_value = Py_Ellipsis; // marker value
3402-
assert(PyDict_GetItemStringRef(dict, "key", &get_value) == 1);
3403-
assert(get_value == value);
3404-
Py_DECREF(get_value);
3405-
3406-
// test PyDict_Contains(), missing key
3407-
assert(PyDict_Contains(dict, missing_key) == 0);
3408-
3409-
// test PyDict_GetItem(), missing key
3410-
assert(PyDict_GetItem(dict, missing_key) == NULL);
3411-
assert(!PyErr_Occurred());
3412-
3413-
// test PyDict_GetItemString(), missing key
3414-
assert(PyDict_GetItemString(dict, "missing_key") == NULL);
3415-
assert(!PyErr_Occurred());
3416-
3417-
// test PyDict_GetItemWithError(), missing key
3418-
assert(PyDict_GetItem(dict, missing_key) == NULL);
3419-
assert(!PyErr_Occurred());
3420-
3421-
// test PyDict_GetItemRef(), missing key
3422-
get_value = Py_Ellipsis; // marker value
3423-
assert(PyDict_GetItemRef(dict, missing_key, &get_value) == 0);
3424-
assert(!PyErr_Occurred());
3425-
assert(get_value == NULL);
3426-
3427-
// test PyDict_GetItemStringRef(), missing key
3428-
get_value = Py_Ellipsis; // marker value
3429-
assert(PyDict_GetItemStringRef(dict, "missing_key", &get_value) == 0);
3430-
assert(!PyErr_Occurred());
3431-
assert(get_value == NULL);
3432-
3433-
// test PyDict_GetItem(), invalid dict
3434-
PyObject *invalid_dict = key; // borrowed reference
3435-
assert(PyDict_GetItem(invalid_dict, key) == NULL);
3436-
assert(!PyErr_Occurred());
3437-
3438-
// test PyDict_GetItemWithError(), invalid dict
3439-
assert(PyDict_GetItemWithError(invalid_dict, key) == NULL);
3440-
assert(PyErr_ExceptionMatches(PyExc_SystemError));
3441-
PyErr_Clear();
3442-
3443-
// test PyDict_GetItemRef(), invalid dict
3444-
get_value = Py_Ellipsis; // marker value
3445-
assert(PyDict_GetItemRef(invalid_dict, key, &get_value) == -1);
3446-
assert(PyErr_ExceptionMatches(PyExc_SystemError));
3447-
PyErr_Clear();
3448-
assert(get_value == NULL);
3449-
3450-
// test PyDict_GetItemStringRef(), invalid dict
3451-
get_value = Py_Ellipsis; // marker value
3452-
assert(PyDict_GetItemStringRef(invalid_dict, "key", &get_value) == -1);
3453-
assert(PyErr_ExceptionMatches(PyExc_SystemError));
3454-
PyErr_Clear();
3455-
assert(get_value == NULL);
3456-
3457-
invalid_key = PyList_New(0);
3458-
if (invalid_key == NULL) {
3459-
goto error;
3460-
}
3461-
3462-
// test PyDict_Contains(), invalid key
3463-
assert(PyDict_Contains(dict, invalid_key) == -1);
3464-
assert(PyErr_ExceptionMatches(PyExc_TypeError));
3465-
PyErr_Clear();
3466-
3467-
// test PyDict_GetItem(), invalid key
3468-
assert(PyDict_GetItem(dict, invalid_key) == NULL);
3469-
assert(!PyErr_Occurred());
3470-
3471-
// test PyDict_GetItemWithError(), invalid key
3472-
assert(PyDict_GetItemWithError(dict, invalid_key) == NULL);
3473-
assert(PyErr_ExceptionMatches(PyExc_TypeError));
3474-
PyErr_Clear();
3475-
3476-
// test PyDict_GetItemRef(), invalid key
3477-
get_value = Py_Ellipsis; // marker value
3478-
assert(PyDict_GetItemRef(dict, invalid_key, &get_value) == -1);
3479-
assert(PyErr_ExceptionMatches(PyExc_TypeError));
3480-
PyErr_Clear();
3481-
assert(get_value == NULL);
3482-
3483-
// test PyDict_DelItem(), key is present
3484-
assert(PyDict_DelItem(dict, key) == 0);
3485-
assert(PyDict_Size(dict) == 0);
3486-
3487-
// test PyDict_DelItem(), missing key
3488-
assert(PyDict_DelItem(dict, missing_key) == -1);
3489-
assert(PyErr_ExceptionMatches(PyExc_KeyError));
3490-
PyErr_Clear();
3491-
3492-
// test PyDict_DelItem(), invalid key
3493-
assert(PyDict_DelItem(dict, invalid_key) == -1);
3494-
assert(PyErr_ExceptionMatches(PyExc_TypeError));
3495-
PyErr_Clear();
3496-
3497-
// test PyDict_Clear()
3498-
PyDict_Clear(dict);
3499-
3500-
Py_DECREF(dict);
3501-
Py_DECREF(key);
3502-
Py_DECREF(missing_key);
3503-
Py_DECREF(value);
3504-
Py_DECREF(invalid_key);
3505-
3506-
Py_RETURN_NONE;
3507-
3508-
error:
3509-
Py_XDECREF(dict);
3510-
Py_XDECREF(key);
3511-
Py_XDECREF(missing_key);
3512-
Py_XDECREF(value);
3513-
Py_XDECREF(invalid_key);
3514-
return NULL;
3515-
}
3516-
3517-
35183328
static PyObject *
35193329
sys_getobject(PyObject *Py_UNUSED(module), PyObject *arg)
35203330
{
@@ -3678,7 +3488,6 @@ static PyMethodDef TestMethods[] = {
36783488
{"function_set_kw_defaults", function_set_kw_defaults, METH_VARARGS, NULL},
36793489
{"check_pyimport_addmodule", check_pyimport_addmodule, METH_VARARGS},
36803490
{"test_weakref_capi", test_weakref_capi, METH_NOARGS},
3681-
{"test_dict_capi", test_dict_capi, METH_NOARGS},
36823491
{"sys_getobject", sys_getobject, METH_O},
36833492
{"sys_setobject", sys_setobject, METH_VARARGS},
36843493
{NULL, NULL} /* sentinel */

0 commit comments

Comments
 (0)