Show More
@@ -1,56 +1,57 | |||
|
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 | 25 | def test_retina_png(): |
|
26 | 26 | here = os.path.dirname(__file__) |
|
27 | 27 | img = display.Image(os.path.join(here, "2x2.png"), retina=True) |
|
28 | 28 | nt.assert_equal(img.height, 1) |
|
29 | 29 | nt.assert_equal(img.width, 1) |
|
30 | 30 | data, md = img._repr_png_() |
|
31 | 31 | nt.assert_equal(md['width'], 1) |
|
32 | 32 | nt.assert_equal(md['height'], 1) |
|
33 | 33 | |
|
34 | 34 | def test_retina_jpeg(): |
|
35 | 35 | here = os.path.dirname(__file__) |
|
36 | 36 | img = display.Image(os.path.join(here, "2x2.jpg"), retina=True) |
|
37 | 37 | nt.assert_equal(img.height, 1) |
|
38 | 38 | nt.assert_equal(img.width, 1) |
|
39 | 39 | data, md = img._repr_jpeg_() |
|
40 | 40 | nt.assert_equal(md['width'], 1) |
|
41 | 41 | nt.assert_equal(md['height'], 1) |
|
42 | 42 | |
|
43 | 43 | def test_image_filename_defaults(): |
|
44 | 44 | '''test format constraint, and validity of jpeg and png''' |
|
45 | 45 | tpath = ipath.get_ipython_package_dir() |
|
46 | 46 | nt.assert_raises(ValueError, display.Image, filename=os.path.join(tpath, 'testing/tests/badformat.gif'), |
|
47 | 47 | embed=True) |
|
48 | 48 | nt.assert_raises(ValueError, display.Image) |
|
49 | 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 | 52 | img = display.Image(filename=imgfile) |
|
52 | 53 | nt.assert_equal('png', img.format) |
|
53 | 54 | nt.assert_is_not_none(img._repr_png_()) |
|
54 | 55 | img = display.Image(filename=os.path.join(tpath, 'testing/tests/logo.jpg'), embed=False) |
|
55 | 56 | nt.assert_equal('jpeg', img.format) |
|
56 | 57 | nt.assert_is_none(img._repr_jpeg_()) |
General Comments 0
You need to be logged in to leave comments.
Login now