@@ -155,6 +155,22 @@ def _parse_lines(self, linesource, module):
155
155
classes .sort ()
156
156
return functions , classes
157
157
158
+ @classmethod
159
+ def _normalize_repr (cls , value ):
160
+ if isinstance (value , list ):
161
+ return '[{}]' .format (', ' .join (map (cls ._normalize_repr , value )))
162
+ if isinstance (value , tuple ):
163
+ if len (value ) == 1 :
164
+ return '({},)' .format (cls ._normalize_repr (value [0 ]))
165
+ return '({})' .format (', ' .join (map (cls ._normalize_repr , value )))
166
+ if isinstance (value , (str , bytes )):
167
+ value = repr (value )
168
+ if value [0 ] not in ('"' , "'" ):
169
+ value = value [1 :]
170
+ else :
171
+ value = repr (value )
172
+ return value
173
+
158
174
def test_specs (self , uri ):
159
175
"""Check input and output specs in an uri
160
176
@@ -206,6 +222,7 @@ def test_specs(self, uri):
206
222
if not os .path .exists (nonautotest ):
207
223
with open (testfile , 'wt' ) as fp :
208
224
cmd = ['# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT' ,
225
+ 'from __future__ import unicode_literals' ,
209
226
'from ..%s import %s' % (uri .split ('.' )[- 1 ], c ),
210
227
'' ]
211
228
cmd .append ('\n def test_%s_inputs():' % c )
@@ -215,14 +232,7 @@ def test_specs(self, uri):
215
232
for key , value in sorted (trait .__dict__ .items ()):
216
233
if key in in_built or key == 'desc' :
217
234
continue
218
- if isinstance (value , (str , bytes )):
219
- quote = "'"
220
- if "'" in value :
221
- quote = '"'
222
- input_fields += "%s=%s%s%s,\n " % (key , quote ,
223
- value , quote )
224
- else :
225
- input_fields += "%s=%s,\n " % (key , value )
235
+ input_fields += "%s=%s,\n " % (key , self ._normalize_repr (value ))
226
236
input_fields += '),\n '
227
237
cmd += [' input_map = dict(%s)' % input_fields ]
228
238
cmd += [' inputs = %s.input_spec()' % c ]
@@ -259,14 +269,7 @@ def test_specs(self, uri):
259
269
for key , value in sorted (trait .__dict__ .items ()):
260
270
if key in in_built or key == 'desc' :
261
271
continue
262
- if isinstance (value , (str , bytes )):
263
- quote = "'"
264
- if "'" in value :
265
- quote = '"'
266
- input_fields += "%s=%s%s%s,\n " % (key , quote ,
267
- value , quote )
268
- else :
269
- input_fields += "%s=%s,\n " % (key , value )
272
+ input_fields += "%s=%s,\n " % (key , self ._normalize_repr (value ))
270
273
input_fields += '),\n '
271
274
cmd += [' output_map = dict(%s)' % input_fields ]
272
275
cmd += [' outputs = %s.output_spec()' % c ]
0 commit comments