##// END OF EJS Templates
explict python version check
explict python version check

File last commit:

r27106:03a05afa
r28176:ce77c86d
Show More
test_display.py
513 lines | 15.6 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
Min RK
test display_id machinery
r23013 from unittest import mock
Samuel Gaist
[core][tests][display] Remove nose
r26891 import pytest
Jerry Fowler
Issue 2053:...
r8077
Matthias Bussonnier
Do not import from IPython.core.display and warn users.
r25632 from IPython import display
MinRK
test display.set_matplotlib_formats...
r15395 from IPython.core.getipython import get_ipython
Henry Fredrick Schreiner
Changing tests to be fully nose compatible
r23962 from IPython.utils.io import capture_output
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
Matthias Bussonnier
Cleanup unused imports.
r25335 from IPython.testing.tools import AssertNotPrints
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)
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert '<img src="%s" width="200" height="200"/>' % (thisurl) == img._repr_html_()
M Pacer
Add metadata to DisplayObject (#10614)...
r23746 img = display.Image(url=thisurl, metadata={'width':200, 'height':200})
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert '<img src="%s" width="200" height="200"/>' % (thisurl) == img._repr_html_()
Jerry Fowler
Issue 2053:...
r8077 img = display.Image(url=thisurl, width=200)
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert '<img src="%s" width="200"/>' % (thisurl) == img._repr_html_()
Jerry Fowler
Issue 2053:...
r8077 img = display.Image(url=thisurl)
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert '<img src="%s"/>' % (thisurl) == img._repr_html_()
Min RK
add unconfined, raw metadata to display.Image...
r20986 img = display.Image(url=thisurl, unconfined=True)
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert '<img src="%s" class="unconfined"/>' % (thisurl) == img._repr_html_()
Jerry Fowler
Issue 2053:...
r8077
Matthias Bussonnier
add minimal test
r23406
Min RK
implement GIF support without registering a new formatter...
r23849 def test_image_mimes():
fmt = get_ipython().display_formatter.format
for format in display.Image._ACCEPTABLE_EMBEDDINGS:
mime = display.Image._MIMETYPES[format]
img = display.Image(b'garbage', format=format)
data, metadata = fmt(img)
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert sorted(data) == sorted([mime, "text/plain"])
Min RK
implement GIF support without registering a new formatter...
r23849
Matthias Bussonnier
add minimal test
r23406 def test_geojson():
gj = display.GeoJSON(data={
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-81.327, 296.038]
},
"properties": {
"name": "Inca City"
}
},
url_template="http://s3-eu-west-1.amazonaws.com/whereonmars.cartodb.net/{basemap_id}/{z}/{x}/{y}.png",
layer_options={
"basemap_id": "celestia_mars-shaded-16k_global",
"attribution": "Celestia/praesepe",
"minZoom": 0,
"maxZoom": 18,
Samuel Gaist
[core][tests][display] Remove nose
r26891 },
)
assert "<IPython.core.display.GeoJSON object>" == str(gj)
Matthias Bussonnier
add minimal test
r23406
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)
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert img.height == 1
assert img.width == 1
MinRK
test Image(retina=True)
r10804 data, md = img._repr_png_()
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert md["width"] == 1
assert md["height"] == 1
MinRK
test Image(retina=True)
r10804
Ian Castleden
added documentation and test
r25616 def test_embed_svg_url():
Ian Castleden
added mocked response
r25617 import gzip
from io import BytesIO
svg_data = b'<svg><circle x="0" y="0" r="1"/></svg>'
url = 'http://test.com/circle.svg'
Pete Blois
Add formal support for alt text to IPython.display.Image....
r26382
Ian Castleden
added mocked response
r25617 gzip_svg = BytesIO()
with gzip.open(gzip_svg, 'wb') as fp:
fp.write(svg_data)
gzip_svg = gzip_svg.getvalue()
Pete Blois
Add formal support for alt text to IPython.display.Image....
r26382
Ian Castleden
added mocked response
r25617 def mocked_urlopen(*args, **kwargs):
class MockResponse:
def __init__(self, svg):
self._svg_data = svg
self.headers = {'content-type': 'image/svg+xml'}
def read(self):
return self._svg_data
if args[0] == url:
return MockResponse(svg_data)
Pete Blois
Fix lint errors
r26410 elif args[0] == url + "z":
ret = MockResponse(gzip_svg)
ret.headers["content-encoding"] = "gzip"
Ian Castleden
added mocked response
r25617 return ret
return MockResponse(None)
with mock.patch('urllib.request.urlopen', side_effect=mocked_urlopen):
svg = display.SVG(url=url)
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert svg._repr_svg_().startswith("<svg") is True
svg = display.SVG(url=url + "z")
assert svg._repr_svg_().startswith("<svg") is True
Pete Blois
Add formal support for alt text to IPython.display.Image....
r26382
MinRK
test Image(retina=True)
r10804 def test_retina_jpeg():
here = os.path.dirname(__file__)
img = display.Image(os.path.join(here, "2x2.jpg"), retina=True)
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert img.height == 1
assert img.width == 1
MinRK
test Image(retina=True)
r10804 data, md = img._repr_jpeg_()
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert md["width"] == 1
assert md["height"] == 1
MinRK
test Image(retina=True)
r10804
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()
Samuel Gaist
[core][tests][display] Remove nose
r26891 pytest.raises(
ValueError,
display.Image,
filename=os.path.join(tpath, "testing/tests/badformat.zip"),
embed=True,
)
pytest.raises(ValueError, display.Image)
pytest.raises(
ValueError,
display.Image,
data="this is not an image",
format="badformat",
embed=True,
)
# 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)
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert "png" == img.format
assert img._repr_png_() is not None
img = display.Image(
filename=os.path.join(tpath, "testing/tests/logo.jpg"), embed=False
)
assert "jpeg" == img.format
assert img._repr_jpeg_() is None
MinRK
test display.set_matplotlib_formats...
r15395
def _get_inline_config():
martinRenou
Use matplotlib-inline instead of ipykernel.pylab
r26464 from matplotlib_inline.config import InlineBackend
MinRK
test display.set_matplotlib_formats...
r15395 return InlineBackend.instance()
Adam Eury
feat(JSON): Add expanded metadata to JSON display class
r22947
Matthias Bussonnier
skip test if ipykernel not there....
r26071
@dec.skip_without("matplotlib")
MinRK
test display.set_matplotlib_formats...
r15395 def test_set_matplotlib_close():
cfg = _get_inline_config()
cfg.close_figures = False
Nikita Kniazev
Suppress bunch of self-deprecation warnings...
r27009 with pytest.deprecated_call():
display.set_matplotlib_close()
MinRK
test display.set_matplotlib_formats...
r15395 assert cfg.close_figures
Nikita Kniazev
Suppress bunch of self-deprecation warnings...
r27009 with pytest.deprecated_call():
display.set_matplotlib_close(False)
MinRK
test display.set_matplotlib_formats...
r15395 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}
Nikita Kniazev
Suppress bunch of self-deprecation warnings...
r27009 with pytest.deprecated_call():
display.set_matplotlib_formats(*formats)
MinRK
test display.set_matplotlib_formats...
r15395 for mime, f in formatters.items():
if mime in active_mimes:
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert Figure in f
MinRK
test display.set_matplotlib_formats...
r15395 else:
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert Figure not in f
MinRK
test display.set_matplotlib_formats...
r15395
Matthias Bussonnier
skip test if ipykernel not there....
r26071
@dec.skip_without("matplotlib")
MinRK
test display.set_matplotlib_formats...
r15395 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'))
Matthias Bussonnier
Misc CI warning and error.
r26390 kwargs = dict(dpi=150)
Nikita Kniazev
Suppress bunch of self-deprecation warnings...
r27009 with pytest.deprecated_call():
display.set_matplotlib_formats("png", **kwargs)
formatter = ip.display_formatter.formatters["image/png"]
MinRK
test display.set_matplotlib_formats...
r15395 f = formatter.lookup_by_type(Figure)
Min RK
print_figure return base64 str instead of bytes...
r26812 formatter_kwargs = f.keywords
MinRK
test display.set_matplotlib_formats...
r15395 expected = kwargs
Min RK
print_figure return base64 str instead of bytes...
r26812 expected["base64"] = True
expected["fmt"] = "png"
MinRK
test display.set_matplotlib_formats...
r15395 expected.update(cfg.print_figure_kwargs)
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert formatter_kwargs == expected
MinRK
test display.set_matplotlib_formats...
r15395
Matthias Bussonnier
Add test that display is available without imports.
r23710 def test_display_available():
"""
Test that display is available without import
We don't really care if it's in builtin or anything else, but it should
always be available.
"""
ip = get_ipython()
with AssertNotPrints('NameError'):
ip.run_cell('display')
try:
ip.run_cell('del display')
except NameError:
pass # it's ok, it might be in builtins
# even if deleted it should be back
with AssertNotPrints('NameError'):
ip.run_cell('display')
ryan thielke
Fix signature for IPython.core.display:Pretty #10595
r23729 def test_textdisplayobj_pretty_repr():
Samuel Gaist
[core][tests][display] Remove nose
r26891 p = display.Pretty("This is a simple test")
assert repr(p) == "<IPython.core.display.Pretty object>"
assert p.data == "This is a simple test"
p._show_mem_addr = True
assert repr(p) == object.__repr__(p)
ryan thielke
Fix signature for IPython.core.display:Pretty #10595
r23729
Matthias Bussonnier
Add test that display is available without imports.
r23710
Jessica B. Hamrick
Add test for DisplayObject.__repr__
r16397 def test_displayobject_repr():
Samuel Gaist
[core][tests][display] Remove nose
r26891 h = display.HTML("<br />")
assert repr(h) == "<IPython.core.display.HTML object>"
Jessica B. Hamrick
Add test for DisplayObject.__repr__
r16397 h._show_mem_addr = True
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert repr(h) == object.__repr__(h)
Jessica B. Hamrick
Add test for DisplayObject.__repr__
r16397 h._show_mem_addr = False
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert repr(h) == "<IPython.core.display.HTML object>"
Jessica B. Hamrick
Add test for DisplayObject.__repr__
r16397
Samuel Gaist
[core][tests][display] Remove nose
r26891 j = display.Javascript("")
assert repr(j) == "<IPython.core.display.Javascript object>"
Jessica B. Hamrick
Add test for DisplayObject.__repr__
r16397 j._show_mem_addr = True
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert repr(j) == object.__repr__(j)
Jessica B. Hamrick
Add test for DisplayObject.__repr__
r16397 j._show_mem_addr = False
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert repr(j) == "<IPython.core.display.Javascript object>"
Min RK
JSON formatter expects JSONable dict/list...
r19557
Michael Penkov
Fix #9343: warn when using HTML instead of IFrame
r24619 @mock.patch('warnings.warn')
def test_encourage_iframe_over_html(m_warn):
Michael Penkov
handle case-insensitivity
r24654 display.HTML()
m_warn.assert_not_called()
Michael Penkov
Fix #9343: warn when using HTML instead of IFrame
r24619 display.HTML('<br />')
m_warn.assert_not_called()
Michael Penkov
don't warn if the iframe isn't the only thing in the data
r24653 display.HTML('<html><p>Lots of content here</p><iframe src="http://a.com"></iframe>')
m_warn.assert_not_called()
Michael Penkov
Fix #9343: warn when using HTML instead of IFrame
r24619 display.HTML('<iframe src="http://a.com"></iframe>')
m_warn.assert_called_with('Consider using IPython.display.IFrame instead')
Michael Penkov
handle case-insensitivity
r24654 m_warn.reset_mock()
display.HTML('<IFRAME SRC="http://a.com"></IFRAME>')
m_warn.assert_called_with('Consider using IPython.display.IFrame instead')
Marius van Niekerk
add some light tests
r23855 def test_progress():
p = display.ProgressBar(10)
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert "0/10" in repr(p)
p.html_width = "100%"
Marius van Niekerk
fix tests
r23861 p.progress = 5
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert (
p._repr_html_() == "<progress style='width:100%' max='10' value='5'></progress>"
)
Marius van Niekerk
add some light tests
r23855
Henry Fredrick Schreiner
Changing tests to be fully nose compatible
r23962 def test_progress_iter():
with capture_output(display=False) as captured:
for i in display.ProgressBar(5):
out = captured.stdout
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert "{0}/5".format(i) in out
Henry Fredrick Schreiner
Changing tests to be fully nose compatible
r23962 out = captured.stdout
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert "5/5" in out
Henry Fredrick Schreiner
Adding iteration to ProgressBar to make it a more useful utility
r23943
Min RK
JSON formatter expects JSONable dict/list...
r19557 def test_json():
d = {'a': 5}
lis = [d]
dhirschf
Update test_json to account for new metadata
r24413 metadata = [
{'expanded': False, 'root': 'root'},
{'expanded': True, 'root': 'root'},
{'expanded': False, 'root': 'custom'},
{'expanded': True, 'root': 'custom'},
]
json_objs = [
display.JSON(d),
display.JSON(d, expanded=True),
display.JSON(d, root='custom'),
display.JSON(d, expanded=True, root='custom'),
]
for j, md in zip(json_objs, metadata):
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert j._repr_json_() == (d, md)
Adam Eury
feat(JSON): Add expanded metadata to JSON display class
r22947
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))
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert len(w) == 1
assert j._repr_json_() == (d, metadata[0])
dhirschf
Update test_json to account for new metadata
r24413
json_objs = [
display.JSON(lis),
display.JSON(lis, expanded=True),
display.JSON(lis, root='custom'),
display.JSON(lis, expanded=True, root='custom'),
]
for j, md in zip(json_objs, metadata):
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert j._repr_json_() == (lis, md)
Adam Eury
feat(JSON): Add expanded metadata to JSON display class
r22947
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))
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert len(w) == 1
assert j._repr_json_() == (lis, metadata[0])
Adam Eury
feat(JSON): Add expanded metadata to JSON display class
r22947
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_()
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert 'src="data:' not in html
assert 'src="http://ignored"' in html
Min RK
require explicit embed=True before embedding b64-encoded video
r22116
Samuel Gaist
[core][tests][display] Remove nose
r26891 with pytest.raises(ValueError):
Min RK
require explicit embed=True before embedding b64-encoded video
r22116 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_()
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert 'src="data:' not in html
Adam Eury
feat(JSON): Add expanded metadata to JSON display class
r22947
sukisuki
added basic test...
r21266 v = display.Video(f.name, embed=True)
html = v._repr_html_()
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert 'src="data:video/mp4;base64,YWJj"' in html
Adam Eury
feat(JSON): Add expanded metadata to JSON display class
r22947
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_()
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert 'src="data:video/other;base64,YWJj"' in html
Adam Eury
feat(JSON): Add expanded metadata to JSON display class
r22947
Min RK
handle raw video data as input to Video
r22115 v = display.Video(b'abc', embed=True, mimetype='video/mp4')
html = v._repr_html_()
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert 'src="data:video/mp4;base64,YWJj"' in html
Min RK
handle raw video data as input to Video
r22115
v = display.Video(u'YWJj', embed=True, mimetype='video/xyz')
html = v._repr_html_()
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert 'src="data:video/xyz;base64,YWJj"' in html
Min RK
test display_id machinery
r23013
Thomas Kluyver
Display objects should emit metadata when it exists
r24301 def test_html_metadata():
s = "<h1>Test</h1>"
h = display.HTML(s, metadata={"isolated": True})
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert h._repr_html_() == (s, {"isolated": True})
Min RK
test display_id machinery
r23013
def test_display_id():
ip = get_ipython()
with mock.patch.object(ip.display_pub, 'publish') as pub:
handle = display.display('x')
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert handle is None
Min RK
test display_id machinery
r23013 handle = display.display('y', display_id='secret')
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert isinstance(handle, display.DisplayHandle)
Min RK
test display_id machinery
r23013 handle2 = display.display('z', display_id=True)
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert isinstance(handle2, display.DisplayHandle)
assert handle.display_id != handle2.display_id
Min RK
test display_id machinery
r23013
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert pub.call_count == 3
Min RK
test display_id machinery
r23013 args, kwargs = pub.call_args_list[0]
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert args == ()
assert kwargs == {
Min RK
test display_id machinery
r23013 'data': {
'text/plain': repr('x')
},
'metadata': {},
Samuel Gaist
[core][tests][display] Remove nose
r26891 }
Min RK
test display_id machinery
r23013 args, kwargs = pub.call_args_list[1]
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert args == ()
assert kwargs == {
Min RK
test display_id machinery
r23013 'data': {
'text/plain': repr('y')
},
'metadata': {},
'transient': {
'display_id': handle.display_id,
},
Samuel Gaist
[core][tests][display] Remove nose
r26891 }
Min RK
test display_id machinery
r23013 args, kwargs = pub.call_args_list[2]
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert args == ()
assert kwargs == {
Min RK
test display_id machinery
r23013 'data': {
'text/plain': repr('z')
},
'metadata': {},
'transient': {
'display_id': handle2.display_id,
},
Samuel Gaist
[core][tests][display] Remove nose
r26891 }
Min RK
test display_id machinery
r23013
def test_update_display():
ip = get_ipython()
with mock.patch.object(ip.display_pub, 'publish') as pub:
Samuel Gaist
[core][tests][display] Remove nose
r26891 with pytest.raises(TypeError):
Min RK
test display_id machinery
r23013 display.update_display('x')
display.update_display('x', display_id='1')
display.update_display('y', display_id='2')
args, kwargs = pub.call_args_list[0]
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert args == ()
assert kwargs == {
Min RK
test display_id machinery
r23013 'data': {
'text/plain': repr('x')
},
'metadata': {},
'transient': {
'display_id': '1',
},
'update': True,
Samuel Gaist
[core][tests][display] Remove nose
r26891 }
Min RK
test display_id machinery
r23013 args, kwargs = pub.call_args_list[1]
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert args == ()
assert kwargs == {
Min RK
test display_id machinery
r23013 'data': {
'text/plain': repr('y')
},
'metadata': {},
'transient': {
'display_id': '2',
},
'update': True,
Samuel Gaist
[core][tests][display] Remove nose
r26891 }
Min RK
test display_id machinery
r23013
def test_display_handle():
ip = get_ipython()
handle = display.DisplayHandle()
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert isinstance(handle.display_id, str)
handle = display.DisplayHandle("my-id")
assert handle.display_id == "my-id"
with mock.patch.object(ip.display_pub, "publish") as pub:
handle.display("x")
handle.update("y")
Min RK
test display_id machinery
r23013
args, kwargs = pub.call_args_list[0]
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert args == ()
assert kwargs == {
Min RK
test display_id machinery
r23013 'data': {
'text/plain': repr('x')
},
'metadata': {},
'transient': {
'display_id': handle.display_id,
}
Samuel Gaist
[core][tests][display] Remove nose
r26891 }
Min RK
test display_id machinery
r23013 args, kwargs = pub.call_args_list[1]
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert args == ()
assert kwargs == {
Min RK
test display_id machinery
r23013 'data': {
'text/plain': repr('y')
},
'metadata': {},
'transient': {
'display_id': handle.display_id,
},
'update': True,
Samuel Gaist
[core][tests][display] Remove nose
r26891 }
Min RK
implement GIF support without registering a new formatter...
r23849
Blazej Michalik
Add a testcase for Image raising on bad filename
r26416
Pete Blois
Add formal support for alt text to IPython.display.Image....
r26382 def test_image_alt_tag():
"""Simple test for display.Image(args, alt=x,)"""
Pete Blois
Fix lint errors
r26410 thisurl = "http://example.com/image.png"
img = display.Image(url=thisurl, alt="an image")
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert '<img src="%s" alt="an image"/>' % (thisurl) == img._repr_html_()
Pete Blois
Fix lint errors
r26410 img = display.Image(url=thisurl, unconfined=True, alt="an image")
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert (
'<img src="%s" class="unconfined" alt="an image"/>' % (thisurl)
== img._repr_html_()
Pete Blois
Fix lint errors
r26410 )
Pete Blois
Add formal support for alt text to IPython.display.Image....
r26382 img = display.Image(url=thisurl, alt='>"& <')
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert '<img src="%s" alt="&gt;&quot;&amp; &lt;"/>' % (thisurl) == img._repr_html_()
Pete Blois
Add formal support for alt text to IPython.display.Image....
r26382
Pete Blois
Fix lint errors
r26410 img = display.Image(url=thisurl, metadata={"alt": "an image"})
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert img.alt == "an image"
Pete Blois
Add formal support for alt text to IPython.display.Image....
r26382 here = os.path.dirname(__file__)
Pete Blois
Fix lint errors
r26410 img = display.Image(os.path.join(here, "2x2.png"), alt="an image")
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert img.alt == "an image"
Pete Blois
Add formal support for alt text to IPython.display.Image....
r26382 _, md = img._repr_png_()
Samuel Gaist
[core][tests][display] Remove nose
r26891 assert md["alt"] == "an image"
blois
Merge branch 'master' into alt_text
r26808
Blazej Michalik
Add a testcase for Image raising on bad filename
r26416 def test_image_bad_filename_raises_proper_exception():
Samuel Gaist
[core][tests][display] Remove nose
r26891 with pytest.raises(FileNotFoundError):
display.Image("/this/file/does/not/exist/")._repr_png_()