diff --git a/IPython/frontend/tests/test_asyncfrontendbase.py b/IPython/frontend/tests/test_asyncfrontendbase.py index 617456e..b3ed0e6 100644 --- a/IPython/frontend/tests/test_asyncfrontendbase.py +++ b/IPython/frontend/tests/test_asyncfrontendbase.py @@ -1,6 +1,6 @@ # encoding: utf-8 -"""This file contains unittests for the frontendbase module.""" +"""This file contains unittests for the asyncfrontendbase module.""" __docformat__ = "restructuredtext en" @@ -15,17 +15,17 @@ __docformat__ = "restructuredtext en" # Imports #--------------------------------------------------------------------------- -import unittest try: + from twisted.trial import unittest from IPython.frontend.asyncfrontendbase import AsyncFrontEndBase from IPython.frontend import frontendbase from IPython.kernel.engineservice import EngineService + from IPython.testing.parametric import Parametric, parametric except ImportError: import nose raise nose.SkipTest("This test requires zope.interface, Twisted and Foolscap") -from IPython.testing.decorators import skip class FrontEndCallbackChecker(AsyncFrontEndBase): """FrontEndBase subclass for checking callbacks""" @@ -44,14 +44,11 @@ class FrontEndCallbackChecker(AsyncFrontEndBase): self.renderResultCalled = True return result - def render_error(self, failure): self.renderErrorCalled = True return failure - - class TestAsyncFrontendBase(unittest.TestCase): def setUp(self): """Setup the EngineService and FrontEndBase""" @@ -59,97 +56,56 @@ class TestAsyncFrontendBase(unittest.TestCase): self.fb = FrontEndCallbackChecker(engine=EngineService()) def test_implements_IFrontEnd(self): - assert(frontendbase.IFrontEnd.implementedBy( + self.assert_(frontendbase.IFrontEnd.implementedBy( AsyncFrontEndBase)) def test_is_complete_returns_False_for_incomplete_block(self): - """""" - block = """def test(a):""" - - assert(self.fb.is_complete(block) == False) + self.assert_(self.fb.is_complete(block) == False) def test_is_complete_returns_True_for_complete_block(self): - """""" - block = """def test(a): pass""" - - assert(self.fb.is_complete(block)) - + self.assert_(self.fb.is_complete(block)) block = """a=3""" - - assert(self.fb.is_complete(block)) + self.assert_(self.fb.is_complete(block)) def test_blockID_added_to_result(self): block = """3+3""" - d = self.fb.execute(block, blockID='TEST_ID') - - d.addCallback(self.checkBlockID, expected='TEST_ID') + d.addCallback(lambda r: self.assert_(r['blockID']=='TEST_ID')) + return d def test_blockID_added_to_failure(self): block = "raise Exception()" - d = self.fb.execute(block,blockID='TEST_ID') - d.addErrback(self.checkFailureID, expected='TEST_ID') - - def checkBlockID(self, result, expected=""): - assert(result['blockID'] == expected) - - - def checkFailureID(self, failure, expected=""): - assert(failure.blockID == expected) - + d.addErrback(lambda f: self.assert_(f.blockID=='TEST_ID')) + return d def test_callbacks_added_to_execute(self): - """test that - update_cell_prompt - render_result - - are added to execute request - """ - d = self.fb.execute("10+10") - d.addCallback(self.checkCallbacks) + d.addCallback(lambda r: self.assert_(self.fb.updateCalled and self.fb.renderResultCalled)) + return d - def checkCallbacks(self, result): - assert(self.fb.updateCalled) - assert(self.fb.renderResultCalled) - - @skip("This test fails and lead to an unhandled error in a Deferred.") def test_error_callback_added_to_execute(self): - """test that render_error called on execution error""" + """Test that render_error called on execution error.""" d = self.fb.execute("raise Exception()") - d.addCallback(self.checkRenderError) - - def checkRenderError(self, result): - assert(self.fb.renderErrorCalled) + d.addErrback(lambda f: self.assert_(self.fb.renderErrorCalled)) + return d def test_history_returns_expected_block(self): - """Make sure history browsing doesn't fail""" + """Make sure history browsing doesn't fail.""" blocks = ["a=1","a=2","a=3"] - for b in blocks: - d = self.fb.execute(b) - - # d is now the deferred for the last executed block - d.addCallback(self.historyTests, blocks) - - - def historyTests(self, result, blocks): - """historyTests""" - - assert(len(blocks) >= 3) - assert(self.fb.get_history_previous("") == blocks[-2]) - assert(self.fb.get_history_previous("") == blocks[-3]) - assert(self.fb.get_history_next() == blocks[-2]) - - - def test_history_returns_none_at_startup(self): - """test_history_returns_none_at_startup""" - - assert(self.fb.get_history_previous("")==None) - assert(self.fb.get_history_next()==None) - - + d = self.fb.execute(blocks[0]) + d.addCallback(lambda _: self.fb.execute(blocks[1])) + d.addCallback(lambda _: self.fb.execute(blocks[2])) + d.addCallback(lambda _: self.assert_(self.fb.get_history_previous("")==blocks[-2])) + d.addCallback(lambda _: self.assert_(self.fb.get_history_previous("")==blocks[-3])) + d.addCallback(lambda _: self.assert_(self.fb.get_history_next()==blocks[-2])) + return d + + def test_history_returns_none_at_startup(self): + self.assert_(self.fb.get_history_previous("")==None) + self.assert_(self.fb.get_history_next()==None) +