Skip to content

Commit

Permalink
[3.11] gh-106368: Increase coverage for Argument Clinic output direct…
Browse files Browse the repository at this point in the history
…ive (GH-106979) (#107002)

(cherry picked from commit ee5c01b)

Co-authored-by: Erlend E. Aasland <[email protected]>
  • Loading branch information
ambv and erlend-aasland authored Jul 22, 2023
1 parent 4f7c23e commit 06f8a43
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,68 @@ def test_cpp_monitor_fail_no_matching_if(self):
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]
destination buffer nosuchcommand
[clinic start generated code]*/
""")
msg = "unknown destination command 'nosuchcommand'"
self.assertIn(msg, out)


class ClinicGroupPermuterTest(TestCase):
def _test(self, l, m, r, output):
Expand Down

0 comments on commit 06f8a43

Please sign in to comment.