@@ -86,7 +86,7 @@ def test_caret(self):
86
86
err = self .get_exception_format (self .syntax_error_with_caret ,
87
87
SyntaxError )
88
88
self .assertEqual (len (err ), 4 )
89
- self .assertTrue (err [1 ].strip () == "return x!" )
89
+ self .assertEqual (err [1 ].strip (), "return x!" )
90
90
self .assertIn ("^" , err [2 ]) # third line has caret
91
91
self .assertEqual (err [1 ].find ("!" ), err [2 ].find ("^" )) # in the right place
92
92
self .assertEqual (err [2 ].count ("^" ), 1 )
@@ -419,16 +419,10 @@ def do_test(firstlines, message, charset, lineno):
419
419
err_line = "raise RuntimeError('{0}')" .format (message_ascii )
420
420
err_msg = "RuntimeError: {0}" .format (message_ascii )
421
421
422
- self .assertIn (("line %s" % lineno ), stdout [1 ],
423
- "Invalid line number: {0!r} instead of {1}" .format (
424
- stdout [1 ], lineno ))
425
- self .assertTrue (stdout [2 ].endswith (err_line ),
426
- "Invalid traceback line: {0!r} instead of {1!r}" .format (
427
- stdout [2 ], err_line ))
422
+ self .assertIn ("line %s" % lineno , stdout [1 ])
423
+ self .assertEndsWith (stdout [2 ], err_line )
428
424
actual_err_msg = stdout [3 ]
429
- self .assertTrue (actual_err_msg == err_msg ,
430
- "Invalid error message: {0!r} instead of {1!r}" .format (
431
- actual_err_msg , err_msg ))
425
+ self .assertEqual (actual_err_msg , err_msg )
432
426
433
427
do_test ("" , "foo" , "ascii" , 3 )
434
428
for charset in ("ascii" , "iso-8859-1" , "utf-8" , "GBK" ):
@@ -1809,9 +1803,9 @@ def check_traceback_format(self, cleanup_func=None):
1809
1803
banner = tb_lines [0 ]
1810
1804
self .assertEqual (len (tb_lines ), 5 )
1811
1805
location , source_line = tb_lines [- 2 ], tb_lines [- 1 ]
1812
- self .assertTrue (banner . startswith ( 'Traceback' ) )
1813
- self .assertTrue (location . startswith ( ' File' ) )
1814
- self .assertTrue (source_line . startswith ( ' raise' ) )
1806
+ self .assertStartsWith (banner , 'Traceback' )
1807
+ self .assertStartsWith (location , ' File' )
1808
+ self .assertStartsWith (source_line , ' raise' )
1815
1809
1816
1810
def test_traceback_format (self ):
1817
1811
self .check_traceback_format ()
@@ -2190,12 +2184,12 @@ def zero_div(self):
2190
2184
def check_zero_div (self , msg ):
2191
2185
lines = msg .splitlines ()
2192
2186
if has_no_debug_ranges ():
2193
- self .assertTrue (lines [- 3 ]. startswith ( ' File' ) )
2187
+ self .assertStartsWith (lines [- 3 ], ' File' )
2194
2188
self .assertIn ('1/0 # In zero_div' , lines [- 2 ])
2195
2189
else :
2196
- self .assertTrue (lines [- 4 ]. startswith ( ' File' ) )
2190
+ self .assertStartsWith (lines [- 4 ], ' File' )
2197
2191
self .assertIn ('1/0 # In zero_div' , lines [- 3 ])
2198
- self .assertTrue (lines [- 1 ]. startswith ( 'ZeroDivisionError' ), lines [ - 1 ] )
2192
+ self .assertStartsWith (lines [- 1 ], 'ZeroDivisionError' )
2199
2193
2200
2194
def test_simple (self ):
2201
2195
try :
@@ -2205,12 +2199,12 @@ def test_simple(self):
2205
2199
lines = self .get_report (e ).splitlines ()
2206
2200
if has_no_debug_ranges ():
2207
2201
self .assertEqual (len (lines ), 4 )
2208
- self .assertTrue (lines [3 ]. startswith ( 'ZeroDivisionError' ) )
2202
+ self .assertStartsWith (lines [3 ], 'ZeroDivisionError' )
2209
2203
else :
2210
2204
self .assertEqual (len (lines ), 5 )
2211
- self .assertTrue (lines [4 ]. startswith ( 'ZeroDivisionError' ) )
2212
- self .assertTrue (lines [0 ]. startswith ( 'Traceback' ) )
2213
- self .assertTrue (lines [1 ]. startswith ( ' File' ) )
2205
+ self .assertStartsWith (lines [4 ], 'ZeroDivisionError' )
2206
+ self .assertStartsWith (lines [0 ], 'Traceback' )
2207
+ self .assertStartsWith (lines [1 ], ' File' )
2214
2208
self .assertIn ('1/0 # Marker' , lines [2 ])
2215
2209
2216
2210
def test_cause (self ):
@@ -2251,9 +2245,9 @@ def test_context_suppression(self):
2251
2245
e = _
2252
2246
lines = self .get_report (e ).splitlines ()
2253
2247
self .assertEqual (len (lines ), 4 )
2254
- self .assertTrue (lines [3 ]. startswith ( 'ZeroDivisionError' ) )
2255
- self .assertTrue (lines [0 ]. startswith ( 'Traceback' ) )
2256
- self .assertTrue (lines [1 ]. startswith ( ' File' ) )
2248
+ self .assertStartsWith (lines [3 ], 'ZeroDivisionError' )
2249
+ self .assertStartsWith (lines [0 ], 'Traceback' )
2250
+ self .assertStartsWith (lines [1 ], ' File' )
2257
2251
self .assertIn ('ZeroDivisionError from None' , lines [2 ])
2258
2252
2259
2253
def test_cause_and_context (self ):
0 commit comments