From cb957315b4f4870957feac801c08d2d9abb4e73b 2014-01-12 21:54:47 From: Paul Ivanov Date: 2014-01-12 21:54:47 Subject: [PATCH] refactor clearing and executing first cell in test --- diff --git a/IPython/html/tests/casperjs/test_cases/nb_roundtrip.js b/IPython/html/tests/casperjs/test_cases/nb_roundtrip.js index 738113f..eb6b5b6 100644 --- a/IPython/html/tests/casperjs/test_cases/nb_roundtrip.js +++ b/IPython/html/tests/casperjs/test_cases/nb_roundtrip.js @@ -49,6 +49,18 @@ function check_output_area(output_type, keys) { } } + +// helper function to clear the first two cells, set the text of and execute +// the first one +function clear_and_execute(that, code) { + that.evaluate(function() { + IPython.notebook.get_cell(0).clear_output(); + IPython.notebook.get_cell(1).clear_output(); + }); + that.set_cell_text(0, code); + that.execute_cell(0); +} + casper.notebook_test(function () { this.evaluate(function () { var cell = IPython.notebook.get_cell(0); @@ -80,13 +92,7 @@ casper.notebook_test(function () { }); this.then(function() { - // test output of text/plain and application/json keys - this.evaluate(function() { - IPython.notebook.get_cell(0).clear_output(); - IPython.notebook.get_cell(1).clear_output(); - }); - this.set_cell_text(0, "%lsmagic"); - this.execute_cell(0); + clear_and_execute(this, '%lsmagic'); }); this.then(function () { @@ -94,12 +100,7 @@ casper.notebook_test(function () { }); this.then(function() { - // test display of text/plain and application/json keys - this.evaluate(function() { - IPython.notebook.get_cell(0).clear_output(); - IPython.notebook.get_cell(1).clear_output(); - }); - this.set_cell_text(0, + clear_and_execute(this, "x = %lsmagic\nfrom IPython.display import display; display(x)"); this.execute_cell(0); });