Show More
@@ -73,11 +73,44 def test_retina_png(): | |||
|
73 | 73 | nt.assert_equal(md['height'], 1) |
|
74 | 74 | |
|
75 | 75 | def test_embed_svg_url(): |
|
76 | # 6.1kB of data | |
|
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 | ||
|
109 | # do it for real: 6.1kB of data | |
|
77 | 110 | url = "https://upload.wikimedia.org/wikipedia/commons/3/30/Vector-based_example.svg" |
|
78 | 111 | svg = display.SVG(url=url) |
|
79 |
nt.assert_true(svg._repr_svg_().startswith('<svg |
|
|
80 | ||
|
112 | nt.assert_true(svg._repr_svg_().startswith('<svg')) | |
|
113 | ||
|
81 | 114 | def test_retina_jpeg(): |
|
82 | 115 | here = os.path.dirname(__file__) |
|
83 | 116 | img = display.Image(os.path.join(here, "2x2.jpg"), retina=True) |
General Comments 0
You need to be logged in to leave comments.
Login now