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