Skip to content

Commit 06f8a43

Browse files
ambverlend-aasland
andauthored
[3.11] gh-106368: Increase coverage for Argument Clinic output directive (GH-106979) (#107002)
(cherry picked from commit ee5c01b) Co-authored-by: Erlend E. Aasland <erlend@python.org>
1 parent 4f7c23e commit 06f8a43

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

Lib/test/test_clinic.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,68 @@ 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+
305+
def test_unknown_destination_command(self):
306+
out = self.expect_failure("""
307+
/*[clinic input]
308+
destination buffer nosuchcommand
309+
[clinic start generated code]*/
310+
""")
311+
msg = "unknown destination command 'nosuchcommand'"
312+
self.assertIn(msg, out)
313+
252314

253315
class ClinicGroupPermuterTest(TestCase):
254316
def _test(self, l, m, r, output):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy