##// END OF EJS Templates
test display_id machinery
Min RK -
Show More
@@ -5,6 +5,8 b' import json'
5 import os
5 import os
6 import warnings
6 import warnings
7
7
8 from unittest import mock
9
8 import nose.tools as nt
10 import nose.tools as nt
9
11
10 from IPython.core import display
12 from IPython.core import display
@@ -196,3 +198,115 b' def test_video_embedding():'
196 v = display.Video(u'YWJj', embed=True, mimetype='video/xyz')
198 v = display.Video(u'YWJj', embed=True, mimetype='video/xyz')
197 html = v._repr_html_()
199 html = v._repr_html_()
198 nt.assert_in('src="data:video/xyz;base64,YWJj"',html)
200 nt.assert_in('src="data:video/xyz;base64,YWJj"',html)
201
202
203 def test_display_id():
204 ip = get_ipython()
205 with mock.patch.object(ip.display_pub, 'publish') as pub:
206 handle = display.display('x')
207 nt.assert_is(handle, None)
208 handle = display.display('y', display_id='secret')
209 nt.assert_is_instance(handle, display.DisplayHandle)
210 handle2 = display.display('z', display_id=True)
211 nt.assert_is_instance(handle2, display.DisplayHandle)
212 nt.assert_not_equal(handle.display_id, handle2.display_id)
213
214 nt.assert_equal(pub.call_count, 3)
215 args, kwargs = pub.call_args_list[0]
216 nt.assert_equal(args, ())
217 nt.assert_equal(kwargs, {
218 'data': {
219 'text/plain': repr('x')
220 },
221 'metadata': {},
222 })
223 args, kwargs = pub.call_args_list[1]
224 nt.assert_equal(args, ())
225 nt.assert_equal(kwargs, {
226 'data': {
227 'text/plain': repr('y')
228 },
229 'metadata': {},
230 'transient': {
231 'display_id': handle.display_id,
232 },
233 })
234 args, kwargs = pub.call_args_list[2]
235 nt.assert_equal(args, ())
236 nt.assert_equal(kwargs, {
237 'data': {
238 'text/plain': repr('z')
239 },
240 'metadata': {},
241 'transient': {
242 'display_id': handle2.display_id,
243 },
244 })
245
246
247 def test_update_display():
248 ip = get_ipython()
249 with mock.patch.object(ip.display_pub, 'publish') as pub:
250 with nt.assert_raises(TypeError):
251 display.update_display('x')
252 display.update_display('x', display_id='1')
253 display.update_display('y', display_id='2')
254 args, kwargs = pub.call_args_list[0]
255 nt.assert_equal(args, ())
256 nt.assert_equal(kwargs, {
257 'data': {
258 'text/plain': repr('x')
259 },
260 'metadata': {},
261 'transient': {
262 'display_id': '1',
263 },
264 'update': True,
265 })
266 args, kwargs = pub.call_args_list[1]
267 nt.assert_equal(args, ())
268 nt.assert_equal(kwargs, {
269 'data': {
270 'text/plain': repr('y')
271 },
272 'metadata': {},
273 'transient': {
274 'display_id': '2',
275 },
276 'update': True,
277 })
278
279
280 def test_display_handle():
281 ip = get_ipython()
282 handle = display.DisplayHandle()
283 nt.assert_is_instance(handle.display_id, str)
284 handle = display.DisplayHandle('my-id')
285 nt.assert_equal(handle.display_id, 'my-id')
286 with mock.patch.object(ip.display_pub, 'publish') as pub:
287 handle.display('x')
288 handle.update('y')
289
290 args, kwargs = pub.call_args_list[0]
291 nt.assert_equal(args, ())
292 nt.assert_equal(kwargs, {
293 'data': {
294 'text/plain': repr('x')
295 },
296 'metadata': {},
297 'transient': {
298 'display_id': handle.display_id,
299 }
300 })
301 args, kwargs = pub.call_args_list[1]
302 nt.assert_equal(args, ())
303 nt.assert_equal(kwargs, {
304 'data': {
305 'text/plain': repr('y')
306 },
307 'metadata': {},
308 'transient': {
309 'display_id': handle.display_id,
310 },
311 'update': True,
312 })
General Comments 0
You need to be logged in to leave comments. Login now