##// END OF EJS Templates
Reenabled the test test_asyncfrontendbase.py....
Brian Granger -
Show More
@@ -1,109 +1,106 b''
1 # encoding: utf-8
1 # encoding: utf-8
2 """This file contains unittests for the asyncfrontendbase module."""
2 """This file contains unittests for the asyncfrontendbase module."""
3
4 # Tell nose to skip this module
5 __test__ = {}
6
3
7 #---------------------------------------------------------------------------
4 #---------------------------------------------------------------------------
8 # Copyright (C) 2008-2009 The IPython Development Team
5 # Copyright (C) 2008-2009 The IPython Development Team
9 #
6 #
10 # Distributed under the terms of the BSD License. The full license is in
7 # Distributed under the terms of the BSD License. The full license is in
11 # the file COPYING, distributed as part of this software.
8 # the file COPYING, distributed as part of this software.
12 #---------------------------------------------------------------------------
9 #---------------------------------------------------------------------------
13
10
14 #---------------------------------------------------------------------------
11 #---------------------------------------------------------------------------
15 # Imports
12 # Imports
16 #---------------------------------------------------------------------------
13 #---------------------------------------------------------------------------
17
14
18 from twisted.trial import unittest
15 from twisted.trial import unittest
19
16
20 from IPython.frontend.asyncfrontendbase import AsyncFrontEndBase
17 from IPython.frontend.asyncfrontendbase import AsyncFrontEndBase
21 from IPython.frontend import frontendbase
18 from IPython.frontend import frontendbase
22 from IPython.kernel.engineservice import EngineService
19 from IPython.kernel.engineservice import EngineService
23 from IPython.testing.parametric import Parametric, parametric
20 from IPython.testing.parametric import Parametric, parametric
24
21
25 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
26 # Classes and functions
23 # Classes and functions
27 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
28
25
29 class FrontEndCallbackChecker(AsyncFrontEndBase):
26 class FrontEndCallbackChecker(AsyncFrontEndBase):
30 """FrontEndBase subclass for checking callbacks"""
27 """FrontEndBase subclass for checking callbacks"""
31 def __init__(self, engine=None, history=None):
28 def __init__(self, engine=None, history=None):
32 super(FrontEndCallbackChecker, self).__init__(engine=engine,
29 super(FrontEndCallbackChecker, self).__init__(engine=engine,
33 history=history)
30 history=history)
34 self.updateCalled = False
31 self.updateCalled = False
35 self.renderResultCalled = False
32 self.renderResultCalled = False
36 self.renderErrorCalled = False
33 self.renderErrorCalled = False
37
34
38 def update_cell_prompt(self, result, blockID=None):
35 def update_cell_prompt(self, result, blockID=None):
39 self.updateCalled = True
36 self.updateCalled = True
40 return result
37 return result
41
38
42 def render_result(self, result):
39 def render_result(self, result):
43 self.renderResultCalled = True
40 self.renderResultCalled = True
44 return result
41 return result
45
42
46 def render_error(self, failure):
43 def render_error(self, failure):
47 self.renderErrorCalled = True
44 self.renderErrorCalled = True
48 return failure
45 return failure
49
46
50
47
51 class TestAsyncFrontendBase(unittest.TestCase):
48 class TestAsyncFrontendBase(unittest.TestCase):
52 def setUp(self):
49 def setUp(self):
53 """Setup the EngineService and FrontEndBase"""
50 """Setup the EngineService and FrontEndBase"""
54
51
55 self.fb = FrontEndCallbackChecker(engine=EngineService())
52 self.fb = FrontEndCallbackChecker(engine=EngineService())
56
53
57 def test_implements_IFrontEnd(self):
54 def test_implements_IFrontEnd(self):
58 self.assert_(frontendbase.IFrontEnd.implementedBy(
55 self.assert_(frontendbase.IFrontEnd.implementedBy(
59 AsyncFrontEndBase))
56 AsyncFrontEndBase))
60
57
61 def test_is_complete_returns_False_for_incomplete_block(self):
58 def test_is_complete_returns_False_for_incomplete_block(self):
62 block = """def test(a):"""
59 block = """def test(a):"""
63 self.assert_(self.fb.is_complete(block) == False)
60 self.assert_(self.fb.is_complete(block) == False)
64
61
65 def test_is_complete_returns_True_for_complete_block(self):
62 def test_is_complete_returns_True_for_complete_block(self):
66 block = """def test(a): pass"""
63 block = """def test(a): pass"""
67 self.assert_(self.fb.is_complete(block))
64 self.assert_(self.fb.is_complete(block))
68 block = """a=3"""
65 block = """a=3"""
69 self.assert_(self.fb.is_complete(block))
66 self.assert_(self.fb.is_complete(block))
70
67
71 def test_blockID_added_to_result(self):
68 def test_blockID_added_to_result(self):
72 block = """3+3"""
69 block = """3+3"""
73 d = self.fb.execute(block, blockID='TEST_ID')
70 d = self.fb.execute(block, blockID='TEST_ID')
74 d.addCallback(lambda r: self.assert_(r['blockID']=='TEST_ID'))
71 d.addCallback(lambda r: self.assert_(r['blockID']=='TEST_ID'))
75 return d
72 return d
76
73
77 def test_blockID_added_to_failure(self):
74 def test_blockID_added_to_failure(self):
78 block = "raise Exception()"
75 block = "raise Exception()"
79 d = self.fb.execute(block,blockID='TEST_ID')
76 d = self.fb.execute(block,blockID='TEST_ID')
80 d.addErrback(lambda f: self.assert_(f.blockID=='TEST_ID'))
77 d.addErrback(lambda f: self.assert_(f.blockID=='TEST_ID'))
81 return d
78 return d
82
79
83 def test_callbacks_added_to_execute(self):
80 def test_callbacks_added_to_execute(self):
84 d = self.fb.execute("10+10")
81 d = self.fb.execute("10+10")
85 d.addCallback(lambda r: self.assert_(self.fb.updateCalled and self.fb.renderResultCalled))
82 d.addCallback(lambda r: self.assert_(self.fb.updateCalled and self.fb.renderResultCalled))
86 return d
83 return d
87
84
88 def test_error_callback_added_to_execute(self):
85 def test_error_callback_added_to_execute(self):
89 """Test that render_error called on execution error."""
86 """Test that render_error called on execution error."""
90
87
91 d = self.fb.execute("raise Exception()")
88 d = self.fb.execute("raise Exception()")
92 d.addErrback(lambda f: self.assert_(self.fb.renderErrorCalled))
89 d.addErrback(lambda f: self.assert_(self.fb.renderErrorCalled))
93 return d
90 return d
94
91
95 def test_history_returns_expected_block(self):
92 def test_history_returns_expected_block(self):
96 """Make sure history browsing doesn't fail."""
93 """Make sure history browsing doesn't fail."""
97
94
98 blocks = ["a=1","a=2","a=3"]
95 blocks = ["a=1","a=2","a=3"]
99 d = self.fb.execute(blocks[0])
96 d = self.fb.execute(blocks[0])
100 d.addCallback(lambda _: self.fb.execute(blocks[1]))
97 d.addCallback(lambda _: self.fb.execute(blocks[1]))
101 d.addCallback(lambda _: self.fb.execute(blocks[2]))
98 d.addCallback(lambda _: self.fb.execute(blocks[2]))
102 d.addCallback(lambda _: self.assert_(self.fb.get_history_previous("")==blocks[-2]))
99 d.addCallback(lambda _: self.assert_(self.fb.get_history_previous("")==blocks[-2]))
103 d.addCallback(lambda _: self.assert_(self.fb.get_history_previous("")==blocks[-3]))
100 d.addCallback(lambda _: self.assert_(self.fb.get_history_previous("")==blocks[-3]))
104 d.addCallback(lambda _: self.assert_(self.fb.get_history_next()==blocks[-2]))
101 d.addCallback(lambda _: self.assert_(self.fb.get_history_next()==blocks[-2]))
105 return d
102 return d
106
103
107 def test_history_returns_none_at_startup(self):
104 def test_history_returns_none_at_startup(self):
108 self.assert_(self.fb.get_history_previous("")==None)
105 self.assert_(self.fb.get_history_previous("")==None)
109 self.assert_(self.fb.get_history_next()==None)
106 self.assert_(self.fb.get_history_next()==None)
General Comments 0
You need to be logged in to leave comments. Login now