##// END OF EJS Templates
test Image(retina=True)
MinRK -
Show More
1 NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
@@ -1,38 +1,56 b''
1 1 #-----------------------------------------------------------------------------
2 2 # Copyright (C) 2010-2011 The IPython Development Team.
3 3 #
4 4 # Distributed under the terms of the BSD License.
5 5 #
6 6 # The full license is in the file COPYING.txt, distributed with this software.
7 7 #-----------------------------------------------------------------------------
8 8 import os
9 9
10 10 import nose.tools as nt
11 11
12 12 from IPython.core import display
13 13 from IPython.utils import path as ipath
14 14
15 15 def test_image_size():
16 16 """Simple test for display.Image(args, width=x,height=y)"""
17 17 thisurl = 'http://www.google.fr/images/srpr/logo3w.png'
18 18 img = display.Image(url=thisurl, width=200, height=200)
19 19 nt.assert_equal(u'<img src="%s" width="200" height="200"/>' % (thisurl), img._repr_html_())
20 20 img = display.Image(url=thisurl, width=200)
21 21 nt.assert_equal(u'<img src="%s" width="200"/>' % (thisurl), img._repr_html_())
22 22 img = display.Image(url=thisurl)
23 23 nt.assert_equal(u'<img src="%s"/>' % (thisurl), img._repr_html_())
24 24
25 def test_retina_png():
26 here = os.path.dirname(__file__)
27 img = display.Image(os.path.join(here, "2x2.png"), retina=True)
28 nt.assert_equal(img.height, 1)
29 nt.assert_equal(img.width, 1)
30 data, md = img._repr_png_()
31 nt.assert_equal(md['width'], 1)
32 nt.assert_equal(md['height'], 1)
33
34 def test_retina_jpeg():
35 here = os.path.dirname(__file__)
36 img = display.Image(os.path.join(here, "2x2.jpg"), retina=True)
37 nt.assert_equal(img.height, 1)
38 nt.assert_equal(img.width, 1)
39 data, md = img._repr_jpeg_()
40 nt.assert_equal(md['width'], 1)
41 nt.assert_equal(md['height'], 1)
42
25 43 def test_image_filename_defaults():
26 44 '''test format constraint, and validity of jpeg and png'''
27 45 tpath = ipath.get_ipython_package_dir()
28 46 nt.assert_raises(ValueError, display.Image, filename=os.path.join(tpath, 'testing/tests/badformat.gif'),
29 47 embed=True)
30 48 nt.assert_raises(ValueError, display.Image)
31 49 nt.assert_raises(ValueError, display.Image, data='this is not an image', format='badformat', embed=True)
32 50 imgfile = os.path.join(tpath, 'frontend/html/notebook/static/base/images/ipynblogo.png')
33 51 img = display.Image(filename=imgfile)
34 52 nt.assert_equal('png', img.format)
35 53 nt.assert_is_not_none(img._repr_png_())
36 54 img = display.Image(filename=os.path.join(tpath, 'testing/tests/logo.jpg'), embed=False)
37 55 nt.assert_equal('jpeg', img.format)
38 56 nt.assert_is_none(img._repr_jpeg_())
General Comments 0
You need to be logged in to leave comments. Login now