Remove sleep from the following,

Button, float, int, multicontainer, selection widgets.
This commit is contained in:
Jonathan Frederic 2014-01-31 11:48:51 -08:00
parent d68112885b
commit a2044fd463
7 changed files with 98 additions and 89 deletions

View File

@ -45,15 +45,15 @@ casper.notebook_test(function () {
'.my-throttle-textbox'), 'Textbox exists.');
// Send 20 characters
this.sendKeys('.my-throttle-textbox', '...................A');
this.sendKeys('.my-throttle-textbox', '....................');
});
this.waitFor(function check() {
var outputs = this.evaluate(function(i) {
return IPython.notebook.get_cell(i).output_area.outputs;
}, {i : throttle_index});
var output = outputs[outputs.length-1].text;
return (output[output.length-1] == 'A');
var output = outputs[outputs.length-1].text.trim();
return (output == '20');
}, function then() {
var outputs = this.evaluate(function(i) {

View File

@ -34,11 +34,10 @@ casper.notebook_test(function () {
'.widget-area .widget-subarea button', 'click');
});
this.waitFor(function check() {
return (this.get_output_cell(button_index, 1).text == 'Clicked\n');
}, function then() {
this.test.assert(true, 'Button click event fires.');
}), function timeout() {
this.test.assert(false, 'Button click event fires.');
this.wait_for_output(button_index, 1);
this.then(function () {
this.test.assertEquals(this.get_output_cell(button_index, 1).text, 'Clicked\n',
'Button click event fires.');
});
});

View File

@ -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.');
});

View File

@ -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){

View File

@ -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){

View File

@ -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' +

View File

@ -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;