Show More
@@ -202,29 +202,36 b' class ITaskControllerTestCase(TaskTestBase):' | |||
|
202 | 202 | # frames that actually belong to user code. |
|
203 | 203 | return result.failure.getBriefTraceback().split('\n<string>:')[1:] |
|
204 | 204 | |
|
205 | def test_traceback(self): | |
|
205 | ||
|
206 | def check_traceback(self, cmd, nframes, exception=IOError): | |
|
206 | 207 | """Ensure that we have a traceback object in task failures.""" |
|
207 | 208 | |
|
208 | 209 | self.addEngine(1) |
|
209 | cmd = """ | |
|
210 | def fail(): | |
|
211 | raise IOError('failure test') | |
|
212 | ||
|
213 | result = fail() | |
|
214 | """ | |
|
215 | 210 | t1 = task.StringTask(cmd) |
|
216 | 211 | d = self.tc.run(t1) |
|
217 | 212 | d.addCallback(self.tc.get_task_result, block=True) |
|
218 | 213 | # Sanity check, that the right exception is raised |
|
219 |
d.addCallback(lambda |
|
|
220 |
# Rerun the same task, this time we check for the traceback to have t |
|
|
221 | # frames | |
|
214 | d.addCallback(lambda r: self.assertRaises(exception, r.raise_exception)) | |
|
215 | # Rerun the same task, this time we check for the traceback to have the | |
|
216 | # right number of frames | |
|
222 | 217 | d.addCallback(lambda r: self.tc.run(t1)) |
|
223 | 218 | d.addCallback(self.tc.get_task_result, block=True) |
|
224 | 219 | d.addCallback(self.get_traceback_frames) |
|
225 |
d.addCallback(lambda frames: self.assertEquals(len(frames), |
|
|
220 | d.addCallback(lambda frames: self.assertEquals(len(frames), nframes)) | |
|
221 | return d | |
|
222 | ||
|
223 | # Check traceback structure with 2 and 4 frame-deep stacks | |
|
224 | def test_traceback(self): | |
|
225 | cmd = """ | |
|
226 | def fail(): | |
|
227 | raise IOError('failure test') | |
|
228 | ||
|
229 | result = fail() | |
|
230 | """ | |
|
231 | return self.check_traceback(cmd, 2) | |
|
232 | ||
|
226 | 233 | |
|
227 | # And repeat with a deeper stack, just to be safe | |
|
234 | def test_traceback2(self): | |
|
228 | 235 | cmd = """ |
|
229 | 236 | def boom(): |
|
230 | 237 | raise IOError('failure test') |
@@ -237,10 +244,4 b' def fail():' | |||
|
237 | 244 | |
|
238 | 245 | result = fail() |
|
239 | 246 | """ |
|
240 | t1 = task.StringTask(cmd) | |
|
241 | d.addCallback(lambda r: self.tc.run(t1)) | |
|
242 | d.addCallback(self.tc.get_task_result, block=True) | |
|
243 | d.addCallback(self.get_traceback_frames) | |
|
244 | d.addCallback(lambda frames: self.assertEquals(len(frames), 4)) | |
|
245 | ||
|
246 | return d | |
|
247 | return self.check_traceback(cmd, 4) |
General Comments 0
You need to be logged in to leave comments.
Login now