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