##// END OF EJS Templates
added blockID for failures (special case)
Barry Wark -
Show More
@@ -40,6 +40,7 b' from IPython.kernel.engineservice import EngineService, ThreadedEngineService'
40 from IPython.frontend.frontendbase import FrontEndBase
40 from IPython.frontend.frontendbase import FrontEndBase
41
41
42 from twisted.internet.threads import blockingCallFromThread
42 from twisted.internet.threads import blockingCallFromThread
43 from twisted.python.failure import Failure
43
44
44 #-------------------------------------------------------------------------------
45 #-------------------------------------------------------------------------------
45 # Classes to implement the Cocoa frontend
46 # Classes to implement the Cocoa frontend
@@ -305,7 +306,12 b' class IPythonCocoaController(NSObject, FrontEndBase):'
305 return block[-1]
306 return block[-1]
306
307
307 def update_cell_prompt(self, result):
308 def update_cell_prompt(self, result):
308 blockID = result['blockID']
309 if(isinstance(result, Failure)):
310 blockID = result.blockID
311 else:
312 blockID = result['blockID']
313
314
309 self.insert_text(self.input_prompt(result=result),
315 self.insert_text(self.input_prompt(result=result),
310 textRange=NSMakeRange(self.blockRanges[blockID].location,0),
316 textRange=NSMakeRange(self.blockRanges[blockID].location,0),
311 scrollToVisible=False
317 scrollToVisible=False
@@ -234,18 +234,23 b' class FrontEndBase(object):'
234 blockID = uuid.uuid4() #random UUID
234 blockID = uuid.uuid4() #random UUID
235
235
236 d = self.engine.execute(block)
236 d = self.engine.execute(block)
237 d.addCallback(self._add_block_id, blockID)
238 d.addCallback(self._add_history, block=block)
237 d.addCallback(self._add_history, block=block)
239 d.addCallback(self.update_cell_prompt)
238 d.addBoth(self._add_block_id, blockID)
239 d.addBoth(self.update_cell_prompt)
240 d.addCallbacks(self.render_result, errback=self.render_error)
240 d.addCallbacks(self.render_result, errback=self.render_error)
241
241
242 return d
242 return d
243
243
244
244
245 def _add_block_id(self, result, blockID):
245 def _add_block_id(self, result, blockID):
246 """Add the blockID to result"""
246 """Add the blockID to result or failure. Unfortunatley, we have to treat failures
247 differently than result dicts
248 """
247
249
248 result['blockID'] = blockID
250 if(isinstance(result, Failure)):
251 result.blockID = blockID
252 else:
253 result['blockID'] = blockID
249
254
250 return result
255 return result
251
256
@@ -287,7 +292,17 b' class FrontEndBase(object):'
287 def update_cell_prompt(self, result):
292 def update_cell_prompt(self, result):
288 """Subclass may override to update the input prompt for a block.
293 """Subclass may override to update the input prompt for a block.
289 Since this method will be called as a twisted.internet.defer.Deferred's callback,
294 Since this method will be called as a twisted.internet.defer.Deferred's callback,
290 implementations should return result when finished."""
295 implementations should return result when finished.
296
297 NP: result is a failure if the execute returned a failre. To get the blockID, you should
298 do something like::
299 if(isinstance(result, twisted.python.failure.Failure)):
300 blockID = result.blockID
301 else:
302 blockID = result['blockID']
303
304
305 """
291
306
292 return result
307 return result
293
308
@@ -80,10 +80,20 b' class TestFrontendBase(unittest.TestCase):'
80
80
81 d.addCallback(self.checkBlockID, expected='TEST_ID')
81 d.addCallback(self.checkBlockID, expected='TEST_ID')
82
82
83 def test_blockID_added_to_failure(self):
84 block = "raise Exception()"
85
86 d = self.fb.execute(block,blockID='TEST_ID')
87 d.addErrback(self.checkFailureID, expected='TEST_ID')
88
83 def checkBlockID(self, result, expected=""):
89 def checkBlockID(self, result, expected=""):
84 assert(result['blockID'] == expected)
90 assert(result['blockID'] == expected)
85
91
86
92
93 def checkFailureID(self, failure, expected=""):
94 assert(failure.blockID == expected)
95
96
87 def test_callbacks_added_to_execute(self):
97 def test_callbacks_added_to_execute(self):
88 """test that
98 """test that
89 update_cell_prompt
99 update_cell_prompt
General Comments 0
You need to be logged in to leave comments. Login now