@@ -220,6 +220,30 @@ def try_convert_namedtuple(got):
220
220
return got_again
221
221
222
222
223
+ def try_convert_printed_array (got ):
224
+ """Printed arrays: reinsert commas.
225
+ """
226
+ # a minimal version is `s_got = ", ".join(got[1:-1].split())`
227
+ # but it fails if there's a space after the opening bracket: "[ 0 1 2 ]"
228
+ # For 2D arrays, split into rows, drop spurious entries, then reassemble.
229
+ if not got .startswith ('[' ):
230
+ return got
231
+
232
+ g1 = got [1 :- 1 ] # strip outer "[...]"-s
233
+ rows = [x for x in g1 .split ("[" ) if x ]
234
+ rows2 = [", " .join (row .split ()) for row in rows ]
235
+
236
+ if got .startswith ("[[" ):
237
+ # was a 2D array, restore the opening brackets in rows; XXX clean up
238
+ rows3 = ["[" + row for row in rows2 ]
239
+ else :
240
+ rows3 = rows2
241
+
242
+ # add back the outer brackets
243
+ s_got = "[" + ", " .join (rows3 ) + "]"
244
+ return s_got
245
+
246
+
223
247
def has_masked (got ):
224
248
return 'masked_array' in got and '--' in got
225
249
@@ -281,8 +305,9 @@ def check_output(self, want, got, optionflags):
281
305
cond = (s_want .startswith ("[" ) and s_want .endswith ("]" ) and
282
306
s_got .startswith ("[" ) and s_got .endswith ("]" ))
283
307
if cond :
284
- s_want = ", " .join (s_want [1 :- 1 ].split ())
285
- s_got = ", " .join (s_got [1 :- 1 ].split ())
308
+ s_want = try_convert_printed_array (s_want )
309
+ s_got = try_convert_printed_array (s_got )
310
+
286
311
return self .check_output (s_want , s_got , optionflags )
287
312
288
313
#handle array abbreviation for n-dimensional arrays, n >= 1
0 commit comments