@@ -69,7 +69,7 @@ def __init__(self):
69
69
self .converters = FakeConvertersDict ()
70
70
self .legacy_converters = FakeConvertersDict ()
71
71
self .language = clinic .CLanguage (None )
72
- self .filename = None
72
+ self .filename = "clinic_tests"
73
73
self .destination_buffers = {}
74
74
self .block_parser = clinic .BlockParser ('' , self .language )
75
75
self .modules = collections .OrderedDict ()
@@ -1849,10 +1849,10 @@ def test_non_ascii_character_in_docstring(self):
1849
1849
self .parse (block )
1850
1850
# The line numbers are off; this is a known limitation.
1851
1851
expected = dedent ("""\
1852
- Warning on line 0:
1852
+ Warning in file 'clinic_tests' on line 0:
1853
1853
Non-ascii characters are not allowed in docstrings: 'á'
1854
1854
1855
- Warning on line 0:
1855
+ Warning in file 'clinic_tests' on line 0:
1856
1856
Non-ascii characters are not allowed in docstrings: 'ü', 'á', 'ß'
1857
1857
1858
1858
""" )
@@ -3030,5 +3030,93 @@ def test_suffix_all_lines(self):
3030
3030
self .assertEqual (out , expected )
3031
3031
3032
3032
3033
+ class ClinicReprTests (unittest .TestCase ):
3034
+ def test_Block_repr (self ):
3035
+ block = clinic .Block ("foo" )
3036
+ expected_repr = "<clinic.Block 'text' input='foo' output=None>"
3037
+ self .assertEqual (repr (block ), expected_repr )
3038
+
3039
+ block2 = clinic .Block ("bar" , "baz" , [], "eggs" , "spam" )
3040
+ expected_repr_2 = "<clinic.Block 'baz' input='bar' output='eggs'>"
3041
+ self .assertEqual (repr (block2 ), expected_repr_2 )
3042
+
3043
+ block3 = clinic .Block (
3044
+ input = "longboi_" * 100 ,
3045
+ dsl_name = "wow_so_long" ,
3046
+ signatures = [],
3047
+ output = "very_long_" * 100 ,
3048
+ indent = ""
3049
+ )
3050
+ expected_repr_3 = (
3051
+ "<clinic.Block 'wow_so_long' input='longboi_longboi_longboi_l...' output='very_long_very_long_very_...'>"
3052
+ )
3053
+ self .assertEqual (repr (block3 ), expected_repr_3 )
3054
+
3055
+ def test_Destination_repr (self ):
3056
+ destination = clinic .Destination (
3057
+ "foo" , type = "file" , clinic = FakeClinic (), args = ("eggs" ,)
3058
+ )
3059
+ self .assertEqual (
3060
+ repr (destination ), "<clinic.Destination 'foo' type='file' file='eggs'>"
3061
+ )
3062
+
3063
+ destination2 = clinic .Destination ("bar" , type = "buffer" , clinic = FakeClinic ())
3064
+ self .assertEqual (repr (destination2 ), "<clinic.Destination 'bar' type='buffer'>" )
3065
+
3066
+ def test_Module_repr (self ):
3067
+ module = clinic .Module ("foo" , FakeClinic ())
3068
+ self .assertRegex (repr (module ), r"<clinic.Module 'foo' at \d+>" )
3069
+
3070
+ def test_Class_repr (self ):
3071
+ cls = clinic .Class ("foo" , FakeClinic (), None , 'some_typedef' , 'some_type_object' )
3072
+ self .assertRegex (repr (cls ), r"<clinic.Class 'foo' at \d+>" )
3073
+
3074
+ def test_FunctionKind_repr (self ):
3075
+ self .assertEqual (
3076
+ repr (clinic .FunctionKind .INVALID ), "<clinic.FunctionKind.INVALID>"
3077
+ )
3078
+ self .assertEqual (
3079
+ repr (clinic .FunctionKind .CLASS_METHOD ), "<clinic.FunctionKind.CLASS_METHOD>"
3080
+ )
3081
+
3082
+ def test_Function_and_Parameter_reprs (self ):
3083
+ function = clinic .Function (
3084
+ name = 'foo' ,
3085
+ module = FakeClinic (),
3086
+ cls = None ,
3087
+ c_basename = None ,
3088
+ full_name = 'foofoo' ,
3089
+ return_converter = clinic .init_return_converter (),
3090
+ kind = clinic .FunctionKind .METHOD_INIT ,
3091
+ coexist = False
3092
+ )
3093
+ self .assertEqual (repr (function ), "<clinic.Function 'foo'>" )
3094
+
3095
+ converter = clinic .self_converter ('bar' , 'bar' , function )
3096
+ parameter = clinic .Parameter (
3097
+ "bar" ,
3098
+ kind = inspect .Parameter .POSITIONAL_OR_KEYWORD ,
3099
+ function = function ,
3100
+ converter = converter
3101
+ )
3102
+ self .assertEqual (repr (parameter ), "<clinic.Parameter 'bar'>" )
3103
+
3104
+ def test_Monitor_repr (self ):
3105
+ monitor = clinic .cpp .Monitor ()
3106
+ self .assertRegex (repr (monitor ), r"<clinic.Monitor \d+ line=0 condition=''>" )
3107
+
3108
+ monitor .line_number = 42
3109
+ monitor .stack .append (("token1" , "condition1" ))
3110
+ self .assertRegex (
3111
+ repr (monitor ), r"<clinic.Monitor \d+ line=42 condition='condition1'>"
3112
+ )
3113
+
3114
+ monitor .stack .append (("token2" , "condition2" ))
3115
+ self .assertRegex (
3116
+ repr (monitor ),
3117
+ r"<clinic.Monitor \d+ line=42 condition='condition1 && condition2'>"
3118
+ )
3119
+
3120
+
3033
3121
if __name__ == "__main__" :
3034
3122
unittest .main ()
0 commit comments