##// END OF EJS Templates
fixes and tests for history
Barry Wark -
Show More
@@ -197,7 +197,7 b' class IPythonCocoaController(NSObject, FrontEndBase):'
197 197 return True
198 198
199 199 elif(selector == 'moveDown:'):
200 nextBlock = self.get_history_next(self.currentBlock())
200 nextBlock = self.get_history_next()
201 201 if(nextBlock != None):
202 202 self.replaceCurrentBlockWithString(textView, nextBlock)
203 203 else:
@@ -115,10 +115,11 b' class IFrontEnd(zi.Interface):'
115 115
116 116
117 117 def get_history_previous(currentBlock):
118 """Returns the block previous in the history."""
118 """Returns the block previous in the history. Saves currentBlock if
119 the history_cursor is currently at the end of the input history"""
119 120 pass
120 121
121 def get_history_next(currentBlock):
122 def get_history_next():
122 123 """Returns the next block in the history."""
123 124
124 125 pass
@@ -261,21 +262,21 b' class FrontEndBase(object):'
261 262 def get_history_previous(self, currentBlock):
262 263 """ Returns previous history string and decrement history cursor.
263 264 """
264 print self.history
265 265 command = self.history.get_history_item(self.history_cursor - 1)
266 print command
266
267 267 if command is not None:
268 if(self.history_cursor == len(self.history.input_cache)):
268 269 self.history.input_cache[self.history_cursor] = currentBlock
269 270 self.history_cursor -= 1
270 271 return command
271 272
272 273
273 def get_history_next(self, currentBlock):
274 def get_history_next(self):
274 275 """ Returns next history string and increment history cursor.
275 276 """
276 277 command = self.history.get_history_item(self.history_cursor + 1)
278
277 279 if command is not None:
278 self.history.input_cache[self.history_cursor] = currentBlock
279 280 self.history_cursor += 1
280 281 return command
281 282
@@ -110,5 +110,30 b' class TestFrontendBase(unittest.TestCase):'
110 110 def checkRenderError(self, result):
111 111 assert(self.fb.renderErrorCalled)
112 112
113 # TODO: add tests for history
113 def test_history_returns_expected_block(self):
114 """Make sure history browsing doesn't fail"""
115
116 blocks = ["a=1","a=2","a=3"]
117 for b in blocks:
118 d = self.fb.execute(b)
119
120 # d is now the deferred for the last executed block
121 d.addCallback(self.historyTests, blocks)
122
123
124 def historyTests(self, result, blocks):
125 """historyTests"""
126
127 assert(len(blocks) >= 3)
128 assert(self.fb.get_history_previous("") == blocks[-2])
129 assert(self.fb.get_history_previous("") == blocks[-3])
130 assert(self.fb.get_history_next() == blocks[-2])
131
132
133 def test_history_returns_none_at_startup(self):
134 """test_history_returns_none_at_startup"""
135
136 assert(self.fb.get_history_previous("")==None)
137 assert(self.fb.get_history_next()==None)
138
114 139
General Comments 0
You need to be logged in to leave comments. Login now