File tree 1 file changed +12
-2
lines changed
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -39,15 +39,25 @@ def assert_false(b: bool, msg: str = None) -> None:
39
39
if b :
40
40
raise AssertionFailure (msg )
41
41
42
+ def good_repr (obj : object ) -> str :
43
+ if isinstance (obj , str ):
44
+ if obj .count ('\n ' ) > 1 :
45
+ bits = ["'''\\ " ]
46
+ for line in obj .split ('\n ' ):
47
+ # force repr to use ' not ", then cut it off
48
+ bits .append (repr ('"' + line )[2 :- 1 ])
49
+ bits [- 1 ] += "'''"
50
+ return '\n ' .join (bits )
51
+ return repr (obj )
42
52
43
53
def assert_equal (a : object , b : object , fmt : str = '{} != {}' ) -> None :
44
54
if a != b :
45
- raise AssertionFailure (fmt .format (repr (a ), repr (b )))
55
+ raise AssertionFailure (fmt .format (good_repr (a ), good_repr (b )))
46
56
47
57
48
58
def assert_not_equal (a : object , b : object , fmt : str = '{} == {}' ) -> None :
49
59
if a == b :
50
- raise AssertionFailure (fmt .format (repr (a ), repr (b )))
60
+ raise AssertionFailure (fmt .format (good_repr (a ), good_repr (b )))
51
61
52
62
53
63
def assert_raises (typ : type , * rest : Any ) -> None :
You can’t perform that action at this time.
0 commit comments