@@ -292,16 +292,23 @@ def _compare_eq_sequence(left, right, verbose=0):
292
292
explanation += [u"At index %s diff: %r != %r" % (i , left [i ], right [i ])]
293
293
break
294
294
len_diff = len_left - len_right
295
- if len_diff > 0 :
296
- explanation += [
297
- u"Left contains %d more items, first extra item: %s"
298
- % (len_diff , saferepr (left [len_right ]))
299
- ]
300
- elif len_diff < 0 :
301
- explanation += [
302
- u"Right contains %d more items, first extra item: %s"
303
- % (0 - len_diff , saferepr (right [len_left ]))
304
- ]
295
+
296
+ if len_diff :
297
+ if len_diff > 0 :
298
+ dir_with_more = "Left"
299
+ extra = saferepr (left [len_right ])
300
+ elif len_diff < 0 :
301
+ len_diff = 0 - len_diff
302
+ dir_with_more = "Right"
303
+ extra = saferepr (right [len_left ])
304
+
305
+ if len_diff == 1 :
306
+ explanation += [u"%s contains one more item: %s" % (dir_with_more , extra )]
307
+ else :
308
+ explanation += [
309
+ u"%s contains %d more items, first extra item: %s"
310
+ % (dir_with_more , len_diff , extra )
311
+ ]
305
312
return explanation
306
313
307
314
@@ -337,14 +344,22 @@ def _compare_eq_dict(left, right, verbose=0):
337
344
for k in diff :
338
345
explanation += [saferepr ({k : left [k ]}) + " != " + saferepr ({k : right [k ]})]
339
346
extra_left = set_left - set_right
340
- if extra_left :
341
- explanation .append (u"Left contains %d more items:" % len (extra_left ))
347
+ len_extra_left = len (extra_left )
348
+ if len_extra_left :
349
+ explanation .append (
350
+ u"Left contains %d more item%s:"
351
+ % (len_extra_left , "" if len_extra_left == 1 else "s" )
352
+ )
342
353
explanation .extend (
343
354
pprint .pformat ({k : left [k ] for k in extra_left }).splitlines ()
344
355
)
345
356
extra_right = set_right - set_left
346
- if extra_right :
347
- explanation .append (u"Right contains %d more items:" % len (extra_right ))
357
+ len_extra_right = len (extra_right )
358
+ if len_extra_right :
359
+ explanation .append (
360
+ u"Right contains %d more item%s:"
361
+ % (len_extra_right , "" if len_extra_right == 1 else "s" )
362
+ )
348
363
explanation .extend (
349
364
pprint .pformat ({k : right [k ] for k in extra_right }).splitlines ()
350
365
)
0 commit comments