@@ -1123,7 +1123,7 @@ def test_context(self):
11231123 self .assertEqual (exc_info [0 ], exc .exc_type )
11241124 self .assertEqual (str (exc_info [1 ]), str (exc ))
11251125
1126- def test_comparison (self ):
1126+ def test_comparison_basic (self ):
11271127 try :
11281128 1 / 0
11291129 except Exception :
@@ -1135,6 +1135,43 @@ def test_comparison(self):
11351135 self .assertNotEqual (exc , object ())
11361136 self .assertEqual (exc , ALWAYS_EQ )
11371137
1138+ def test_comparison_params_variations (self ):
1139+ def raise_exc ():
1140+ try :
1141+ raise ValueError ('bad value' )
1142+ except :
1143+ raise
1144+
1145+ def raise_with_locals ():
1146+ x , y = 1 , 2
1147+ raise_exc ()
1148+
1149+ try :
1150+ raise_with_locals ()
1151+ except Exception :
1152+ exc_info = sys .exc_info ()
1153+
1154+ exc = traceback .TracebackException (* exc_info )
1155+ exc1 = traceback .TracebackException (* exc_info , limit = 10 )
1156+ exc2 = traceback .TracebackException (* exc_info , limit = 2 )
1157+
1158+ self .assertEqual (exc , exc1 ) # limit=10 gets all frames
1159+ self .assertNotEqual (exc , exc2 ) # limit=2 truncates the output
1160+
1161+ # locals change the output
1162+ exc3 = traceback .TracebackException (* exc_info , capture_locals = True )
1163+ self .assertNotEqual (exc , exc3 )
1164+
1165+ # there are no locals in the innermost frame
1166+ exc4 = traceback .TracebackException (* exc_info , limit = - 1 )
1167+ exc5 = traceback .TracebackException (* exc_info , limit = - 1 , capture_locals = True )
1168+ self .assertEqual (exc4 , exc5 )
1169+
1170+ # there are locals in the next-to-innermost frame
1171+ exc6 = traceback .TracebackException (* exc_info , limit = - 2 )
1172+ exc7 = traceback .TracebackException (* exc_info , limit = - 2 , capture_locals = True )
1173+ self .assertNotEqual (exc6 , exc7 )
1174+
11381175 def test_unhashable (self ):
11391176 class UnhashableException (Exception ):
11401177 def __eq__ (self , other ):
@@ -1176,7 +1213,7 @@ def test_lookup_lines(self):
11761213 f = test_frame (c , None , None )
11771214 tb = test_tb (f , 6 , None )
11781215 exc = traceback .TracebackException (Exception , e , tb , lookup_lines = False )
1179- self .assertEqual ({}, linecache .cache )
1216+ self .assertEqual (linecache .cache , {} )
11801217 linecache .updatecache ('/foo.py' , globals ())
11811218 self .assertEqual (exc .stack [0 ].line , "import sys" )
11821219
0 commit comments