diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-07-22 10:48:35 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-22 10:48:35 (GMT) |
commit | 76fd98a675d0c1a4f61735f9038e1f8282b60177 (patch) | |
tree | 60c417c345ea0fad36181ba96d07471b135c0fdf /Lib/test | |
parent | 67748f18c9b53def23f7614759fb632165f50d6a (diff) | |
download | cpython-76fd98a675d0c1a4f61735f9038e1f8282b60177.zip cpython-76fd98a675d0c1a4f61735f9038e1f8282b60177.tar.gz cpython-76fd98a675d0c1a4f61735f9038e1f8282b60177.tar.bz2 |
[3.12] gh-106368: Increase coverage for Argument Clinic output directive (GH-106979) (#106994)
(cherry picked from commit ee5c01b473eeadb007b9f330db3143e34e46038b)
Co-authored-by: Erlend E. Aasland <erlend@python.org>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_clinic.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index e40579b..c24b8cd 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -249,6 +249,59 @@ class ClinicWholeFileTest(_ParserBase): out = self.expect_failure(raw) self.assertEqual(out, msg) + def test_directive_output_unknown_preset(self): + out = self.expect_failure(""" + /*[clinic input] + output preset nosuchpreset + [clinic start generated code]*/ + """) + msg = "Unknown preset 'nosuchpreset'" + self.assertIn(msg, out) + + def test_directive_output_cant_pop(self): + out = self.expect_failure(""" + /*[clinic input] + output pop + [clinic start generated code]*/ + """) + msg = "Can't 'output pop', stack is empty" + self.assertIn(msg, out) + + def test_directive_output_print(self): + raw = dedent(""" + /*[clinic input] + output print 'I told you once.' + [clinic start generated code]*/ + """) + out = self.clinic.parse(raw) + # The generated output will differ for every run, but we can check that + # it starts with the clinic block, we check that it contains all the + # expected fields, and we check that it contains the checksum line. + self.assertTrue(out.startswith(dedent(""" + /*[clinic input] + output print 'I told you once.' + [clinic start generated code]*/ + """))) + fields = { + "cpp_endif", + "cpp_if", + "docstring_definition", + "docstring_prototype", + "impl_definition", + "impl_prototype", + "methoddef_define", + "methoddef_ifndef", + "parser_definition", + "parser_prototype", + } + for field in fields: + with self.subTest(field=field): + self.assertIn(field, out) + last_line = out.rstrip().split("\n")[-1] + self.assertTrue( + last_line.startswith("/*[clinic end generated code: output=") + ) + def test_unknown_destination_command(self): out = self.expect_failure(""" /*[clinic input] |