Show More
@@ -204,9 +204,11 b' casper.append_cell = function(text, cell_type) {' | |||
|
204 | 204 | return index; |
|
205 | 205 | }; |
|
206 | 206 | |
|
207 | casper.execute_cell = function(index){ | |
|
207 | casper.execute_cell = function(index, expect_failure){ | |
|
208 | 208 | // Asynchronously executes a cell by index. |
|
209 | 209 | // Returns the cell's index. |
|
210 | ||
|
211 | if (expect_failure === undefined) expect_failure = false; | |
|
210 | 212 | var that = this; |
|
211 | 213 | this.then(function(){ |
|
212 | 214 | that.evaluate(function (index) { |
@@ -214,15 +216,37 b' casper.execute_cell = function(index){' | |||
|
214 | 216 | cell.execute(); |
|
215 | 217 | }, index); |
|
216 | 218 | }); |
|
219 | this.wait_for_idle(); | |
|
220 | ||
|
221 | this.then(function () { | |
|
222 | var error = that.evaluate(function (index) { | |
|
223 | var cell = IPython.notebook.get_cell(index); | |
|
224 | var outputs = cell.output_area.outputs; | |
|
225 | for (var i = 0; i < outputs.length; i++) { | |
|
226 | if (outputs[i].output_type == 'error') { | |
|
227 | return outputs[i]; | |
|
228 | } | |
|
229 | } | |
|
230 | return false; | |
|
231 | }, index); | |
|
232 | if (error === null) { | |
|
233 | this.test.fail("Failed to check for error output"); | |
|
234 | } | |
|
235 | if (expect_failure && error === false) { | |
|
236 | this.test.fail("Expected error while running cell"); | |
|
237 | } else if (!expect_failure && error !== false) { | |
|
238 | this.test.fail("Error running cell:\n" + error.traceback.join('\n')); | |
|
239 | } | |
|
240 | }); | |
|
217 | 241 | return index; |
|
218 | 242 | }; |
|
219 | 243 | |
|
220 | casper.execute_cell_then = function(index, then_callback) { | |
|
244 | casper.execute_cell_then = function(index, then_callback, expect_failure) { | |
|
221 | 245 | // Synchronously executes a cell by index. |
|
222 | 246 | // Optionally accepts a then_callback parameter. then_callback will get called |
|
223 | 247 | // when the cell has finished executing. |
|
224 | 248 | // Returns the cell's index. |
|
225 | var return_val = this.execute_cell(index); | |
|
249 | var return_val = this.execute_cell(index, expect_failure); | |
|
226 | 250 | |
|
227 | 251 | this.wait_for_idle(); |
|
228 | 252 | |
@@ -231,7 +255,7 b' casper.execute_cell_then = function(index, then_callback) {' | |||
|
231 | 255 | if (then_callback!==undefined) { |
|
232 | 256 | then_callback.apply(that, [index]); |
|
233 | 257 | } |
|
234 |
}); |
|
|
258 | }); | |
|
235 | 259 | |
|
236 | 260 | return return_val; |
|
237 | 261 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now