Skip to content

Commit ee5c01b

Browse files
gh-106368: Increase coverage for Argument Clinic output directive (#106979)
1 parent 443d9b3 commit ee5c01b

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

Lib/test/test_clinic.py

+53
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,59 @@ def test_cpp_monitor_fail_no_matching_if(self):
249249
out = self.expect_failure(raw)
250250
self.assertEqual(out, msg)
251251

252+
def test_directive_output_unknown_preset(self):
253+
out = self.expect_failure("""
254+
/*[clinic input]
255+
output preset nosuchpreset
256+
[clinic start generated code]*/
257+
""")
258+
msg = "Unknown preset 'nosuchpreset'"
259+
self.assertIn(msg, out)
260+
261+
def test_directive_output_cant_pop(self):
262+
out = self.expect_failure("""
263+
/*[clinic input]
264+
output pop
265+
[clinic start generated code]*/
266+
""")
267+
msg = "Can't 'output pop', stack is empty"
268+
self.assertIn(msg, out)
269+
270+
def test_directive_output_print(self):
271+
raw = dedent("""
272+
/*[clinic input]
273+
output print 'I told you once.'
274+
[clinic start generated code]*/
275+
""")
276+
out = self.clinic.parse(raw)
277+
# The generated output will differ for every run, but we can check that
278+
# it starts with the clinic block, we check that it contains all the
279+
# expected fields, and we check that it contains the checksum line.
280+
self.assertTrue(out.startswith(dedent("""
281+
/*[clinic input]
282+
output print 'I told you once.'
283+
[clinic start generated code]*/
284+
""")))
285+
fields = {
286+
"cpp_endif",
287+
"cpp_if",
288+
"docstring_definition",
289+
"docstring_prototype",
290+
"impl_definition",
291+
"impl_prototype",
292+
"methoddef_define",
293+
"methoddef_ifndef",
294+
"parser_definition",
295+
"parser_prototype",
296+
}
297+
for field in fields:
298+
with self.subTest(field=field):
299+
self.assertIn(field, out)
300+
last_line = out.rstrip().split("\n")[-1]
301+
self.assertTrue(
302+
last_line.startswith("/*[clinic end generated code: output=")
303+
)
304+
252305
def test_unknown_destination_command(self):
253306
out = self.expect_failure("""
254307
/*[clinic input]

0 commit comments

Comments
 (0)