[WIP] [3335] Converting prompt_numbers.js test to selenium

arovitn 8 years ago
parent 4faed778b6
commit 5b0bc68e77

@ -1,36 +0,0 @@
// Test
casper.notebook_test(function () {
var that = this;
var set_prompt = function (i, val) {
that.evaluate(function (i, val) {
var cell = IPython.notebook.get_cell(i);
cell.set_input_prompt(val);
}, [i, val]);
};
var get_prompt = function (i) {
return that.evaluate(function (i) {
var elem = IPython.notebook.get_cell(i).element;
return elem.find('div.input_prompt').html();
}, [i]);
};
this.then(function () {
var a = 'print("a")';
var index = this.append_cell(a);
this.test.assertEquals(get_prompt(index), "<bdi>In</bdi>&nbsp;[&nbsp;]:", "prompt number is &nbsp; by default");
set_prompt(index, 2);
this.test.assertEquals(get_prompt(index), "<bdi>In</bdi>&nbsp;[2]:", "prompt number is 2");
set_prompt(index, 0);
this.test.assertEquals(get_prompt(index), "<bdi>In</bdi>&nbsp;[0]:", "prompt number is 0");
set_prompt(index, "*");
this.test.assertEquals(get_prompt(index), "<bdi>In</bdi>&nbsp;[*]:", "prompt number is *");
set_prompt(index, undefined);
this.test.assertEquals(get_prompt(index), "<bdi>In</bdi>&nbsp;[&nbsp;]:", "prompt number is &nbsp;");
set_prompt(index, null);
this.test.assertEquals(get_prompt(index), "<bdi>In</bdi>&nbsp;[&nbsp;]:", "prompt number is &nbsp;");
});
});

@ -0,0 +1,28 @@
import os
import pytest
import time
# selenium test version for 'prompt_numbers.js'
def get_prompt(nb, index):
cell = nb.cells[0]
return cell.find_element_by_class_name('input').find_element_by_class_name('input_prompt').get_attribute('innerHTML').strip()
def set_prompt(nb, index, value):
nb.set_cell_input_prompt(index, value)
def test_prompt_numbers(notebook):
cell_index = 0
a = 'print("a")'
notebook.edit_cell(index=cell_index, content=a)
assert get_prompt(notebook, cell_index) == "<bdi>In</bdi>&nbsp;[&nbsp;]:"
set_prompt(notebook, cell_index, 2);
assert get_prompt(notebook, cell_index) == "<bdi>In</bdi>&nbsp;[2]:"
set_prompt(notebook, cell_index, 0);
assert get_prompt(notebook, cell_index) == "<bdi>In</bdi>&nbsp;[0]:"
set_prompt(notebook, cell_index, "'*'");
assert get_prompt(notebook, cell_index) == "<bdi>In</bdi>&nbsp;[*]:"
set_prompt(notebook, cell_index, "undefined");
assert get_prompt(notebook, cell_index) == "<bdi>In</bdi>&nbsp;[&nbsp;]:"
set_prompt(notebook, cell_index, "null");
assert get_prompt(notebook, cell_index) == "<bdi>In</bdi>&nbsp;[&nbsp;]:"

@ -135,6 +135,10 @@ class Notebook:
JS = 'Jupyter.notebook.get_cell({}).metadata.{} = {}'.format(index, key, value)
return self.browser.execute_script(JS)
def set_cell_input_prompt(self, index, prmpt_val):
JS = 'Jupyter.notebook.get_cell({}).set_input_prompt({})'.format(index, prmpt_val)
self.browser.execute_script(JS)
def edit_cell(self, cell=None, index=0, content="", render=False):
"""Set the contents of a cell to *content*, by cell object or by index
"""

Loading…
Cancel
Save