MCPcopy Create free account
hub / github.com/ipython/ipython / test_embed_svg_url

Function test_embed_svg_url

IPython/core/tests/test_display.py:75–107  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

73 nt.assert_equal(md['height'], 1)
74
75def test_embed_svg_url():
76 import gzip
77 from io import BytesIO
78 svg_data = b'<svg><circle x="0" y="0" r="1"/></svg>'
79 url = 'http://test.com/circle.svg'
80
81 gzip_svg = BytesIO()
82 with gzip.open(gzip_svg, 'wb') as fp:
83 fp.write(svg_data)
84 gzip_svg = gzip_svg.getvalue()
85
86 def mocked_urlopen(*args, **kwargs):
87 class MockResponse:
88 def __init__(self, svg):
89 self._svg_data = svg
90 self.headers = {'content-type': 'image/svg+xml'}
91
92 def read(self):
93 return self._svg_data
94
95 if args[0] == url:
96 return MockResponse(svg_data)
97 elif args[0] == url + 'z':
98 ret= MockResponse(gzip_svg)
99 ret.headers['content-encoding']= 'gzip'
100 return ret
101 return MockResponse(None)
102
103 with mock.patch('urllib.request.urlopen', side_effect=mocked_urlopen):
104 svg = display.SVG(url=url)
105 nt.assert_true(svg._repr_svg_().startswith('<svg'))
106 svg = display.SVG(url=url + 'z')
107 nt.assert_true(svg._repr_svg_().startswith('<svg'))
108
109def test_retina_jpeg():
110 here = os.path.dirname(__file__)

Callers

nothing calls this directly

Calls 2

_repr_svg_Method · 0.95
writeMethod · 0.45

Tested by

no test coverage detected