##// END OF EJS Templates
Fixed casperjs widget tests...
Jonathan Frederic -
Show More
@@ -1,97 +1,99 b''
1 //
1 //
2 // Test the widget framework.
2 // Test the widget framework.
3 //
3 //
4 casper.notebook_test(function () {
4 casper.notebook_test(function () {
5 //this.test.begin("widget tests (notebook)", 2, function(test) {
5 //this.test.begin("widget tests (notebook)", 2, function(test) {
6
6
7
7
8 // Utility function that allows us to easily execute a cell of python code
8 // Utility function that allows us to easily execute a cell of python code
9 // and wait for the results.
9 // and wait for the results.
10 var that = this;
10 var that = this;
11 var run_python_code = function(code){
11 var run_python_code = function(code){
12 var index = that.evaluate(function (code) {
12 var index = that.evaluate(function (code) {
13 var index = IPython.notebook.ncells();
13 var index = IPython.notebook.ncells();
14 var cell = IPython.notebook.insert_cell_at_index('code', index);
14 var cell = IPython.notebook.insert_cell_at_index('code', index);
15 cell.set_text(code);
15 cell.set_text(code);
16 cell.execute();
16 cell.execute();
17 return index;
17 return index;
18 }, code);
18 }, code);
19
19
20 that.wait_for_output(index);
20 that.wait_for_output(index);
21 return index;
21 return index;
22 };
22 };
23
23
24 // Test widget dependencies ////////////////////////////////////////////////
24 // Test widget dependencies ////////////////////////////////////////////////
25 run_python_code('from IPython.html import widgets\n' +
26 'from IPython.display import display, clear_output\n' +
27 'widgets.init_widget_js()');
28 this.wait(500); // Wait for require.js async callbacks to load dependencies.
29
30 this.then(function () {
25 this.then(function () {
31
26
32 // Check if the WidgetManager class is defined.
27 // Check if the WidgetManager class is defined.
33 this.test.assert(this.evaluate(function() {
28 this.test.assert(this.evaluate(function() {
34 return IPython.WidgetManager != undefined;
29 return IPython.WidgetManager != undefined;
35 }), 'WidgetManager class is defined');
30 }), 'WidgetManager class is defined');
36
31 });
32
33 run_python_code('from IPython.html import widgets\n' +
34 'from IPython.display import display, clear_output\n' +
35 'print("Success")');
36 this.wait(500); // Wait for require.js async callbacks to load dependencies.
37
38 this.then(function () {
37 // Check if the widget manager has been instanciated.
39 // Check if the widget manager has been instanciated.
38 this.test.assert(this.evaluate(function() {
40 this.test.assert(this.evaluate(function() {
39 return IPython.notebook.widget_manager != undefined;
41 return IPython.widget_manager != undefined;
40 }), 'Notebook widget manager instanciated');
42 }), 'Notebook widget manager instanciated');
41 });
43 });
42
44
43
45
44 // Check widget mapping ////////////////////////////////////////////////////
46 // Check widget mapping ////////////////////////////////////////////////////
45 var cell_index = run_python_code('names = [name for name in dir(widgets)' +
47 var cell_index = run_python_code('names = [name for name in dir(widgets)' +
46 ' if name.endswith("Widget") and name!= "Widget"]\n' +
48 ' if name.endswith("Widget") and name!= "Widget"]\n' +
47 'for name in names:\n' +
49 'for name in names:\n' +
48 ' print(name)\n');
50 ' print(name)\n');
49
51
50 this.then(function () {
52 this.then(function () {
51 // Get the widget names that are registered with the widget manager. Assume
53 // Get the widget names that are registered with the widget manager. Assume
52 // a 1 to 1 mapping of model and widgets names (model names just have 'model'
54 // a 1 to 1 mapping of model and widgets names (model names just have 'model'
53 // suffixed).
55 // suffixed).
54 var javascript_names = this.evaluate(function () {
56 var javascript_names = this.evaluate(function () {
55 names = [];
57 names = [];
56 for (var name in IPython.notebook.widget_manager.widget_model_types) {
58 for (var name in IPython.widget_manager.widget_model_types) {
57 names.push(name.replace('Model',''));
59 names.push(name.replace('Model',''));
58 }
60 }
59 return names;
61 return names;
60 });
62 });
61
63
62 // Get the widget names registered in python.
64 // Get the widget names registered in python.
63 var python_names = this.get_output_cell(cell_index).text.split('\n');
65 var python_names = this.get_output_cell(cell_index).text.split('\n');
64
66
65 // Make sure the two lists have the same items.
67 // Make sure the two lists have the same items.
66 for (var i in javascript_names) {
68 for (var i in javascript_names) {
67 var javascript_name = javascript_names[i];
69 var javascript_name = javascript_names[i];
68 var found = false;
70 var found = false;
69 for (var j in python_names) {
71 for (var j in python_names) {
70 var python_name = python_names[j];
72 var python_name = python_names[j];
71 if (python_name==javascript_name) {
73 if (python_name==javascript_name) {
72 found = true;
74 found = true;
73 break;
75 break;
74 }
76 }
75 }
77 }
76 this.test.assert(found, javascript_name + ' exists in python');
78 this.test.assert(found, javascript_name + ' exists in python');
77 }
79 }
78 for (var i in python_names) {
80 for (var i in python_names) {
79 var python_name = python_names[i];
81 var python_name = python_names[i];
80 if (python_name.length > 0) {
82 if (python_name.length > 0) {
81 var found = false;
83 var found = false;
82 for (var j in javascript_names) {
84 for (var j in javascript_names) {
83 var javascript_name = javascript_names[j];
85 var javascript_name = javascript_names[j];
84 if (python_name==javascript_name) {
86 if (python_name==javascript_name) {
85 found = true;
87 found = true;
86 break;
88 break;
87 }
89 }
88 }
90 }
89 this.test.assert(found, python_name + ' exists in javascript');
91 this.test.assert(found, python_name + ' exists in javascript');
90 }
92 }
91 }
93 }
92 });
94 });
93
95
94
96
95 //}); // end of test.begin
97 //}); // end of test.begin
96 });
98 });
97
99
General Comments 0
You need to be logged in to leave comments. Login now