# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
import json
import os
import warnings
from unittest import mock
import nose.tools as nt
from IPython.core import display
from IPython.core.getipython import get_ipython
from IPython.utils.io import capture_output
from IPython.utils.tempdir import NamedFileInTemporaryDirectory
from IPython import paths as ipath
from IPython.testing.tools import AssertNotPrints
import IPython.testing.decorators as dec
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'' % (thisurl), img._repr_html_())
img = display.Image(url=thisurl, metadata={'width':200, 'height':200})
nt.assert_equal(u'' % (thisurl), img._repr_html_())
img = display.Image(url=thisurl, width=200)
nt.assert_equal(u'' % (thisurl), img._repr_html_())
img = display.Image(url=thisurl)
nt.assert_equal(u'' % (thisurl), img._repr_html_())
img = display.Image(url=thisurl, unconfined=True)
nt.assert_equal(u'' % (thisurl), img._repr_html_())
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)
nt.assert_equal(sorted(data), sorted([mime, 'text/plain']))
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,
})
nt.assert_equal(u'', str(gj))
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_embed_svg_url():
# 6.1kB of data
url = "https://upload.wikimedia.org/wikipedia/commons/3/30/Vector-based_example.svg"
svg = display.SVG(url=url)
nt.assert_true(svg._repr_svg_().startswith('