@@ -161,11 +161,8 @@ def test_checksum_mismatch(self):
161
161
[clinic start generated code]*/
162
162
/*[clinic end generated code: output=0123456789abcdef input=fedcba9876543210]*/
163
163
"""
164
- err = (
165
- 'Checksum mismatch!\n '
166
- 'Expected: 0123456789abcdef\n '
167
- 'Computed: da39a3ee5e6b4b0d\n '
168
- )
164
+ err = ("Checksum mismatch! "
165
+ "Expected '0123456789abcdef', computed 'da39a3ee5e6b4b0d'" )
169
166
self .expect_failure (raw , err , filename = "test.c" , lineno = 3 )
170
167
171
168
def test_garbage_after_stop_line (self ):
@@ -403,7 +400,7 @@ def test_clone_mismatch(self):
403
400
self .expect_failure (block , err , lineno = 9 )
404
401
405
402
def test_badly_formed_return_annotation (self ):
406
- err = "Badly formed annotation for m.f: 'Custom'"
403
+ err = "Badly formed annotation for ' m.f' : 'Custom'"
407
404
block = """
408
405
/*[python input]
409
406
class Custom_return_converter(CReturnConverter):
@@ -509,6 +506,15 @@ def test_dest_buffer_not_empty_at_eof(self):
509
506
self .assertIn (expected_warning , stdout .getvalue ())
510
507
self .assertEqual (generated , expected_generated )
511
508
509
+ def test_dest_clear (self ):
510
+ err = "Can't clear destination 'file': it's not of type 'buffer'"
511
+ block = """
512
+ /*[clinic input]
513
+ destination file clear
514
+ [clinic start generated code]*/
515
+ """
516
+ self .expect_failure (block , err , lineno = 2 )
517
+
512
518
def test_directive_set_misuse (self ):
513
519
err = "unknown variable 'ets'"
514
520
block = """
@@ -598,7 +604,7 @@ def test_directive_printout(self):
598
604
self .assertEqual (generated , expected )
599
605
600
606
def test_directive_preserve_twice (self ):
601
- err = "Can't have preserve twice in one block!"
607
+ err = "Can't have ' preserve' twice in one block!"
602
608
block = """
603
609
/*[clinic input]
604
610
preserve
@@ -637,13 +643,24 @@ def test_directive_preserve_output(self):
637
643
self .assertEqual (generated , block )
638
644
639
645
def test_directive_output_invalid_command (self ):
640
- err = (
641
- "Invalid command / destination name 'cmd', must be one of:\n "
642
- " preset push pop print everything cpp_if docstring_prototype "
643
- "docstring_definition methoddef_define impl_prototype "
644
- "parser_prototype parser_definition cpp_endif methoddef_ifndef "
645
- "impl_definition"
646
- )
646
+ err = dedent ("""
647
+ Invalid command or destination name 'cmd'. Must be one of:
648
+ - 'preset'
649
+ - 'push'
650
+ - 'pop'
651
+ - 'print'
652
+ - 'everything'
653
+ - 'cpp_if'
654
+ - 'docstring_prototype'
655
+ - 'docstring_definition'
656
+ - 'methoddef_define'
657
+ - 'impl_prototype'
658
+ - 'parser_prototype'
659
+ - 'parser_definition'
660
+ - 'cpp_endif'
661
+ - 'methoddef_ifndef'
662
+ - 'impl_definition'
663
+ """ ).strip ()
647
664
block = """
648
665
/*[clinic input]
649
666
output cmd buffer
@@ -919,7 +936,7 @@ def test_param_default_expr_named_constant(self):
919
936
self .assertEqual ("MAXSIZE" , p .converter .c_default )
920
937
921
938
err = (
922
- "When you specify a named constant ('sys.maxsize') as your default value,\n "
939
+ "When you specify a named constant ('sys.maxsize') as your default value, "
923
940
"you MUST specify a valid c_default."
924
941
)
925
942
block = """
@@ -931,7 +948,7 @@ def test_param_default_expr_named_constant(self):
931
948
932
949
def test_param_default_expr_binop (self ):
933
950
err = (
934
- "When you specify an expression ('a + b') as your default value,\n "
951
+ "When you specify an expression ('a + b') as your default value, "
935
952
"you MUST specify a valid c_default."
936
953
)
937
954
block = """
@@ -954,7 +971,7 @@ def test_param_no_docstring(self):
954
971
955
972
def test_param_default_parameters_out_of_order (self ):
956
973
err = (
957
- "Can't have a parameter without a default ('something_else')\n "
974
+ "Can't have a parameter without a default ('something_else') "
958
975
"after a parameter with a default!"
959
976
)
960
977
block = """
@@ -1088,7 +1105,7 @@ def test_return_converter_invalid_syntax(self):
1088
1105
module os
1089
1106
os.stat -> invalid syntax
1090
1107
"""
1091
- err = "Badly formed annotation for os.stat: 'invalid syntax'"
1108
+ err = "Badly formed annotation for ' os.stat' : 'invalid syntax'"
1092
1109
self .expect_failure (block , err )
1093
1110
1094
1111
def test_legacy_converter_disallowed_in_return_annotation (self ):
@@ -1252,8 +1269,8 @@ def test_nested_groups(self):
1252
1269
1253
1270
def test_disallowed_grouping__two_top_groups_on_left (self ):
1254
1271
err = (
1255
- ' Function two_top_groups_on_left has an unsupported group '
1256
- ' configuration. (Unexpected state 2.b)'
1272
+ " Function ' two_top_groups_on_left' has an unsupported group "
1273
+ " configuration. (Unexpected state 2.b)"
1257
1274
)
1258
1275
block = """
1259
1276
module foo
@@ -1281,7 +1298,7 @@ def test_disallowed_grouping__two_top_groups_on_right(self):
1281
1298
]
1282
1299
"""
1283
1300
err = (
1284
- "Function two_top_groups_on_right has an unsupported group "
1301
+ "Function ' two_top_groups_on_right' has an unsupported group "
1285
1302
"configuration. (Unexpected state 6.b)"
1286
1303
)
1287
1304
self .expect_failure (block , err )
@@ -1317,7 +1334,7 @@ def test_disallowed_grouping__group_after_parameter_on_left(self):
1317
1334
param: int
1318
1335
"""
1319
1336
err = (
1320
- "Function group_after_parameter_on_left has an unsupported group "
1337
+ "Function ' group_after_parameter_on_left' has an unsupported group "
1321
1338
"configuration. (Unexpected state 2.b)"
1322
1339
)
1323
1340
self .expect_failure (block , err )
@@ -1334,7 +1351,7 @@ def test_disallowed_grouping__empty_group_on_left(self):
1334
1351
param: int
1335
1352
"""
1336
1353
err = (
1337
- "Function empty_group has an empty group.\n "
1354
+ "Function ' empty_group' has an empty group. "
1338
1355
"All groups must contain at least one parameter."
1339
1356
)
1340
1357
self .expect_failure (block , err )
@@ -1351,7 +1368,7 @@ def test_disallowed_grouping__empty_group_on_right(self):
1351
1368
]
1352
1369
"""
1353
1370
err = (
1354
- "Function empty_group has an empty group.\n "
1371
+ "Function ' empty_group' has an empty group. "
1355
1372
"All groups must contain at least one parameter."
1356
1373
)
1357
1374
self .expect_failure (block , err )
@@ -1365,7 +1382,7 @@ def test_disallowed_grouping__no_matching_bracket(self):
1365
1382
group2: int
1366
1383
]
1367
1384
"""
1368
- err = "Function empty_group has a ] without a matching [. "
1385
+ err = "Function ' empty_group' has a ']' without a matching '[' "
1369
1386
self .expect_failure (block , err )
1370
1387
1371
1388
def test_no_parameters (self ):
@@ -1400,7 +1417,7 @@ def test_illegal_module_line(self):
1400
1417
foo.bar => int
1401
1418
/
1402
1419
"""
1403
- err = "Illegal function name: foo.bar => int"
1420
+ err = "Illegal function name: ' foo.bar => int' "
1404
1421
self .expect_failure (block , err )
1405
1422
1406
1423
def test_illegal_c_basename (self ):
@@ -1409,7 +1426,7 @@ def test_illegal_c_basename(self):
1409
1426
foo.bar as 935
1410
1427
/
1411
1428
"""
1412
- err = "Illegal C basename: 935"
1429
+ err = "Illegal C basename: ' 935' "
1413
1430
self .expect_failure (block , err )
1414
1431
1415
1432
def test_single_star (self ):
@@ -1419,7 +1436,7 @@ def test_single_star(self):
1419
1436
*
1420
1437
*
1421
1438
"""
1422
- err = "Function bar uses '*' more than once."
1439
+ err = "Function ' bar' uses '*' more than once."
1423
1440
self .expect_failure (block , err )
1424
1441
1425
1442
def test_parameters_required_after_star (self ):
@@ -1429,7 +1446,7 @@ def test_parameters_required_after_star(self):
1429
1446
"module foo\n foo.bar\n this: int\n *" ,
1430
1447
"module foo\n foo.bar\n this: int\n *\n Docstring." ,
1431
1448
)
1432
- err = "Function bar specifies '*' without any parameters afterwards."
1449
+ err = "Function ' bar' specifies '*' without any parameters afterwards."
1433
1450
for block in dataset :
1434
1451
with self .subTest (block = block ):
1435
1452
self .expect_failure (block , err )
@@ -1442,7 +1459,7 @@ def test_single_slash(self):
1442
1459
/
1443
1460
"""
1444
1461
err = (
1445
- "Function bar has an unsupported group configuration. "
1462
+ "Function ' bar' has an unsupported group configuration. "
1446
1463
"(Unexpected state 0.d)"
1447
1464
)
1448
1465
self .expect_failure (block , err )
@@ -1456,7 +1473,7 @@ def test_double_slash(self):
1456
1473
b: int
1457
1474
/
1458
1475
"""
1459
- err = "Function bar uses '/' more than once."
1476
+ err = "Function ' bar' uses '/' more than once."
1460
1477
self .expect_failure (block , err )
1461
1478
1462
1479
def test_mix_star_and_slash (self ):
@@ -1470,7 +1487,7 @@ def test_mix_star_and_slash(self):
1470
1487
/
1471
1488
"""
1472
1489
err = (
1473
- "Function bar mixes keyword-only and positional-only parameters, "
1490
+ "Function ' bar' mixes keyword-only and positional-only parameters, "
1474
1491
"which is unsupported."
1475
1492
)
1476
1493
self .expect_failure (block , err )
@@ -1483,7 +1500,7 @@ def test_parameters_not_permitted_after_slash_for_now(self):
1483
1500
x: int
1484
1501
"""
1485
1502
err = (
1486
- "Function bar has an unsupported group configuration. "
1503
+ "Function ' bar' has an unsupported group configuration. "
1487
1504
"(Unexpected state 0.d)"
1488
1505
)
1489
1506
self .expect_failure (block , err )
@@ -1582,7 +1599,8 @@ def test_indent_stack_no_tabs(self):
1582
1599
*vararg1: object
1583
1600
\t *vararg2: object
1584
1601
"""
1585
- err = "Tab characters are illegal in the Clinic DSL."
1602
+ err = ("Tab characters are illegal in the Clinic DSL: "
1603
+ r"'\t*vararg2: object'" )
1586
1604
self .expect_failure (block , err )
1587
1605
1588
1606
def test_indent_stack_illegal_outdent (self ):
@@ -1841,16 +1859,25 @@ def test_vararg_cannot_take_default_value(self):
1841
1859
"""
1842
1860
self .expect_failure (block , err , lineno = 1 )
1843
1861
1862
+ def test_default_is_not_of_correct_type (self ):
1863
+ err = ("int_converter: default value 2.5 for field 'a' "
1864
+ "is not of type 'int'" )
1865
+ block = """
1866
+ fn
1867
+ a: int = 2.5
1868
+ """
1869
+ self .expect_failure (block , err , lineno = 1 )
1870
+
1844
1871
def test_invalid_legacy_converter (self ):
1845
- err = "fhi is not a valid legacy converter"
1872
+ err = "' fhi' is not a valid legacy converter"
1846
1873
block = """
1847
1874
fn
1848
1875
a: 'fhi'
1849
1876
"""
1850
1877
self .expect_failure (block , err , lineno = 1 )
1851
1878
1852
1879
def test_parent_class_or_module_does_not_exist (self ):
1853
- err = "Parent class or module z does not exist"
1880
+ err = "Parent class or module 'z' does not exist"
1854
1881
block = """
1855
1882
module m
1856
1883
z.func
@@ -1877,7 +1904,7 @@ def test_param_requires_custom_c_name(self):
1877
1904
self .expect_failure (block , err , lineno = 2 )
1878
1905
1879
1906
def test_state_func_docstring_assert_no_group (self ):
1880
- err = "Function func has a ] without a matching [. "
1907
+ err = "Function ' func' has a ']' without a matching '[' "
1881
1908
block = """
1882
1909
module m
1883
1910
m.func
@@ -1887,7 +1914,7 @@ def test_state_func_docstring_assert_no_group(self):
1887
1914
self .expect_failure (block , err , lineno = 2 )
1888
1915
1889
1916
def test_state_func_docstring_no_summary (self ):
1890
- err = "Docstring for m.func does not have a summary line!"
1917
+ err = "Docstring for ' m.func' does not have a summary line!"
1891
1918
block = """
1892
1919
module m
1893
1920
m.func
@@ -1983,13 +2010,11 @@ def test_cli_force(self):
1983
2010
const char *hand_edited = "output block is overwritten";
1984
2011
/*[clinic end generated code: output=bogus input=bogus]*/
1985
2012
""" )
1986
- fail_msg = dedent ("""
1987
- Checksum mismatch!
1988
- Expected: bogus
1989
- Computed: 2ed19
1990
- Suggested fix: remove all generated code including the end marker,
1991
- or use the '-f' option.
1992
- """ )
2013
+ fail_msg = (
2014
+ "Checksum mismatch! Expected 'bogus', computed '2ed19'. "
2015
+ "Suggested fix: remove all generated code including the end marker, "
2016
+ "or use the '-f' option.\n "
2017
+ )
1993
2018
with os_helper .temp_dir () as tmp_dir :
1994
2019
fn = os .path .join (tmp_dir , "test.c" )
1995
2020
with open (fn , "w" , encoding = "utf-8" ) as f :
@@ -2214,7 +2239,7 @@ def test_file_dest(self):
2214
2239
f .write ("" ) # Write an empty output file!
2215
2240
# Clinic should complain about the empty output file.
2216
2241
_ , err = self .expect_failure (in_fn )
2217
- expected_err = (f"Modified destination file { out_fn !r} , "
2242
+ expected_err = (f"Modified destination file { out_fn !r} ; "
2218
2243
"not overwriting!" )
2219
2244
self .assertIn (expected_err , err )
2220
2245
# Run clinic again, this time with the -f option.
0 commit comments