##// END OF EJS Templates
working in tab completion
working in tab completion

File last commit:

r5390:c82649ea
r5580:e1e6febe
Show More
test_asyncfrontendbase.py
106 lines | 4.1 KiB | text/x-python | PythonLexer
/ IPython / deathrow / oldfrontend / tests / test_asyncfrontendbase.py
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 # encoding: utf-8
Brian Granger
Fixes for ticket https://bugs.launchpad.net/bugs/266921...
r1937 """This file contains unittests for the asyncfrontendbase module."""
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710
#---------------------------------------------------------------------------
Matthias BUSSONNIER
update copyright to 2011/20xx-2011...
r5390 # Copyright (C) 2008-2011 The IPython Development Team
Bernardo B. Marques
remove all trailling spaces
r4872 #
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 #---------------------------------------------------------------------------
Fernando Perez
Fixes so the test suite runs when Twisted is not available....
r2133
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 #---------------------------------------------------------------------------
Bernardo B. Marques
remove all trailling spaces
r4872 # Imports
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 #---------------------------------------------------------------------------
Brian Granger
Fixing misc testing related things.
r1960 from twisted.trial import unittest
Bernardo B. Marques
remove all trailling spaces
r4872
Brian Granger
Fixing misc testing related things.
r1960 from IPython.frontend.asyncfrontendbase import AsyncFrontEndBase
Bernardo B. Marques
remove all trailling spaces
r4872 from IPython.frontend import frontendbase
Brian Granger
Fixing misc testing related things.
r1960 from IPython.kernel.engineservice import EngineService
from IPython.testing.parametric import Parametric, parametric
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710
Fernando Perez
Fixes so the test suite runs when Twisted is not available....
r2133 #-----------------------------------------------------------------------------
# Classes and functions
#-----------------------------------------------------------------------------
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710
class FrontEndCallbackChecker(AsyncFrontEndBase):
"""FrontEndBase subclass for checking callbacks"""
def __init__(self, engine=None, history=None):
Bernardo B. Marques
remove all trailling spaces
r4872 super(FrontEndCallbackChecker, self).__init__(engine=engine,
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 history=history)
self.updateCalled = False
self.renderResultCalled = False
self.renderErrorCalled = False
Bernardo B. Marques
remove all trailling spaces
r4872
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 def update_cell_prompt(self, result, blockID=None):
self.updateCalled = True
return result
Bernardo B. Marques
remove all trailling spaces
r4872
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 def render_result(self, result):
self.renderResultCalled = True
return result
Bernardo B. Marques
remove all trailling spaces
r4872
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 def render_error(self, failure):
self.renderErrorCalled = True
return failure
class TestAsyncFrontendBase(unittest.TestCase):
def setUp(self):
"""Setup the EngineService and FrontEndBase"""
Bernardo B. Marques
remove all trailling spaces
r4872
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 self.fb = FrontEndCallbackChecker(engine=EngineService())
Bernardo B. Marques
remove all trailling spaces
r4872
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 def test_implements_IFrontEnd(self):
Brian Granger
Fixes for ticket https://bugs.launchpad.net/bugs/266921...
r1937 self.assert_(frontendbase.IFrontEnd.implementedBy(
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 AsyncFrontEndBase))
Bernardo B. Marques
remove all trailling spaces
r4872
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 def test_is_complete_returns_False_for_incomplete_block(self):
block = """def test(a):"""
Brian Granger
Fixes for ticket https://bugs.launchpad.net/bugs/266921...
r1937 self.assert_(self.fb.is_complete(block) == False)
Bernardo B. Marques
remove all trailling spaces
r4872
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 def test_is_complete_returns_True_for_complete_block(self):
block = """def test(a): pass"""
Brian Granger
Fixes for ticket https://bugs.launchpad.net/bugs/266921...
r1937 self.assert_(self.fb.is_complete(block))
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 block = """a=3"""
Brian Granger
Fixes for ticket https://bugs.launchpad.net/bugs/266921...
r1937 self.assert_(self.fb.is_complete(block))
Bernardo B. Marques
remove all trailling spaces
r4872
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 def test_blockID_added_to_result(self):
block = """3+3"""
d = self.fb.execute(block, blockID='TEST_ID')
Brian Granger
Fixes for ticket https://bugs.launchpad.net/bugs/266921...
r1937 d.addCallback(lambda r: self.assert_(r['blockID']=='TEST_ID'))
return d
Bernardo B. Marques
remove all trailling spaces
r4872
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 def test_blockID_added_to_failure(self):
block = "raise Exception()"
d = self.fb.execute(block,blockID='TEST_ID')
Brian Granger
Fixes for ticket https://bugs.launchpad.net/bugs/266921...
r1937 d.addErrback(lambda f: self.assert_(f.blockID=='TEST_ID'))
return d
Bernardo B. Marques
remove all trailling spaces
r4872
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 def test_callbacks_added_to_execute(self):
d = self.fb.execute("10+10")
Brian Granger
Fixes for ticket https://bugs.launchpad.net/bugs/266921...
r1937 d.addCallback(lambda r: self.assert_(self.fb.updateCalled and self.fb.renderResultCalled))
return d
Bernardo B. Marques
remove all trailling spaces
r4872
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 def test_error_callback_added_to_execute(self):
Brian Granger
Fixes for ticket https://bugs.launchpad.net/bugs/266921...
r1937 """Test that render_error called on execution error."""
Bernardo B. Marques
remove all trailling spaces
r4872
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 d = self.fb.execute("raise Exception()")
Brian Granger
Fixes for ticket https://bugs.launchpad.net/bugs/266921...
r1937 d.addErrback(lambda f: self.assert_(self.fb.renderErrorCalled))
return d
Bernardo B. Marques
remove all trailling spaces
r4872
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 def test_history_returns_expected_block(self):
Brian Granger
Fixes for ticket https://bugs.launchpad.net/bugs/266921...
r1937 """Make sure history browsing doesn't fail."""
Bernardo B. Marques
remove all trailling spaces
r4872
Gael Varoquaux
Replace all use of the ast module with the codeop module, and all use of...
r1710 blocks = ["a=1","a=2","a=3"]
Brian Granger
Fixes for ticket https://bugs.launchpad.net/bugs/266921...
r1937 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
Bernardo B. Marques
remove all trailling spaces
r4872
def test_history_returns_none_at_startup(self):
Brian Granger
Fixes for ticket https://bugs.launchpad.net/bugs/266921...
r1937 self.assert_(self.fb.get_history_previous("")==None)
self.assert_(self.fb.get_history_next()==None)