mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-27 04:20:22 +08:00
Merge pull request #4952 from jdfreder/widget-tests
Widget test inconsistencies add wait_for_widget
This commit is contained in:
commit
978a5c1bc2
@ -16,8 +16,6 @@ casper.notebook_test(function () {
|
||||
'print("Success")');
|
||||
this.execute_cell_then(index);
|
||||
|
||||
this.wait(500); // Wait for require.js async callbacks to load dependencies.
|
||||
|
||||
this.then(function () {
|
||||
// Check if the widget manager has been instantiated.
|
||||
this.test.assert(this.evaluate(function() {
|
||||
@ -25,19 +23,19 @@ casper.notebook_test(function () {
|
||||
}), 'Notebook widget manager instantiated');
|
||||
});
|
||||
|
||||
var textbox = {};
|
||||
throttle_index = this.append_cell(
|
||||
'import time\n' +
|
||||
'textbox = widgets.TextWidget()\n' +
|
||||
'display(textbox)\n'+
|
||||
'display(textbox)\n' +
|
||||
'textbox.add_class("my-throttle-textbox")\n' +
|
||||
'def handle_change(name, old, new):\n' +
|
||||
' print(len(new))\n' +
|
||||
' time.sleep(0.5)\n' +
|
||||
'textbox.on_trait_change(handle_change, "value")\n' +
|
||||
'print("Success")');
|
||||
'print(textbox.model_id)');
|
||||
this.execute_cell_then(throttle_index, function(index){
|
||||
this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
|
||||
'Test throttling cell executed with correct output');
|
||||
textbox.model_id = this.get_output_cell(index).text.trim();
|
||||
|
||||
this.test.assert(this.cell_element_exists(index,
|
||||
'.widget-area .widget-subarea'),
|
||||
@ -50,9 +48,9 @@ casper.notebook_test(function () {
|
||||
this.sendKeys('.my-throttle-textbox', '....................');
|
||||
});
|
||||
|
||||
this.wait(2000); // Wait for clicks to execute in kernel
|
||||
this.wait_for_widget(textbox);
|
||||
|
||||
this.then(function(){
|
||||
this.then(function () {
|
||||
var outputs = this.evaluate(function(i) {
|
||||
return IPython.notebook.get_cell(i).output_area.outputs;
|
||||
}, {i : throttle_index});
|
||||
|
@ -34,7 +34,7 @@ casper.notebook_test(function () {
|
||||
'.widget-area .widget-subarea button', 'click');
|
||||
});
|
||||
|
||||
this.wait(500); // Wait for click to execute in kernel and write output
|
||||
this.wait_for_output(button_index, 1);
|
||||
|
||||
this.then(function () {
|
||||
this.test.assertEquals(this.get_output_cell(button_index, 1).text, 'Clicked\n',
|
||||
|
@ -6,72 +6,64 @@ casper.notebook_test(function () {
|
||||
'print("Success")');
|
||||
this.execute_cell_then(index);
|
||||
|
||||
var float_text_query_2 = '.widget-area .widget-subarea .widget-hbox-single .my-second-float-text';
|
||||
|
||||
var float_index = this.append_cell(
|
||||
var float_text = {};
|
||||
float_text.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-float-text';
|
||||
float_text.index = this.append_cell(
|
||||
'float_widget = widgets.FloatTextWidget()\n' +
|
||||
'display(float_widget)\n' +
|
||||
'float_widget.add_class("my-second-float-text")\n' +
|
||||
'print("Success")\n');
|
||||
this.execute_cell_then(float_index, function(index){
|
||||
|
||||
this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
|
||||
'Create float cell executed with correct output.');
|
||||
|
||||
'print(float_widget.model_id)\n');
|
||||
this.execute_cell_then(float_text.index, function(index){
|
||||
float_text.model_id = this.get_output_cell(index).text.trim();
|
||||
|
||||
this.test.assert(this.cell_element_exists(index,
|
||||
'.widget-area .widget-subarea'),
|
||||
'Widget subarea exists.');
|
||||
|
||||
this.test.assert(this.cell_element_exists(index, float_text_query_2),
|
||||
this.test.assert(this.cell_element_exists(index, float_text.query),
|
||||
'Widget float textbox exists.');
|
||||
|
||||
this.cell_element_function(float_index, float_text_query_2, 'val', ['']);
|
||||
this.sendKeys(float_text_query_2, '1.05');
|
||||
this.cell_element_function(float_text.index, float_text.query, 'val', ['']);
|
||||
this.sendKeys(float_text.query, '1.05');
|
||||
});
|
||||
|
||||
this.wait(500); // Wait for change to execute in kernel
|
||||
this.wait_for_widget(float_text);
|
||||
|
||||
index = this.append_cell('print(float_widget.value)\n');
|
||||
this.execute_cell_then(index, function(index){
|
||||
this.test.assertEquals(this.get_output_cell(index).text, '1.05\n',
|
||||
'Float textbox value set.');
|
||||
this.cell_element_function(float_index, float_text_query_2, 'val', ['']);
|
||||
this.sendKeys(float_text_query_2, '123456789.0');
|
||||
this.cell_element_function(float_text.index, float_text.query, 'val', ['']);
|
||||
this.sendKeys(float_text.query, '123456789.0');
|
||||
});
|
||||
|
||||
this.wait(500); // Wait for change to execute in kernel
|
||||
|
||||
this.wait_for_widget(float_text);
|
||||
|
||||
index = this.append_cell('print(float_widget.value)\n');
|
||||
this.execute_cell_then(index, function(index){
|
||||
this.test.assertEquals(this.get_output_cell(index).text, '123456789.0\n',
|
||||
'Long float textbox value set (probably triggers throttling).');
|
||||
this.cell_element_function(float_index, float_text_query_2, 'val', ['']);
|
||||
this.sendKeys(float_text_query_2, '12hello');
|
||||
this.cell_element_function(float_text.index, float_text.query, 'val', ['']);
|
||||
this.sendKeys(float_text.query, '12hello');
|
||||
});
|
||||
|
||||
this.wait(500); // Wait for change to execute in kernel
|
||||
this.wait_for_widget(float_text);
|
||||
|
||||
index = this.append_cell('print(float_widget.value)\n');
|
||||
this.execute_cell_then(index, function(index){
|
||||
this.test.assertEquals(this.get_output_cell(index).text, '12.0\n',
|
||||
'Invald float textbox value caught and filtered.');
|
||||
});
|
||||
|
||||
index = this.append_cell(
|
||||
'from IPython.html import widgets\n' +
|
||||
'from IPython.display import display, clear_output\n' +
|
||||
'print("Success")');
|
||||
this.execute_cell_then(index);
|
||||
|
||||
var slider_query = '.widget-area .widget-subarea .widget-hbox-single .slider';
|
||||
var float_text_query = '.widget-area .widget-subarea .widget-hbox-single .widget-numeric-text';
|
||||
|
||||
var floatrange_index = this.append_cell(
|
||||
var slider = {};
|
||||
slider.query = '.widget-area .widget-subarea .widget-hbox-single .slider';
|
||||
slider.index = this.append_cell(
|
||||
'floatrange = [widgets.BoundedFloatTextWidget(), \n' +
|
||||
' widgets.FloatSliderWidget()]\n' +
|
||||
'[display(floatrange[i]) for i in range(2)]\n' +
|
||||
'print("Success")\n');
|
||||
this.execute_cell_then(floatrange_index, function(index){
|
||||
this.execute_cell_then(slider.index, function(index){
|
||||
|
||||
this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
|
||||
'Create float range cell executed with correct output.');
|
||||
@ -80,7 +72,7 @@ casper.notebook_test(function () {
|
||||
'.widget-area .widget-subarea'),
|
||||
'Widget subarea exists.');
|
||||
|
||||
this.test.assert(this.cell_element_exists(index, slider_query),
|
||||
this.test.assert(this.cell_element_exists(index, slider.query),
|
||||
'Widget slider exists.');
|
||||
|
||||
this.test.assert(this.cell_element_exists(index, float_text_query),
|
||||
@ -98,10 +90,10 @@ casper.notebook_test(function () {
|
||||
this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
|
||||
'Float range properties cell executed with correct output.');
|
||||
|
||||
this.test.assert(this.cell_element_exists(floatrange_index, slider_query),
|
||||
this.test.assert(this.cell_element_exists(slider.index, slider.query),
|
||||
'Widget slider exists.');
|
||||
|
||||
this.test.assert(this.cell_element_function(floatrange_index, slider_query,
|
||||
this.test.assert(this.cell_element_function(slider.index, slider.query,
|
||||
'slider', ['value']) == 25.0,
|
||||
'Slider set to Python value.');
|
||||
});
|
||||
|
@ -6,50 +6,48 @@ casper.notebook_test(function () {
|
||||
'print("Success")');
|
||||
this.execute_cell_then(index);
|
||||
|
||||
var int_text_query_2 = '.widget-area .widget-subarea .widget-hbox-single .my-second-int-text';
|
||||
|
||||
var int_index = this.append_cell(
|
||||
var int_text = {}
|
||||
int_text.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-int-text';
|
||||
int_text.index = this.append_cell(
|
||||
'int_widget = widgets.IntTextWidget()\n' +
|
||||
'display(int_widget)\n' +
|
||||
'int_widget.add_class("my-second-int-text")\n' +
|
||||
'print("Success")\n');
|
||||
this.execute_cell_then(int_index, function(index){
|
||||
|
||||
this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
|
||||
'Create int cell executed with correct output.');
|
||||
|
||||
'print(int_widget.model_id)\n');
|
||||
this.execute_cell_then(int_text.index, function(index){
|
||||
int_text.model_id = this.get_output_cell(index).text.trim();
|
||||
|
||||
this.test.assert(this.cell_element_exists(index,
|
||||
'.widget-area .widget-subarea'),
|
||||
'Widget subarea exists.');
|
||||
|
||||
this.test.assert(this.cell_element_exists(index, int_text_query_2),
|
||||
this.test.assert(this.cell_element_exists(index, int_text.query),
|
||||
'Widget int textbox exists.');
|
||||
|
||||
this.cell_element_function(int_index, int_text_query_2, 'val', ['']);
|
||||
this.sendKeys(int_text_query_2, '1.05');
|
||||
this.cell_element_function(int_text.index, int_text.query, 'val', ['']);
|
||||
this.sendKeys(int_text.query, '1.05');
|
||||
});
|
||||
|
||||
this.wait(500); // Wait for change to execute in kernel
|
||||
this.wait_for_widget(int_text);
|
||||
|
||||
index = this.append_cell('print(int_widget.value)\n');
|
||||
this.execute_cell_then(index, function(index){
|
||||
this.test.assertEquals(this.get_output_cell(index).text, '1\n',
|
||||
'Int textbox value set.');
|
||||
this.cell_element_function(int_index, int_text_query_2, 'val', ['']);
|
||||
this.sendKeys(int_text_query_2, '123456789');
|
||||
this.cell_element_function(int_text.index, int_text.query, 'val', ['']);
|
||||
this.sendKeys(int_text.query, '123456789');
|
||||
});
|
||||
|
||||
this.wait(500); // Wait for change to execute in kernel
|
||||
this.wait_for_widget(int_text);
|
||||
|
||||
index = this.append_cell('print(int_widget.value)\n');
|
||||
this.execute_cell_then(index, function(index){
|
||||
this.test.assertEquals(this.get_output_cell(index).text, '123456789\n',
|
||||
'Long int textbox value set (probably triggers throttling).');
|
||||
this.cell_element_function(int_index, int_text_query_2, 'val', ['']);
|
||||
this.sendKeys(int_text_query_2, '12hello');
|
||||
this.cell_element_function(int_text.index, int_text.query, 'val', ['']);
|
||||
this.sendKeys(int_text.query, '12hello');
|
||||
});
|
||||
|
||||
this.wait(500); // Wait for change to execute in kernel
|
||||
this.wait_for_widget(int_text);
|
||||
|
||||
index = this.append_cell('print(int_widget.value)\n');
|
||||
this.execute_cell_then(index, function(index){
|
||||
@ -63,19 +61,18 @@ casper.notebook_test(function () {
|
||||
'print("Success")');
|
||||
this.execute_cell_then(index);
|
||||
|
||||
var slider_query = '.widget-area .widget-subarea .widget-hbox-single .slider';
|
||||
var int_text_query = '.widget-area .widget-subarea .widget-hbox-single .my-second-num-test-text';
|
||||
|
||||
var intrange_index = this.append_cell(
|
||||
var slider_query = '.widget-area .widget-subarea .widget-hbox-single .slider';
|
||||
var int_text2 = {};
|
||||
int_text2.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-num-test-text';
|
||||
int_text2.index = this.append_cell(
|
||||
'intrange = [widgets.BoundedIntTextWidget(),\n' +
|
||||
' widgets.IntSliderWidget()]\n' +
|
||||
'[display(intrange[i]) for i in range(2)]\n' +
|
||||
'intrange[0].add_class("my-second-num-test-text")\n' +
|
||||
'print("Success")\n');
|
||||
this.execute_cell_then(intrange_index, function(index){
|
||||
|
||||
this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
|
||||
'Create int range cell executed with correct output.');
|
||||
'print(intrange[0].model_id)\n');
|
||||
this.execute_cell_then(int_text2.index, function(index){
|
||||
int_text2.model_id = this.get_output_cell(index).text.trim();
|
||||
|
||||
this.test.assert(this.cell_element_exists(index,
|
||||
'.widget-area .widget-subarea'),
|
||||
@ -84,7 +81,7 @@ casper.notebook_test(function () {
|
||||
this.test.assert(this.cell_element_exists(index, slider_query),
|
||||
'Widget slider exists.');
|
||||
|
||||
this.test.assert(this.cell_element_exists(index, int_text_query),
|
||||
this.test.assert(this.cell_element_exists(index, int_text2.query),
|
||||
'Widget int textbox exists.');
|
||||
});
|
||||
|
||||
@ -99,23 +96,23 @@ casper.notebook_test(function () {
|
||||
this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
|
||||
'Int range properties cell executed with correct output.');
|
||||
|
||||
this.test.assert(this.cell_element_exists(intrange_index, slider_query),
|
||||
this.test.assert(this.cell_element_exists(int_text2.index, slider_query),
|
||||
'Widget slider exists.');
|
||||
|
||||
this.test.assert(this.cell_element_function(intrange_index, slider_query,
|
||||
this.test.assert(this.cell_element_function(int_text2.index, slider_query,
|
||||
'slider', ['value']) == 25,
|
||||
'Slider set to Python value.');
|
||||
|
||||
this.test.assert(this.cell_element_function(intrange_index, int_text_query,
|
||||
this.test.assert(this.cell_element_function(int_text2.index, int_text2.query,
|
||||
'val') == 25, 'Int textbox set to Python value.');
|
||||
|
||||
// Clear the int textbox value and then set it to 1 by emulating
|
||||
// keyboard presses.
|
||||
this.cell_element_function(intrange_index, int_text_query, 'val', ['']);
|
||||
this.sendKeys(int_text_query, '1');
|
||||
this.cell_element_function(int_text2.index, int_text2.query, 'val', ['']);
|
||||
this.sendKeys(int_text2.query, '1');
|
||||
});
|
||||
|
||||
this.wait(500); // Wait for change to execute in kernel
|
||||
this.wait_for_widget(int_text2);
|
||||
|
||||
index = this.append_cell('print(intrange[0].value)\n');
|
||||
this.execute_cell_then(index, function(index){
|
||||
@ -124,11 +121,11 @@ casper.notebook_test(function () {
|
||||
|
||||
// Clear the int textbox value and then set it to 120 by emulating
|
||||
// keyboard presses.
|
||||
this.cell_element_function(intrange_index, int_text_query, 'val', ['']);
|
||||
this.sendKeys(int_text_query, '120');
|
||||
this.cell_element_function(int_text2.index, int_text2.query, 'val', ['']);
|
||||
this.sendKeys(int_text2.query, '120');
|
||||
});
|
||||
|
||||
this.wait(500); // Wait for change to execute in kernel
|
||||
this.wait_for_widget(int_text2);
|
||||
|
||||
index = this.append_cell('print(intrange[0].value)\n');
|
||||
this.execute_cell_then(index, function(index){
|
||||
@ -137,11 +134,11 @@ casper.notebook_test(function () {
|
||||
|
||||
// Clear the int textbox value and then set it to 'hello world' by
|
||||
// emulating keyboard presses. 'hello world' should get filtered...
|
||||
this.cell_element_function(intrange_index, int_text_query, 'val', ['']);
|
||||
this.sendKeys(int_text_query, 'hello world');
|
||||
this.cell_element_function(int_text2.index, int_text2.query, 'val', ['']);
|
||||
this.sendKeys(int_text2.query, 'hello world');
|
||||
});
|
||||
|
||||
this.wait(500); // Wait for change to execute in kernel
|
||||
this.wait_for_widget(int_text2);
|
||||
|
||||
index = this.append_cell('print(intrange[0].value)\n');
|
||||
this.execute_cell_then(index, function(index){
|
||||
|
@ -36,7 +36,7 @@ casper.notebook_test(function () {
|
||||
this.click(multicontainer1_query + ' li:nth-child(2) a');
|
||||
});
|
||||
|
||||
this.wait(500); // Wait for change to execute in kernel
|
||||
this.wait_for_idle();
|
||||
|
||||
index = this.append_cell(
|
||||
'print(multicontainer.selected_index)\n' +
|
||||
@ -98,7 +98,7 @@ casper.notebook_test(function () {
|
||||
this.click(multicontainer2_query + ' .accordion-group:nth-child(2) .accordion-heading .accordion-toggle');
|
||||
});
|
||||
|
||||
this.wait(500); // Wait for change to execute in kernel
|
||||
this.wait_for_idle();
|
||||
|
||||
index = this.append_cell('print(multicontainer.selected_index)'); // 0 based
|
||||
this.execute_cell_then(index, function(index){
|
||||
|
@ -93,33 +93,33 @@ casper.notebook_test(function () {
|
||||
// Verify that selecting a radio button updates all of the others.
|
||||
this.cell_element_function(selection_index, radio_selector + ' .radio:nth-child(2) input', 'click');
|
||||
});
|
||||
this.wait(500);
|
||||
this.wait_for_idle();
|
||||
this.then(function () {
|
||||
this.test.assert(verify_selection(this, 1), 'Radio button selection updated view states correctly.');
|
||||
|
||||
// Verify that selecting a list option updates all of the others.
|
||||
this.cell_element_function(selection_index, list_selector + ' option:nth-child(3)', 'click');
|
||||
});
|
||||
this.wait(500);
|
||||
this.wait_for_idle();
|
||||
this.then(function () {
|
||||
this.test.assert(verify_selection(this, 2), 'List selection updated view states correctly.');
|
||||
|
||||
// Verify that selecting a multibutton option updates all of the others.
|
||||
this.cell_element_function(selection_index, multibtn_selector + ' .btn:nth-child(4)', 'click');
|
||||
});
|
||||
this.wait(500);
|
||||
this.wait_for_idle();
|
||||
this.then(function () {
|
||||
this.test.assert(verify_selection(this, 3), 'Multibutton selection updated view states correctly.');
|
||||
|
||||
// Verify that selecting a combobox option updates all of the others.
|
||||
this.cell_element_function(selection_index, '.widget-area .widget-subarea .widget-hbox-single .btn-group ul.dropdown-menu li:nth-child(3) a', 'click');
|
||||
});
|
||||
this.wait(500);
|
||||
this.wait_for_idle();
|
||||
this.then(function () {
|
||||
this.test.assert(verify_selection(this, 2), 'Combobox selection updated view states correctly.');
|
||||
});
|
||||
|
||||
this.wait(500); // Wait for change to execute in kernel
|
||||
this.wait_for_idle();
|
||||
|
||||
index = this.append_cell(
|
||||
'for widget in selection:\n' +
|
||||
|
@ -38,13 +38,6 @@ casper.notebook_test(function () {
|
||||
'.widget-area .widget-subarea .widget-hbox-single input[type=text]', 'val')=='xyz',
|
||||
'Python set textbox value.');
|
||||
|
||||
});
|
||||
|
||||
this.wait(500); // Wait for change to execute in kernel
|
||||
|
||||
index = this.append_cell('print(string_widget.value)');
|
||||
this.execute_cell_then(index, function(index){
|
||||
|
||||
this.test.assert(this.cell_element_exists(string_index,
|
||||
'.widget-area .widget-subarea div span.MathJax_Preview'),
|
||||
'MathJax parsed the LaTeX successfully.');
|
||||
|
@ -94,6 +94,27 @@ casper.wait_for_output = function (cell_num, out_num) {
|
||||
});
|
||||
};
|
||||
|
||||
// wait for a widget msg que to reach 0
|
||||
//
|
||||
// Parameters
|
||||
// ----------
|
||||
// widget_info : object
|
||||
// Object which contains info related to the widget. The model_id property
|
||||
// is used to identify the widget.
|
||||
casper.wait_for_widget = function (widget_info) {
|
||||
this.waitFor(function () {
|
||||
var pending = this.evaluate(function (m) {
|
||||
return IPython.notebook.kernel.widget_manager.get_model(m).pending_msgs;
|
||||
}, {m: widget_info.model_id});
|
||||
|
||||
if (pending == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// return an output of a given cell
|
||||
casper.get_output_cell = function (cell_num, out_num) {
|
||||
out_num = out_num || 0;
|
||||
|
Loading…
Reference in New Issue
Block a user