Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 00437ad

Browse files
gh-93649: Split memory and docstring tests from _testcapimodule.c (#99517)
1 parent 33f42c2 commit 00437ad

File tree

7 files changed

+767
-671
lines changed

7 files changed

+767
-671
lines changed

Modules/Setup.stdlib.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
@MODULE__XXTESTFUZZ_TRUE@_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
170170
@MODULE__TESTBUFFER_TRUE@_testbuffer _testbuffer.c
171171
@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c
172-
@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/vectorcall_limited.c _testcapi/heaptype.c _testcapi/unicode.c _testcapi/getargs.c _testcapi/pytime.c _testcapi/datetime.c
172+
@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/vectorcall_limited.c _testcapi/heaptype.c _testcapi/unicode.c _testcapi/getargs.c _testcapi/pytime.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c
173173

174174
# Some testing modules MUST be built as shared libraries.
175175
*shared*

Modules/_testcapi/docstring.c

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#include "parts.h"
2+
3+
4+
PyDoc_STRVAR(docstring_empty,
5+
""
6+
);
7+
8+
PyDoc_STRVAR(docstring_no_signature,
9+
"This docstring has no signature."
10+
);
11+
12+
PyDoc_STRVAR(docstring_with_invalid_signature,
13+
"docstring_with_invalid_signature($module, /, boo)\n"
14+
"\n"
15+
"This docstring has an invalid signature."
16+
);
17+
18+
PyDoc_STRVAR(docstring_with_invalid_signature2,
19+
"docstring_with_invalid_signature2($module, /, boo)\n"
20+
"\n"
21+
"--\n"
22+
"\n"
23+
"This docstring also has an invalid signature."
24+
);
25+
26+
PyDoc_STRVAR(docstring_with_signature,
27+
"docstring_with_signature($module, /, sig)\n"
28+
"--\n"
29+
"\n"
30+
"This docstring has a valid signature."
31+
);
32+
33+
PyDoc_STRVAR(docstring_with_signature_but_no_doc,
34+
"docstring_with_signature_but_no_doc($module, /, sig)\n"
35+
"--\n"
36+
"\n"
37+
);
38+
39+
PyDoc_STRVAR(docstring_with_signature_and_extra_newlines,
40+
"docstring_with_signature_and_extra_newlines($module, /, parameter)\n"
41+
"--\n"
42+
"\n"
43+
"\n"
44+
"This docstring has a valid signature and some extra newlines."
45+
);
46+
47+
PyDoc_STRVAR(docstring_with_signature_with_defaults,
48+
"docstring_with_signature_with_defaults(module, s='avocado',\n"
49+
" b=b'bytes', d=3.14, i=35, n=None, t=True, f=False,\n"
50+
" local=the_number_three, sys=sys.maxsize,\n"
51+
" exp=sys.maxsize - 1)\n"
52+
"--\n"
53+
"\n"
54+
"\n"
55+
"\n"
56+
"This docstring has a valid signature with parameters,\n"
57+
"and the parameters take defaults of varying types."
58+
);
59+
60+
/* This is here to provide a docstring for test_descr. */
61+
static PyObject *
62+
test_with_docstring(PyObject *self, PyObject *Py_UNUSED(ignored))
63+
{
64+
Py_RETURN_NONE;
65+
}
66+
67+
static PyMethodDef test_methods[] = {
68+
{"docstring_empty",
69+
(PyCFunction)test_with_docstring, METH_NOARGS,
70+
docstring_empty},
71+
{"docstring_no_signature",
72+
(PyCFunction)test_with_docstring, METH_NOARGS,
73+
docstring_no_signature},
74+
{"docstring_with_invalid_signature",
75+
(PyCFunction)test_with_docstring, METH_NOARGS,
76+
docstring_with_invalid_signature},
77+
{"docstring_with_invalid_signature2",
78+
(PyCFunction)test_with_docstring, METH_NOARGS,
79+
docstring_with_invalid_signature2},
80+
{"docstring_with_signature",
81+
(PyCFunction)test_with_docstring, METH_NOARGS,
82+
docstring_with_signature},
83+
{"docstring_with_signature_and_extra_newlines",
84+
(PyCFunction)test_with_docstring, METH_NOARGS,
85+
docstring_with_signature_and_extra_newlines},
86+
{"docstring_with_signature_but_no_doc",
87+
(PyCFunction)test_with_docstring, METH_NOARGS,
88+
docstring_with_signature_but_no_doc},
89+
{"docstring_with_signature_with_defaults",
90+
(PyCFunction)test_with_docstring, METH_NOARGS,
91+
docstring_with_signature_with_defaults},
92+
{"no_docstring",
93+
(PyCFunction)test_with_docstring, METH_NOARGS},
94+
{"test_with_docstring",
95+
test_with_docstring, METH_NOARGS,
96+
PyDoc_STR("This is a pretty normal docstring.")},
97+
{NULL},
98+
};
99+
100+
int
101+
_PyTestCapi_Init_Docstring(PyObject *mod)
102+
{
103+
if (PyModule_AddFunctions(mod, test_methods) < 0) {
104+
return -1;
105+
}
106+
return 0;
107+
}

0 commit comments

Comments
 (0)