Show More
@@ -0,0 +1,97 | |||||
|
1 | // | |||
|
2 | // Test the widget framework. | |||
|
3 | // | |||
|
4 | casper.notebook_test(function () { | |||
|
5 | //this.test.begin("widget tests (notebook)", 2, function(test) { | |||
|
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 | ||||
|
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 () { | |||
|
31 | ||||
|
32 | // Check if the WidgetManager class is defined. | |||
|
33 | this.test.assert(this.evaluate(function() { | |||
|
34 | return IPython.WidgetManager != undefined; | |||
|
35 | }), 'WidgetManager class is defined'); | |||
|
36 | ||||
|
37 | // Check if the widget manager has been instanciated. | |||
|
38 | this.test.assert(this.evaluate(function() { | |||
|
39 | return IPython.notebook.widget_manager != undefined; | |||
|
40 | }), 'Notebook widget manager instanciated'); | |||
|
41 | }); | |||
|
42 | ||||
|
43 | ||||
|
44 | // Check widget mapping //////////////////////////////////////////////////// | |||
|
45 | var cell_index = run_python_code('names = [name for name in dir(widgets)' + | |||
|
46 | ' if name.endswith("Widget") and name!= "Widget"]\n' + | |||
|
47 | 'for name in names:\n' + | |||
|
48 | ' print(name)\n'); | |||
|
49 | ||||
|
50 | this.then(function () { | |||
|
51 | // 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' | |||
|
53 | // suffixed). | |||
|
54 | var javascript_names = this.evaluate(function () { | |||
|
55 | names = []; | |||
|
56 | for (var name in IPython.notebook.widget_manager.widget_model_types) { | |||
|
57 | names.push(name.replace('Model','')); | |||
|
58 | } | |||
|
59 | return names; | |||
|
60 | }); | |||
|
61 | ||||
|
62 | // Get the widget names registered in python. | |||
|
63 | var python_names = this.get_output_cell(cell_index).text.split('\n'); | |||
|
64 | ||||
|
65 | // Make sure the two lists have the same items. | |||
|
66 | for (var i in javascript_names) { | |||
|
67 | var javascript_name = javascript_names[i]; | |||
|
68 | var found = false; | |||
|
69 | for (var j in python_names) { | |||
|
70 | var python_name = python_names[j]; | |||
|
71 | if (python_name==javascript_name) { | |||
|
72 | found = true; | |||
|
73 | break; | |||
|
74 | } | |||
|
75 | } | |||
|
76 | this.test.assert(found, javascript_name + ' exists in python'); | |||
|
77 | } | |||
|
78 | for (var i in python_names) { | |||
|
79 | var python_name = python_names[i]; | |||
|
80 | if (python_name.length > 0) { | |||
|
81 | var found = false; | |||
|
82 | for (var j in javascript_names) { | |||
|
83 | var javascript_name = javascript_names[j]; | |||
|
84 | if (python_name==javascript_name) { | |||
|
85 | found = true; | |||
|
86 | break; | |||
|
87 | } | |||
|
88 | } | |||
|
89 | this.test.assert(found, python_name + ' exists in javascript'); | |||
|
90 | } | |||
|
91 | } | |||
|
92 | }); | |||
|
93 | ||||
|
94 | ||||
|
95 | //}); // end of test.begin | |||
|
96 | }); | |||
|
97 |
General Comments 0
You need to be logged in to leave comments.
Login now