summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHai Shi <shihai1992@gmail.com>2021-08-17 14:50:33 (GMT)
committerGitHub <noreply@github.com>2021-08-17 14:50:33 (GMT)
commitfcd651d16fc5ac3d07dd3f57f1001a861a2e7d23 (patch)
tree105c92579c29eadfed977951e2669259ee6d757d
parent3e2c643ae0b21f9e596bfd9c8ec99ca546ea8d0f (diff)
downloadcpython-fcd651d16fc5ac3d07dd3f57f1001a861a2e7d23.zip
cpython-fcd651d16fc5ac3d07dd3f57f1001a861a2e7d23.tar.gz
cpython-fcd651d16fc5ac3d07dd3f57f1001a861a2e7d23.tar.bz2
bpo-42035: Enhance test_get_type_name() of _testcapi (GH-27649)
-rw-r--r--Modules/_testcapimodule.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 0a3c6e0..e5f1ad3 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -1154,6 +1154,20 @@ test_get_type_name(PyObject *self, PyObject *Py_UNUSED(ignored))
assert(strcmp(PyUnicode_AsUTF8(tp_name), "HeapTypeNameType") == 0);
Py_DECREF(tp_name);
+ PyObject *name = PyUnicode_FromString("test_name");
+ if (name == NULL) {
+ goto done;
+ }
+ if (PyObject_SetAttrString(HeapTypeNameType, "__name__", name) < 0) {
+ Py_DECREF(name);
+ goto done;
+ }
+ tp_name = PyType_GetName((PyTypeObject *)HeapTypeNameType);
+ assert(strcmp(PyUnicode_AsUTF8(tp_name), "test_name") == 0);
+ Py_DECREF(name);
+ Py_DECREF(tp_name);
+
+ done:
Py_DECREF(HeapTypeNameType);
Py_RETURN_NONE;
}