@@ -292,16 +292,23 @@ def _compare_eq_sequence(left, right, verbose=0):
292292 explanation += [u"At index %s diff: %r != %r" % (i , left [i ], right [i ])]
293293 break
294294 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+ ]
305312 return explanation
306313
307314
@@ -337,14 +344,22 @@ def _compare_eq_dict(left, right, verbose=0):
337344 for k in diff :
338345 explanation += [saferepr ({k : left [k ]}) + " != " + saferepr ({k : right [k ]})]
339346 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+ )
342353 explanation .extend (
343354 pprint .pformat ({k : left [k ] for k in extra_left }).splitlines ()
344355 )
345356 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+ )
348363 explanation .extend (
349364 pprint .pformat ({k : right [k ] for k in extra_right }).splitlines ()
350365 )
0 commit comments