Show More
@@ -1,6 +1,6 b'' | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 |
|
2 | |||
3 | """This file contains unittests for the frontendbase module.""" |
|
3 | """This file contains unittests for the asyncfrontendbase module.""" | |
4 |
|
4 | |||
5 | __docformat__ = "restructuredtext en" |
|
5 | __docformat__ = "restructuredtext en" | |
6 |
|
6 | |||
@@ -15,17 +15,17 b' __docformat__ = "restructuredtext en"' | |||||
15 | # Imports |
|
15 | # Imports | |
16 | #--------------------------------------------------------------------------- |
|
16 | #--------------------------------------------------------------------------- | |
17 |
|
17 | |||
18 | import unittest |
|
|||
19 |
|
18 | |||
20 | try: |
|
19 | try: | |
|
20 | from twisted.trial import unittest | |||
21 | from IPython.frontend.asyncfrontendbase import AsyncFrontEndBase |
|
21 | from IPython.frontend.asyncfrontendbase import AsyncFrontEndBase | |
22 | from IPython.frontend import frontendbase |
|
22 | from IPython.frontend import frontendbase | |
23 | from IPython.kernel.engineservice import EngineService |
|
23 | from IPython.kernel.engineservice import EngineService | |
|
24 | from IPython.testing.parametric import Parametric, parametric | |||
24 | except ImportError: |
|
25 | except ImportError: | |
25 | import nose |
|
26 | import nose | |
26 | raise nose.SkipTest("This test requires zope.interface, Twisted and Foolscap") |
|
27 | raise nose.SkipTest("This test requires zope.interface, Twisted and Foolscap") | |
27 |
|
28 | |||
28 | from IPython.testing.decorators import skip |
|
|||
29 |
|
29 | |||
30 | class FrontEndCallbackChecker(AsyncFrontEndBase): |
|
30 | class FrontEndCallbackChecker(AsyncFrontEndBase): | |
31 | """FrontEndBase subclass for checking callbacks""" |
|
31 | """FrontEndBase subclass for checking callbacks""" | |
@@ -44,14 +44,11 b' class FrontEndCallbackChecker(AsyncFrontEndBase):' | |||||
44 | self.renderResultCalled = True |
|
44 | self.renderResultCalled = True | |
45 | return result |
|
45 | return result | |
46 |
|
46 | |||
47 |
|
||||
48 | def render_error(self, failure): |
|
47 | def render_error(self, failure): | |
49 | self.renderErrorCalled = True |
|
48 | self.renderErrorCalled = True | |
50 | return failure |
|
49 | return failure | |
51 |
|
||||
52 |
|
50 | |||
53 |
|
51 | |||
54 |
|
||||
55 | class TestAsyncFrontendBase(unittest.TestCase): |
|
52 | class TestAsyncFrontendBase(unittest.TestCase): | |
56 | def setUp(self): |
|
53 | def setUp(self): | |
57 | """Setup the EngineService and FrontEndBase""" |
|
54 | """Setup the EngineService and FrontEndBase""" | |
@@ -59,97 +56,56 b' class TestAsyncFrontendBase(unittest.TestCase):' | |||||
59 | self.fb = FrontEndCallbackChecker(engine=EngineService()) |
|
56 | self.fb = FrontEndCallbackChecker(engine=EngineService()) | |
60 |
|
57 | |||
61 | def test_implements_IFrontEnd(self): |
|
58 | def test_implements_IFrontEnd(self): | |
62 | assert(frontendbase.IFrontEnd.implementedBy( |
|
59 | self.assert_(frontendbase.IFrontEnd.implementedBy( | |
63 | AsyncFrontEndBase)) |
|
60 | AsyncFrontEndBase)) | |
64 |
|
61 | |||
65 | def test_is_complete_returns_False_for_incomplete_block(self): |
|
62 | def test_is_complete_returns_False_for_incomplete_block(self): | |
66 | """""" |
|
|||
67 |
|
||||
68 | block = """def test(a):""" |
|
63 | block = """def test(a):""" | |
69 |
|
64 | self.assert_(self.fb.is_complete(block) == False) | ||
70 | assert(self.fb.is_complete(block) == False) |
|
|||
71 |
|
65 | |||
72 | def test_is_complete_returns_True_for_complete_block(self): |
|
66 | def test_is_complete_returns_True_for_complete_block(self): | |
73 | """""" |
|
|||
74 |
|
||||
75 | block = """def test(a): pass""" |
|
67 | block = """def test(a): pass""" | |
76 |
|
68 | self.assert_(self.fb.is_complete(block)) | ||
77 | assert(self.fb.is_complete(block)) |
|
|||
78 |
|
||||
79 | block = """a=3""" |
|
69 | block = """a=3""" | |
80 |
|
70 | self.assert_(self.fb.is_complete(block)) | ||
81 | assert(self.fb.is_complete(block)) |
|
|||
82 |
|
71 | |||
83 | def test_blockID_added_to_result(self): |
|
72 | def test_blockID_added_to_result(self): | |
84 | block = """3+3""" |
|
73 | block = """3+3""" | |
85 |
|
||||
86 | d = self.fb.execute(block, blockID='TEST_ID') |
|
74 | d = self.fb.execute(block, blockID='TEST_ID') | |
87 |
|
75 | d.addCallback(lambda r: self.assert_(r['blockID']=='TEST_ID')) | ||
88 | d.addCallback(self.checkBlockID, expected='TEST_ID') |
|
76 | return d | |
89 |
|
77 | |||
90 | def test_blockID_added_to_failure(self): |
|
78 | def test_blockID_added_to_failure(self): | |
91 | block = "raise Exception()" |
|
79 | block = "raise Exception()" | |
92 |
|
||||
93 | d = self.fb.execute(block,blockID='TEST_ID') |
|
80 | d = self.fb.execute(block,blockID='TEST_ID') | |
94 |
d.addErrback(self. |
|
81 | d.addErrback(lambda f: self.assert_(f.blockID=='TEST_ID')) | |
95 |
|
82 | return d | ||
96 | def checkBlockID(self, result, expected=""): |
|
|||
97 | assert(result['blockID'] == expected) |
|
|||
98 |
|
||||
99 |
|
||||
100 | def checkFailureID(self, failure, expected=""): |
|
|||
101 | assert(failure.blockID == expected) |
|
|||
102 |
|
||||
103 |
|
83 | |||
104 | def test_callbacks_added_to_execute(self): |
|
84 | def test_callbacks_added_to_execute(self): | |
105 | """test that |
|
|||
106 | update_cell_prompt |
|
|||
107 | render_result |
|
|||
108 |
|
||||
109 | are added to execute request |
|
|||
110 | """ |
|
|||
111 |
|
||||
112 | d = self.fb.execute("10+10") |
|
85 | d = self.fb.execute("10+10") | |
113 | d.addCallback(self.checkCallbacks) |
|
86 | d.addCallback(lambda r: self.assert_(self.fb.updateCalled and self.fb.renderResultCalled)) | |
|
87 | return d | |||
114 |
|
88 | |||
115 | def checkCallbacks(self, result): |
|
|||
116 | assert(self.fb.updateCalled) |
|
|||
117 | assert(self.fb.renderResultCalled) |
|
|||
118 |
|
||||
119 | @skip("This test fails and lead to an unhandled error in a Deferred.") |
|
|||
120 | def test_error_callback_added_to_execute(self): |
|
89 | def test_error_callback_added_to_execute(self): | |
121 |
""" |
|
90 | """Test that render_error called on execution error.""" | |
122 |
|
91 | |||
123 | d = self.fb.execute("raise Exception()") |
|
92 | d = self.fb.execute("raise Exception()") | |
124 | d.addCallback(self.checkRenderError) |
|
93 | d.addErrback(lambda f: self.assert_(self.fb.renderErrorCalled)) | |
125 |
|
94 | return d | ||
126 | def checkRenderError(self, result): |
|
|||
127 | assert(self.fb.renderErrorCalled) |
|
|||
128 |
|
95 | |||
129 | def test_history_returns_expected_block(self): |
|
96 | def test_history_returns_expected_block(self): | |
130 | """Make sure history browsing doesn't fail""" |
|
97 | """Make sure history browsing doesn't fail.""" | |
131 |
|
98 | |||
132 | blocks = ["a=1","a=2","a=3"] |
|
99 | blocks = ["a=1","a=2","a=3"] | |
133 | for b in blocks: |
|
100 | d = self.fb.execute(blocks[0]) | |
134 |
|
|
101 | d.addCallback(lambda _: self.fb.execute(blocks[1])) | |
135 |
|
102 | d.addCallback(lambda _: self.fb.execute(blocks[2])) | ||
136 | # d is now the deferred for the last executed block |
|
103 | d.addCallback(lambda _: self.assert_(self.fb.get_history_previous("")==blocks[-2])) | |
137 |
d.addCallback(self.history |
|
104 | d.addCallback(lambda _: self.assert_(self.fb.get_history_previous("")==blocks[-3])) | |
138 |
|
105 | d.addCallback(lambda _: self.assert_(self.fb.get_history_next()==blocks[-2])) | ||
139 |
|
106 | return d | ||
140 | def historyTests(self, result, blocks): |
|
107 | ||
141 | """historyTests""" |
|
108 | def test_history_returns_none_at_startup(self): | |
142 |
|
109 | self.assert_(self.fb.get_history_previous("")==None) | ||
143 | assert(len(blocks) >= 3) |
|
110 | self.assert_(self.fb.get_history_next()==None) | |
144 | assert(self.fb.get_history_previous("") == blocks[-2]) |
|
111 | ||
145 | assert(self.fb.get_history_previous("") == blocks[-3]) |
|
|||
146 | assert(self.fb.get_history_next() == blocks[-2]) |
|
|||
147 |
|
||||
148 |
|
||||
149 | def test_history_returns_none_at_startup(self): |
|
|||
150 | """test_history_returns_none_at_startup""" |
|
|||
151 |
|
||||
152 | assert(self.fb.get_history_previous("")==None) |
|
|||
153 | assert(self.fb.get_history_next()==None) |
|
|||
154 |
|
||||
155 |
|
General Comments 0
You need to be logged in to leave comments.
Login now