MCPcopy Index your code
hub / github.com/ipython/ipython / test_embed_svg_url

Function test_embed_svg_url

tests/test_display_2.py:74–107  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

72
73
74def test_embed_svg_url():
75 import gzip
76 from io import BytesIO
77
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 assert svg._repr_svg_().startswith("<svg") is True
106 svg = display.SVG(url=url + "z")
107 assert svg._repr_svg_().startswith("<svg") is True
108
109
110def test_retina_jpeg():

Callers

nothing calls this directly

Calls 2

_repr_svg_Method · 0.95
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…