Skip to content

Commit

Permalink
pythongh-64631: Test exception messages in cloned Argument Clinic funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
erlend-aasland committed May 4, 2023
1 parent b0ce2db commit 4a4e328
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,13 @@ def test_gh_99240_double_free(self):
with self.assertRaisesRegex(TypeError, expected_error):
ac_tester.gh_99240_double_free('a', '\0b')

def test_cloned_func_exception_message(self):
incorrect_arg = -1 # f1() and f2() accept a single str
with self.assertRaisesRegex(TypeError, "clone_f1"):
ac_tester.clone_f1(incorrect_arg)
with self.assertRaisesRegex(TypeError, "clone_f2"):
ac_tester.clone_f2(incorrect_arg)


if __name__ == "__main__":
unittest.main()
29 changes: 29 additions & 0 deletions Modules/_testclinic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,33 @@ gh_99240_double_free_impl(PyObject *module, char *a, char *b)
}


/*[clinic input]
_testclinic.clone_f1 as clone_f1
path: str
[clinic start generated code]*/

static PyObject *
clone_f1_impl(PyObject *module, const char *path)
/*[clinic end generated code: output=8c30b5620ba86715 input=c956032414f389b4]*/
{
Py_RETURN_NONE;
}


/*[clinic input]
_testclinic.clone_f2 as clone_f2 = _testclinic.clone_f1
[clinic start generated code]*/

static PyObject *
clone_f2_impl(PyObject *module, const char *path)
/*[clinic end generated code: output=6aa1c39bec3f5d9b input=cf854c3ad41ddd85]*/
{
Py_RETURN_NONE;
}


static PyMethodDef tester_methods[] = {
TEST_EMPTY_FUNCTION_METHODDEF
OBJECTS_CONVERTER_METHODDEF
Expand Down Expand Up @@ -1168,6 +1195,8 @@ static PyMethodDef tester_methods[] = {
GH_32092_KW_PASS_METHODDEF
GH_99233_REFCOUNT_METHODDEF
GH_99240_DOUBLE_FREE_METHODDEF
CLONE_F1_METHODDEF
CLONE_F2_METHODDEF
{NULL, NULL}
};

Expand Down
134 changes: 133 additions & 1 deletion Modules/clinic/_testclinic.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4a4e328

Please sign in to comment.