##// END OF EJS Templates
Fix "super" objects pretty printing in PyPy...
Fix "super" objects pretty printing in PyPy In PyPy there's no __self__ attribute for super(.) objects. As objects always have a __repr__, the found alternative was to use its curried argument. Previously, only the class name was verified as part of the result, now the tests include a regex.

File last commit:

r22379:6aabd662
r22751:b6a880d3
Show More
test_display.py
191 lines | 6.8 KiB | text/x-python | PythonLexer
Min RK
JSON formatter expects JSONable dict/list...
r19557 # Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
import json
Jerry Fowler
Issue 2053:...
r8077 import os
Min RK
JSON formatter expects JSONable dict/list...
r19557 import warnings
Jerry Fowler
Issue 2053:...
r8077
import nose.tools as nt
from IPython.core import display
MinRK
test display.set_matplotlib_formats...
r15395 from IPython.core.getipython import get_ipython
Thomas Kluyver
Don't try to open temporary file twice in video embed test...
r22130 from IPython.utils.tempdir import NamedFileInTemporaryDirectory
Min RK
update dependency imports...
r21253 from IPython import paths as ipath
Jerry Fowler
Issue 2053:...
r8077
MinRK
test display.set_matplotlib_formats...
r15395 import IPython.testing.decorators as dec
Jerry Fowler
Issue 2053:...
r8077 def test_image_size():
"""Simple test for display.Image(args, width=x,height=y)"""
thisurl = 'http://www.google.fr/images/srpr/logo3w.png'
img = display.Image(url=thisurl, width=200, height=200)
nt.assert_equal(u'<img src="%s" width="200" height="200"/>' % (thisurl), img._repr_html_())
img = display.Image(url=thisurl, width=200)
nt.assert_equal(u'<img src="%s" width="200"/>' % (thisurl), img._repr_html_())
img = display.Image(url=thisurl)
nt.assert_equal(u'<img src="%s"/>' % (thisurl), img._repr_html_())
Min RK
add unconfined, raw metadata to display.Image...
r20986 img = display.Image(url=thisurl, unconfined=True)
nt.assert_equal(u'<img src="%s" class="unconfined"/>' % (thisurl), img._repr_html_())
Jerry Fowler
Issue 2053:...
r8077
MinRK
test Image(retina=True)
r10804 def test_retina_png():
here = os.path.dirname(__file__)
img = display.Image(os.path.join(here, "2x2.png"), retina=True)
nt.assert_equal(img.height, 1)
nt.assert_equal(img.width, 1)
data, md = img._repr_png_()
nt.assert_equal(md['width'], 1)
nt.assert_equal(md['height'], 1)
def test_retina_jpeg():
here = os.path.dirname(__file__)
img = display.Image(os.path.join(here, "2x2.jpg"), retina=True)
nt.assert_equal(img.height, 1)
nt.assert_equal(img.width, 1)
data, md = img._repr_jpeg_()
nt.assert_equal(md['width'], 1)
nt.assert_equal(md['height'], 1)
Matthias Bussonnier
Fix Image when passing only data, and add tests....
r22013 def test_base64image():
display.Image("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAWJLR0QAiAUdSAAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB94BCRQnOqNu0b4AAAAKSURBVAjXY2AAAAACAAHiIbwzAAAAAElFTkSuQmCC")
Jerry Fowler
Issue 2053:...
r8077 def test_image_filename_defaults():
'''test format constraint, and validity of jpeg and png'''
tpath = ipath.get_ipython_package_dir()
nt.assert_raises(ValueError, display.Image, filename=os.path.join(tpath, 'testing/tests/badformat.gif'),
embed=True)
nt.assert_raises(ValueError, display.Image)
nt.assert_raises(ValueError, display.Image, data='this is not an image', format='badformat', embed=True)
Julian Taylor
check the static path for build and install locations...
r14749 # check boths paths to allow packages to test at build and install time
Min RK
update some test skips for removed packages
r21251 imgfile = os.path.join(tpath, 'core/tests/2x2.png')
Jerry Fowler
Issue 2053:...
r8077 img = display.Image(filename=imgfile)
nt.assert_equal('png', img.format)
nt.assert_is_not_none(img._repr_png_())
img = display.Image(filename=os.path.join(tpath, 'testing/tests/logo.jpg'), embed=False)
nt.assert_equal('jpeg', img.format)
nt.assert_is_none(img._repr_jpeg_())
MinRK
test display.set_matplotlib_formats...
r15395
def _get_inline_config():
Min RK
ipython_kernel is now ipykernel
r21337 from ipykernel.pylab.config import InlineBackend
MinRK
test display.set_matplotlib_formats...
r15395 return InlineBackend.instance()
@dec.skip_without('matplotlib')
def test_set_matplotlib_close():
cfg = _get_inline_config()
cfg.close_figures = False
display.set_matplotlib_close()
assert cfg.close_figures
display.set_matplotlib_close(False)
assert not cfg.close_figures
_fmt_mime_map = {
'png': 'image/png',
'jpeg': 'image/jpeg',
'pdf': 'application/pdf',
'retina': 'image/png',
'svg': 'image/svg+xml',
}
@dec.skip_without('matplotlib')
def test_set_matplotlib_formats():
from matplotlib.figure import Figure
formatters = get_ipython().display_formatter.formatters
for formats in [
('png',),
('pdf', 'svg'),
('jpeg', 'retina', 'png'),
(),
]:
active_mimes = {_fmt_mime_map[fmt] for fmt in formats}
display.set_matplotlib_formats(*formats)
for mime, f in formatters.items():
if mime in active_mimes:
nt.assert_in(Figure, f)
else:
nt.assert_not_in(Figure, f)
@dec.skip_without('matplotlib')
def test_set_matplotlib_formats_kwargs():
from matplotlib.figure import Figure
ip = get_ipython()
cfg = _get_inline_config()
cfg.print_figure_kwargs.update(dict(foo='bar'))
kwargs = dict(quality=10)
display.set_matplotlib_formats('png', **kwargs)
formatter = ip.display_formatter.formatters['image/png']
f = formatter.lookup_by_type(Figure)
cell = f.__closure__[0].cell_contents
expected = kwargs
expected.update(cfg.print_figure_kwargs)
nt.assert_equal(cell, expected)
Jessica B. Hamrick
Add test for DisplayObject.__repr__
r16397 def test_displayobject_repr():
h = display.HTML('<br />')
nt.assert_equal(repr(h), '<IPython.core.display.HTML object>')
h._show_mem_addr = True
Jessica B. Hamrick
Test against object.__repr__, rather than hardcoded repr
r16398 nt.assert_equal(repr(h), object.__repr__(h))
Jessica B. Hamrick
Add test for DisplayObject.__repr__
r16397 h._show_mem_addr = False
nt.assert_equal(repr(h), '<IPython.core.display.HTML object>')
j = display.Javascript('')
nt.assert_equal(repr(j), '<IPython.core.display.Javascript object>')
j._show_mem_addr = True
Jessica B. Hamrick
Test against object.__repr__, rather than hardcoded repr
r16398 nt.assert_equal(repr(j), object.__repr__(j))
Jessica B. Hamrick
Add test for DisplayObject.__repr__
r16397 j._show_mem_addr = False
nt.assert_equal(repr(j), '<IPython.core.display.Javascript object>')
Min RK
JSON formatter expects JSONable dict/list...
r19557
def test_json():
d = {'a': 5}
lis = [d]
j = display.JSON(d)
nt.assert_equal(j._repr_json_(), d)
Min RK
ensure warnings are raised in tests...
r19559
Min RK
JSON formatter expects JSONable dict/list...
r19557 with warnings.catch_warnings(record=True) as w:
Min RK
ensure warnings are raised in tests...
r19559 warnings.simplefilter("always")
Min RK
JSON formatter expects JSONable dict/list...
r19557 j = display.JSON(json.dumps(d))
Bussonnier Matthias
put test in content manager
r19558 nt.assert_equal(len(w), 1)
Min RK
ensure warnings are raised in tests...
r19559 nt.assert_equal(j._repr_json_(), d)
Min RK
JSON formatter expects JSONable dict/list...
r19557 j = display.JSON(lis)
nt.assert_equal(j._repr_json_(), lis)
Min RK
ensure warnings are raised in tests...
r19559
Min RK
JSON formatter expects JSONable dict/list...
r19557 with warnings.catch_warnings(record=True) as w:
Min RK
ensure warnings are raised in tests...
r19559 warnings.simplefilter("always")
Min RK
JSON formatter expects JSONable dict/list...
r19557 j = display.JSON(json.dumps(lis))
Bussonnier Matthias
put test in content manager
r19558 nt.assert_equal(len(w), 1)
Min RK
ensure warnings are raised in tests...
r19559 nt.assert_equal(j._repr_json_(), lis)
Min RK
JSON formatter expects JSONable dict/list...
r19557
sukisuki
added basic test...
r21266 def test_video_embedding():
"""use a tempfile, with dummy-data, to ensure that video embedding doesn't crash"""
Min RK
require explicit embed=True before embedding b64-encoded video
r22116 v = display.Video("http://ignored")
assert not v.embed
html = v._repr_html_()
nt.assert_not_in('src="data:', html)
nt.assert_in('src="http://ignored"', html)
with nt.assert_raises(ValueError):
v = display.Video(b'abc')
Thomas Kluyver
Don't try to open temporary file twice in video embed test...
r22130 with NamedFileInTemporaryDirectory('test.mp4') as f:
f.write(b'abc')
f.close()
sukisuki
added basic test...
r21266
Min RK
require explicit embed=True before embedding b64-encoded video
r22116 v = display.Video(f.name)
assert not v.embed
html = v._repr_html_()
nt.assert_not_in('src="data:', html)
sukisuki
added basic test...
r21266 v = display.Video(f.name, embed=True)
html = v._repr_html_()
nt.assert_in('src="data:video/mp4;base64,YWJj"',html)
Min RK
handle raw video data as input to Video
r22115
v = display.Video(f.name, embed=True, mimetype='video/other')
html = v._repr_html_()
nt.assert_in('src="data:video/other;base64,YWJj"',html)
v = display.Video(b'abc', embed=True, mimetype='video/mp4')
html = v._repr_html_()
nt.assert_in('src="data:video/mp4;base64,YWJj"',html)
v = display.Video(u'YWJj', embed=True, mimetype='video/xyz')
html = v._repr_html_()
nt.assert_in('src="data:video/xyz;base64,YWJj"',html)
Min RK
require explicit embed=True before embedding b64-encoded video
r22116