##// END OF EJS Templates
Update widget test for new custom serialization changes
Jason Grout -
Show More
@@ -140,22 +140,15 b' casper.notebook_test(function () {'
140
140
141
141
142 this.thenEvaluate(function() {
142 this.thenEvaluate(function() {
143 define('TestWidget', ['widgets/js/widget', 'base/js/utils'], function(widget, utils) {
143 define('TestWidget', ['widgets/js/widget', 'base/js/utils', 'underscore'], function(widget, utils, _) {
144 var TestWidget = widget.DOMWidgetView.extend({
145 render: function () {
146 this.listenTo(this.model, 'msg:custom', this.handle_msg);
147 },
148 handle_msg: function(content, buffers) {
149 this.msg = [content, buffers];
150 }
151 });
152
153 var floatArray = {
144 var floatArray = {
154 deserialize: function (value, model) {
145 deserialize: function (value, model) {
146 if (value===null) {return null;}
155 // DataView -> float64 typed array
147 // DataView -> float64 typed array
156 return new Float64Array(value.buffer);
148 return new Float64Array(value.buffer);
157 },
149 },
158 // serialization automatically handled by message buffers
150 // serialization automatically handled since the
151 // attribute is an ArrayBuffer view
159 };
152 };
160
153
161 var floatList = {
154 var floatList = {
@@ -168,7 +161,24 b' casper.notebook_test(function () {'
168 return value.map(function(x) {return parseFloat(x);})
161 return value.map(function(x) {return parseFloat(x);})
169 }
162 }
170 };
163 };
171 return {TestWidget: TestWidget, floatArray: floatArray, floatList: floatList};
164
165 var TestWidgetModel = widget.WidgetModel.extend({}, {
166 serializers: _.extend({
167 array_list: floatList,
168 array_binary: floatArray
169 }, widget.WidgetModel.serializers)
170 });
171
172 var TestWidgetView = widget.DOMWidgetView.extend({
173 render: function () {
174 this.listenTo(this.model, 'msg:custom', this.handle_msg);
175 },
176 handle_msg: function(content, buffers) {
177 this.msg = [content, buffers];
178 }
179 });
180
181 return {TestWidgetModel: TestWidgetModel, TestWidgetView: TestWidgetView};
172 });
182 });
173 });
183 });
174
184
@@ -179,14 +189,15 b' casper.notebook_test(function () {'
179 'from IPython.display import display',
189 'from IPython.display import display',
180 'from array import array',
190 'from array import array',
181 'def _array_to_memoryview(x):',
191 'def _array_to_memoryview(x):',
182 ' if x is None: return None, {}',
192 ' if x is None: return None',
183 ' try:',
193 ' try:',
184 ' y = memoryview(x)',
194 ' y = memoryview(x)',
185 ' except TypeError:',
195 ' except TypeError:',
186 ' # in python 2, arrays do not support the new buffer protocol',
196 ' # in python 2, arrays do not support the new buffer protocol',
187 ' y = memoryview(buffer(x))',
197 ' y = memoryview(buffer(x))',
188 ' return y, {"serialization": ("floatArray", "TestWidget")}',
198 ' return y',
189 'def _memoryview_to_array(x):',
199 'def _memoryview_to_array(x):',
200 ' if x is None: return None',
190 ' return array("d", x.tobytes())',
201 ' return array("d", x.tobytes())',
191 'arrays_binary = {',
202 'arrays_binary = {',
192 ' "from_json": _memoryview_to_array,',
203 ' "from_json": _memoryview_to_array,',
@@ -194,8 +205,7 b' casper.notebook_test(function () {'
194 '}',
205 '}',
195 '',
206 '',
196 'def _array_to_list(x):',
207 'def _array_to_list(x):',
197 ' if x is None: return None, {}',
208 ' return list(x)',
198 ' return list(x), {"serialization": ("floatList", "TestWidget")}',
199 'def _list_to_array(x):',
209 'def _list_to_array(x):',
200 ' return array("d",x)',
210 ' return array("d",x)',
201 'arrays_list = {',
211 'arrays_list = {',
@@ -204,10 +214,12 b' casper.notebook_test(function () {'
204 '}',
214 '}',
205 '',
215 '',
206 'class TestWidget(widgets.DOMWidget):',
216 'class TestWidget(widgets.DOMWidget):',
217 ' _model_module = Unicode("TestWidget", sync=True)',
218 ' _model_name = Unicode("TestWidgetModel", sync=True)',
207 ' _view_module = Unicode("TestWidget", sync=True)',
219 ' _view_module = Unicode("TestWidget", sync=True)',
208 ' _view_name = Unicode("TestWidget", sync=True)',
220 ' _view_name = Unicode("TestWidgetView", sync=True)',
209 ' array_binary = Instance(array, sync=True, **arrays_binary)',
221 ' array_binary = Instance(array, allow_none=True, sync=True, **arrays_binary)',
210 ' array_list = Instance(array, sync=True, **arrays_list)',
222 ' array_list = Instance(array, args=("d", [3.0]), allow_none=False, sync=True, **arrays_list)',
211 ' msg = {}',
223 ' msg = {}',
212 ' def __init__(self, **kwargs):',
224 ' def __init__(self, **kwargs):',
213 ' super(widgets.DOMWidget, self).__init__(**kwargs)',
225 ' super(widgets.DOMWidget, self).__init__(**kwargs)',
General Comments 0
You need to be logged in to leave comments. Login now