Show More
@@ -1,25 +1,6 b'' | |||||
1 | // |
|
|||
2 | // Test the widget framework. |
|
1 | // Test the widget framework. | |
3 | // |
|
|||
4 | casper.notebook_test(function () { |
|
2 | casper.notebook_test(function () { | |
5 | //this.test.begin("widget tests (notebook)", 2, function(test) { |
|
3 | var index; | |
6 |
|
||||
7 |
|
||||
8 | // Utility function that allows us to easily execute a cell of python code |
|
|||
9 | // and wait for the results. |
|
|||
10 | var that = this; |
|
|||
11 | var run_python_code = function(code){ |
|
|||
12 | var index = that.evaluate(function (code) { |
|
|||
13 | var index = IPython.notebook.ncells(); |
|
|||
14 | var cell = IPython.notebook.insert_cell_at_index('code', index); |
|
|||
15 | cell.set_text(code); |
|
|||
16 | cell.execute(); |
|
|||
17 | return index; |
|
|||
18 | }, code); |
|
|||
19 |
|
||||
20 | that.wait_for_output(index); |
|
|||
21 | return index; |
|
|||
22 | }; |
|
|||
23 |
|
4 | |||
24 | // Test widget dependencies //////////////////////////////////////////////// |
|
5 | // Test widget dependencies //////////////////////////////////////////////// | |
25 | this.then(function () { |
|
6 | this.then(function () { | |
@@ -30,9 +11,12 b' casper.notebook_test(function () {' | |||||
30 | }), 'WidgetManager class is defined'); |
|
11 | }), 'WidgetManager class is defined'); | |
31 | }); |
|
12 | }); | |
32 |
|
13 | |||
33 | run_python_code('from IPython.html import widgets\n' + |
|
14 | index = append_cell( | |
34 |
|
|
15 | 'from IPython.html import widgets\n' + | |
35 | 'print("Success")'); |
|
16 | 'from IPython.display import display, clear_output\n' + | |
|
17 | 'print("Success")'); | |||
|
18 | execute_cell_then(index); | |||
|
19 | ||||
36 | this.wait(500); // Wait for require.js async callbacks to load dependencies. |
|
20 | this.wait(500); // Wait for require.js async callbacks to load dependencies. | |
37 |
|
21 | |||
38 | this.then(function () { |
|
22 | this.then(function () { | |
@@ -44,12 +28,13 b' casper.notebook_test(function () {' | |||||
44 |
|
28 | |||
45 |
|
29 | |||
46 | // Check widget mapping //////////////////////////////////////////////////// |
|
30 | // Check widget mapping //////////////////////////////////////////////////// | |
47 | var names_cell_index = run_python_code('names = [name for name in dir(widgets)' + |
|
31 | index = append_cell( | |
|
32 | 'names = [name for name in dir(widgets)' + | |||
48 | ' if name.endswith("Widget") and name!= "Widget"]\n' + |
|
33 | ' if name.endswith("Widget") and name!= "Widget"]\n' + | |
49 | 'for name in names:\n' + |
|
34 | 'for name in names:\n' + | |
50 | ' print(name)\n'); |
|
35 | ' print(name)\n'); | |
|
36 | execute_cell_then(index, function(index){ | |||
51 |
|
37 | |||
52 | this.then(function () { |
|
|||
53 | // Get the widget names that are registered with the widget manager. Assume |
|
38 | // Get the widget names that are registered with the widget manager. Assume | |
54 | // a 1 to 1 mapping of model and widgets names (model names just have 'model' |
|
39 | // a 1 to 1 mapping of model and widgets names (model names just have 'model' | |
55 | // suffixed). |
|
40 | // suffixed). | |
@@ -62,7 +47,7 b' casper.notebook_test(function () {' | |||||
62 | }); |
|
47 | }); | |
63 |
|
48 | |||
64 | // Get the widget names registered in python. |
|
49 | // Get the widget names registered in python. | |
65 |
var python_names = this.get_output_cell( |
|
50 | var python_names = this.get_output_cell(index).text.split('\n'); | |
66 |
|
51 | |||
67 | // Make sure the two lists have the same items. |
|
52 | // Make sure the two lists have the same items. | |
68 | for (var i in javascript_names) { |
|
53 | for (var i in javascript_names) { | |
@@ -92,53 +77,57 b' casper.notebook_test(function () {' | |||||
92 | } |
|
77 | } | |
93 | } |
|
78 | } | |
94 | }); |
|
79 | }); | |
95 |
|
||||
96 |
|
80 | |||
97 |
|
81 | |||
98 | // Test button widget ////////////////////////////////////////////////////// |
|
82 | // Test button widget ////////////////////////////////////////////////////// | |
99 | button_cell_index = run_python_code('button = widgets.ButtonWidget(description="Title")\n' + |
|
83 | var button_cell_index = append_cell( | |
|
84 | 'button = widgets.ButtonWidget(description="Title")\n' + | |||
100 | 'display(button)\n'+ |
|
85 | 'display(button)\n'+ | |
101 | 'print("Success")\n' + |
|
86 | 'print("Success")\n' + | |
102 | 'def handle_click(sender):\n' + |
|
87 | 'def handle_click(sender):\n' + | |
103 | ' print("Clicked")\n' + |
|
88 | ' print("Clicked")\n' + | |
104 | 'button.on_click(handle_click)'); |
|
89 | 'button.on_click(handle_click)'); | |
|
90 | execute_cell_then(button_cell_index, function(index){ | |||
105 |
|
91 | |||
106 | this.then(function () { |
|
92 | var button_output = this.get_output_cell(index).text; | |
107 | var button_output = this.get_output_cell(button_cell_index).text; |
|
93 | this.test.assert(button_output == 'Success\n', | |
108 |
|
|
94 | 'Create button widget, cell executed with correct output.'); | |
109 |
|
95 | |||
110 | this.test.assert(casper.evaluate(function (i) { |
|
96 | this.test.assert(cell_element_exists(index, | |
111 | var $cell = IPython.notebook.get_cell(i).element; |
|
97 | '.widget-area .widget-subarea'), | |
112 | return $cell.find('.widget-area').find('.widget-subarea').length > 0; |
|
98 | 'Create button widget, widget subarea exist.'); | |
113 | }, |
|
99 | ||
114 | {i : button_cell_index}), 'Create button widget, widget subarea exist.'); |
|
100 | this.test.assert(cell_element_exists(index, | |
115 |
|
101 | '.widget-area .widget-subarea button'), | ||
116 | this.test.assert(casper.evaluate(function (i) { |
|
102 | 'Create button widget, widget button exist.'); | |
117 | var $cell = IPython.notebook.get_cell(i).element; |
|
103 | ||
118 | return $cell.find('.widget-area').find('.widget-subarea').find('button').length > 0; |
|
104 | this.test.assert(cell_element_function(index, | |
119 | }, |
|
105 | '.widget-area .widget-subarea button', 'html')=='Title', | |
120 | {i : button_cell_index}), 'Create button widget, widget button exist.'); |
|
106 | 'Set button description.'); | |
121 |
|
107 | |||
122 | this.test.assert(casper.evaluate(function (i) { |
|
108 | cell_element_function(index, | |
123 | var $cell = IPython.notebook.get_cell(i).element; |
|
109 | '.widget-area .widget-subarea button', 'click'); | |
124 | return $cell.find('.widget-area').find('.widget-subarea').find('button').html() == 'Title'; |
|
|||
125 | }, |
|
|||
126 | {i : button_cell_index}), 'Set button description.'); |
|
|||
127 |
|
||||
128 | casper.evaluate(function (i) { |
|
|||
129 | var $cell = IPython.notebook.get_cell(i).element; |
|
|||
130 | $cell.find('.widget-area').find('.widget-subarea').find('button').click(); |
|
|||
131 | }, |
|
|||
132 | {i : button_cell_index}); |
|
|||
133 | }); |
|
110 | }); | |
134 |
|
111 | |||
135 |
this.wait( |
|
112 | this.wait(500); // Wait for click to execute in kernel and write output | |
136 |
|
113 | |||
137 | this.then(function () { |
|
114 | this.then(function () { | |
138 |
|
|
115 | this.test.assert(this.get_output_cell(button_cell_index, 1).text == 'Clicked\n', | |
139 |
|
|
116 | 'Button click event fires.'); | |
140 | }); |
|
117 | }); | |
141 |
|
118 | |||
142 | //}); // end of test.begin |
|
119 | index = append_cell( | |
|
120 | 'button.close()\n'+ | |||
|
121 | 'print("Success")\n'); | |||
|
122 | execute_cell_then(index, function(index){ | |||
|
123 | ||||
|
124 | var button_output = this.get_output_cell(index).text; | |||
|
125 | this.test.assert(button_output == 'Success\n', | |||
|
126 | 'Close button, cell executed with correct output.'); | |||
|
127 | ||||
|
128 | this.test.assert(! cell_element_exists(button_cell_index, | |||
|
129 | '.widget-area .widget-subarea button'), | |||
|
130 | 'Remove button, widget button doesn\'t exist.'); | |||
|
131 | }); | |||
143 | }); |
|
132 | }); | |
144 |
|
133 |
@@ -59,19 +59,17 b' casper.delete_current_notebook = function () {' | |||||
59 |
|
59 | |||
60 | // wait for output in a given cell |
|
60 | // wait for output in a given cell | |
61 | casper.wait_for_output = function (cell_num) { |
|
61 | casper.wait_for_output = function (cell_num) { | |
62 |
this. |
|
62 | this.waitFor(function (c) { | |
63 |
this. |
|
63 | return this.evaluate(function get_output(c) { | |
64 | return this.evaluate(function get_output(c) { |
|
64 | var cell = IPython.notebook.get_cell(c); | |
65 | var cell = IPython.notebook.get_cell(c); |
|
65 | return cell.output_area.outputs.length != 0; | |
66 | return cell.output_area.outputs.length != 0; |
|
|||
67 | }, |
|
|||
68 | // pass parameter from the test suite js to the browser code js |
|
|||
69 | {c : cell_num}); |
|
|||
70 | }, |
|
66 | }, | |
71 | function then() { }, |
|
67 | // pass parameter from the test suite js to the browser code js | |
72 | function timeout() { |
|
68 | {c : cell_num}); | |
73 | this.echo("wait_for_output timedout!"); |
|
69 | }, | |
74 | }); |
|
70 | function then() { }, | |
|
71 | function timeout() { | |||
|
72 | this.echo("wait_for_output timed out!"); | |||
75 | }); |
|
73 | }); | |
76 | }; |
|
74 | }; | |
77 |
|
75 |
General Comments 0
You need to be logged in to leave comments.
Login now