gh-94808: add tests covering `PyEval_GetFuncDesc` function (GH-98300)

This commit is contained in:
Nikita Sobolev 2022-11-05 16:07:59 +03:00 committed by GitHub
parent 12078e78f6
commit b5f711185b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -907,6 +907,21 @@ class CAPITest(unittest.TestCase):
self.assertEqual(_testcapi.eval_get_func_name(sum), "sum") # c function
self.assertEqual(_testcapi.eval_get_func_name(A), "type")
def test_eval_get_func_desc(self):
def function_example(): ...
class A:
def method_example(self): ...
self.assertEqual(_testcapi.eval_get_func_desc(function_example),
"()")
self.assertEqual(_testcapi.eval_get_func_desc(A.method_example),
"()")
self.assertEqual(_testcapi.eval_get_func_desc(A().method_example),
"()")
self.assertEqual(_testcapi.eval_get_func_desc(sum), "()") # c function
self.assertEqual(_testcapi.eval_get_func_desc(A), " object")
def test_function_get_code(self):
import types

View File

@ -5579,6 +5579,12 @@ eval_get_func_name(PyObject *self, PyObject *func)
return PyUnicode_FromString(PyEval_GetFuncName(func));
}
static PyObject *
eval_get_func_desc(PyObject *self, PyObject *func)
{
return PyUnicode_FromString(PyEval_GetFuncDesc(func));
}
static PyObject *
get_feature_macros(PyObject *self, PyObject *Py_UNUSED(args))
{
@ -6226,6 +6232,7 @@ static PyMethodDef TestMethods[] = {
{"frame_getbuiltins", frame_getbuiltins, METH_O, NULL},
{"frame_getlasti", frame_getlasti, METH_O, NULL},
{"eval_get_func_name", eval_get_func_name, METH_O, NULL},
{"eval_get_func_desc", eval_get_func_desc, METH_O, NULL},
{"get_feature_macros", get_feature_macros, METH_NOARGS, NULL},
{"test_code_api", test_code_api, METH_NOARGS, NULL},
{"settrace_to_record", settrace_to_record, METH_O, NULL},