@@ -455,7 +455,10 @@ class Mismatch(Failure):
455455 """
456456
457457 def __init__ (self , expected , actual , help = None ):
458- expected , actual = _truncate (expected , actual ), _truncate (actual , expected )
458+ def _safe_truncate (x , y ):
459+ return _truncate (x , y ) if x not in (EOF , TIMEOUT ) else x
460+
461+ expected , actual = _safe_truncate (expected , actual ), _safe_truncate (actual , expected )
459462
460463 rationale = _ ("expected: {}\n actual: {}" ).format (
461464 _raw (expected ),
@@ -464,12 +467,6 @@ def __init__(self, expected, actual, help=None):
464467
465468 super ().__init__ (rationale = rationale , help = help )
466469
467- if expected == EOF :
468- expected = "EOF"
469-
470- if actual == EOF :
471- actual = "EOF"
472-
473470 self .payload .update ({"expected" : expected , "actual" : actual })
474471
475472
@@ -503,11 +500,13 @@ def wrapper(*args, **kwargs):
503500 return decorator
504501
505502def _truncate (s , other , max_len = 10 ):
503+ def normalize (obj ):
504+ if isinstance (obj , list ):
505+ return "\n " .join (map (str , obj ))
506+ else :
507+ return str (obj )
506508
507- if isinstance (s , list ):
508- s = "\n " .join (s )
509- if isinstance (other , list ):
510- other = "\n " .join (other )
509+ s , other = normalize (s ), normalize (other )
511510
512511 # find the index of first difference
513512 limit = min (len (s ), len (other ))
@@ -532,13 +531,15 @@ def _truncate(s, other, max_len=10):
532531
533532
534533def _raw (s ):
535- """Get raw representation of s, truncating if too long ."""
534+ """Get raw representation of s."""
536535
537536 if isinstance (s , list ):
538537 s = "\n " .join (_raw (item ) for item in s )
539538
540539 if s == EOF :
541540 return "EOF"
541+ elif s == TIMEOUT :
542+ return "TIMEOUT"
542543
543544 s = f'"{ repr (str (s ))[1 :- 1 ]} "'
544545 return s
0 commit comments