Show More
@@ -8,13 +8,14 b' var recursive_compare = function(a, b) {' | |||||
8 |
|
8 | |||
9 | if (same) { |
|
9 | if (same) { | |
10 | if (a instanceof Object) { |
|
10 | if (a instanceof Object) { | |
11 |
|
|
11 | var key; | |
|
12 | for (key in a) { | |||
12 | if (a.hasOwnProperty(key) && !recursive_compare(a[key], b[key])) { |
|
13 | if (a.hasOwnProperty(key) && !recursive_compare(a[key], b[key])) { | |
13 | same = false; |
|
14 | same = false; | |
14 | break; |
|
15 | break; | |
15 | } |
|
16 | } | |
16 | } |
|
17 | } | |
17 |
for ( |
|
18 | for (key in b) { | |
18 | if (b.hasOwnProperty(key) && !recursive_compare(a[key], b[key])) { |
|
19 | if (b.hasOwnProperty(key) && !recursive_compare(a[key], b[key])) { | |
19 | same = false; |
|
20 | same = false; | |
20 | break; |
|
21 | break; | |
@@ -26,7 +27,7 b' var recursive_compare = function(a, b) {' | |||||
26 | } |
|
27 | } | |
27 |
|
28 | |||
28 | return same; |
|
29 | return same; | |
29 | } |
|
30 | }; | |
30 |
|
31 | |||
31 |
|
|
32 | // Test the widget framework. | |
32 | casper.notebook_test(function () { |
|
33 | casper.notebook_test(function () { | |
@@ -58,7 +59,6 b' casper.notebook_test(function () {' | |||||
58 | var output = that.evaluate(function(input) { |
|
59 | var output = that.evaluate(function(input) { | |
59 | var model = new IPython.WidgetModel(IPython.notebook.kernel.widget_manager, undefined); |
|
60 | var model = new IPython.WidgetModel(IPython.notebook.kernel.widget_manager, undefined); | |
60 | var results = model._pack_models(input); |
|
61 | var results = model._pack_models(input); | |
61 | delete model; |
|
|||
62 | return results; |
|
62 | return results; | |
63 | }, {input: input}); |
|
63 | }, {input: input}); | |
64 | that.test.assert(recursive_compare(input, output), |
|
64 | that.test.assert(recursive_compare(input, output), | |
@@ -68,7 +68,6 b' casper.notebook_test(function () {' | |||||
68 | var output = that.evaluate(function(input) { |
|
68 | var output = that.evaluate(function(input) { | |
69 | var model = new IPython.WidgetModel(IPython.notebook.kernel.widget_manager, undefined); |
|
69 | var model = new IPython.WidgetModel(IPython.notebook.kernel.widget_manager, undefined); | |
70 | var results = model._unpack_models(input); |
|
70 | var results = model._unpack_models(input); | |
71 | delete model; |
|
|||
72 | return results; |
|
71 | return results; | |
73 | }, {input: input}); |
|
72 | }, {input: input}); | |
74 | that.test.assert(recursive_compare(input, output), |
|
73 | that.test.assert(recursive_compare(input, output), | |
@@ -79,15 +78,53 b' casper.notebook_test(function () {' | |||||
79 | test_unpack(input); |
|
78 | test_unpack(input); | |
80 | }; |
|
79 | }; | |
81 |
|
80 | |||
82 | test_packing({0: 'hi', 1: 'bye'}) |
|
81 | test_packing({0: 'hi', 1: 'bye'}); | |
83 | test_packing(['hi', 'bye']) |
|
82 | test_packing(['hi', 'bye']); | |
84 | test_packing(['hi', 5]) |
|
83 | test_packing(['hi', 5]); | |
85 | test_packing(['hi', '5']) |
|
84 | test_packing(['hi', '5']); | |
86 | test_packing([1.0, 0]) |
|
85 | test_packing([1.0, 0]); | |
87 | test_packing([1.0, false]) |
|
86 | test_packing([1.0, false]); | |
88 | test_packing([1, false]) |
|
87 | test_packing([1, false]); | |
89 | test_packing([1, false, {a: 'hi'}]) |
|
88 | test_packing([1, false, {a: 'hi'}]); | |
90 | test_packing([1, false, ['hi']]) |
|
89 | test_packing([1, false, ['hi']]); | |
|
90 | ||||
|
91 | // Test multi-set, single touch code. First create a custom widget. | |||
|
92 | this.evaluate(function() { | |||
|
93 | var MultiSetView = IPython.DOMWidgetView.extend({ | |||
|
94 | render: function(){ | |||
|
95 | this.model.set('a', 1); | |||
|
96 | this.model.set('b', 2); | |||
|
97 | this.model.set('c', 3); | |||
|
98 | this.touch(); | |||
|
99 | }, | |||
|
100 | }); | |||
|
101 | WidgetManager.register_widget_view('MultiSetView', MultiSetView); | |||
|
102 | }, {}); | |||
|
103 | }); | |||
|
104 | ||||
|
105 | // Try creating the multiset widget, verify that sets the values correctly. | |||
|
106 | var multiset = {}; | |||
|
107 | multiset.index = this.append_cell( | |||
|
108 | 'from IPython.utils.traitlets import Unicode, CInt\n' + | |||
|
109 | 'class MultiSetWidget(widgets.Widget):\n' + | |||
|
110 | ' _view_name = Unicode("MultiSetView", sync=True)\n' + | |||
|
111 | ' a = CInt(0, sync=True)\n' + | |||
|
112 | ' b = CInt(0, sync=True)\n' + | |||
|
113 | ' c = CInt(0, sync=True)\n' + | |||
|
114 | 'multiset = MultiSetWidget()\n' + | |||
|
115 | 'display(multiset)\n' + | |||
|
116 | 'print(multiset.model_id)'); | |||
|
117 | this.execute_cell_then(multiset.index, function(index) { | |||
|
118 | multiset.model_id = this.get_output_cell(index).text.trim(); | |||
|
119 | }); | |||
|
120 | ||||
|
121 | this.wait_for_widget(multiset); | |||
|
122 | ||||
|
123 | index = this.append_cell( | |||
|
124 | 'print("%d%d%d" % (multiset.a, multiset.b, multiset.c))'); | |||
|
125 | this.execute_cell_then(index, function(index) { | |||
|
126 | this.test.assertEquals(this.get_output_cell(index).text.trim(), '123', | |||
|
127 | 'Multiple model.set calls and one view.touch update state in back-end.'); | |||
91 | }); |
|
128 | }); | |
92 |
|
129 | |||
93 | var textbox = {}; |
|
130 | var textbox = {}; |
General Comments 0
You need to be logged in to leave comments.
Login now