@@ -1123,7 +1123,7 @@ def test_context(self):
1123
1123
self .assertEqual (exc_info [0 ], exc .exc_type )
1124
1124
self .assertEqual (str (exc_info [1 ]), str (exc ))
1125
1125
1126
- def test_comparison (self ):
1126
+ def test_comparison_basic (self ):
1127
1127
try :
1128
1128
1 / 0
1129
1129
except Exception :
@@ -1135,6 +1135,43 @@ def test_comparison(self):
1135
1135
self .assertNotEqual (exc , object ())
1136
1136
self .assertEqual (exc , ALWAYS_EQ )
1137
1137
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
+
1138
1175
def test_unhashable (self ):
1139
1176
class UnhashableException (Exception ):
1140
1177
def __eq__ (self , other ):
@@ -1176,7 +1213,7 @@ def test_lookup_lines(self):
1176
1213
f = test_frame (c , None , None )
1177
1214
tb = test_tb (f , 6 , None )
1178
1215
exc = traceback .TracebackException (Exception , e , tb , lookup_lines = False )
1179
- self .assertEqual ({}, linecache .cache )
1216
+ self .assertEqual (linecache .cache , {} )
1180
1217
linecache .updatecache ('/foo.py' , globals ())
1181
1218
self .assertEqual (exc .stack [0 ].line , "import sys" )
1182
1219
0 commit comments