From 88c47d26ef6cc3e9012991c20402ee2d05d6cb3c 2010-07-20 18:21:57 From: Fernando Perez Date: 2010-07-20 18:21:57 Subject: [PATCH] Fix in *tests* for recent traceback bug fix. It turns out that chaining too much info into the same deferred produces rather weird side-effects. So I broke up the test into several independent ones with separate deferreds. Note that the original bug fix was OK, the fix is just for the Twisted tests themselves. As Min said, with Twisted code sometimes getting the tests right is harder than the code itself. --- diff --git a/IPython/kernel/tests/tasktest.py b/IPython/kernel/tests/tasktest.py index e55dfb7..d8392a8 100755 --- a/IPython/kernel/tests/tasktest.py +++ b/IPython/kernel/tests/tasktest.py @@ -202,29 +202,36 @@ class ITaskControllerTestCase(TaskTestBase): # frames that actually belong to user code. return result.failure.getBriefTraceback().split('\n:')[1:] - def test_traceback(self): + + def check_traceback(self, cmd, nframes, exception=IOError): """Ensure that we have a traceback object in task failures.""" self.addEngine(1) - cmd = """ -def fail(): - raise IOError('failure test') - -result = fail() -""" t1 = task.StringTask(cmd) d = self.tc.run(t1) d.addCallback(self.tc.get_task_result, block=True) # Sanity check, that the right exception is raised - d.addCallback(lambda tr: self.assertRaises(IOError, tr.raise_exception)) - # Rerun the same task, this time we check for the traceback to have two - # frames + d.addCallback(lambda r: self.assertRaises(exception, r.raise_exception)) + # Rerun the same task, this time we check for the traceback to have the + # right number of frames d.addCallback(lambda r: self.tc.run(t1)) d.addCallback(self.tc.get_task_result, block=True) d.addCallback(self.get_traceback_frames) - d.addCallback(lambda frames: self.assertEquals(len(frames), 2)) + d.addCallback(lambda frames: self.assertEquals(len(frames), nframes)) + return d + + # Check traceback structure with 2 and 4 frame-deep stacks + def test_traceback(self): + cmd = """ +def fail(): + raise IOError('failure test') + +result = fail() +""" + return self.check_traceback(cmd, 2) + - # And repeat with a deeper stack, just to be safe + def test_traceback2(self): cmd = """ def boom(): raise IOError('failure test') @@ -237,10 +244,4 @@ def fail(): result = fail() """ - t1 = task.StringTask(cmd) - d.addCallback(lambda r: self.tc.run(t1)) - d.addCallback(self.tc.get_task_result, block=True) - d.addCallback(self.get_traceback_frames) - d.addCallback(lambda frames: self.assertEquals(len(frames), 4)) - - return d + return self.check_traceback(cmd, 4)