Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3964f2a

Browse files
committed
Add test for urls on ticks in svg.
1 parent a022b52 commit 3964f2a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,42 @@ def test_savefig_tight():
214214
# Check that the draw-disabled renderer correctly disables open/close_group
215215
# as well.
216216
plt.savefig(BytesIO(), format="svgz", bbox_inches="tight")
217+
218+
219+
def test_url():
220+
# Test that object url appears in output svg.
221+
222+
fig, ax = plt.subplots()
223+
s = ax.scatter([1, 2, 3], [4, 5, 6])
224+
s.set_urls(['http://example.com/foo', 'http://example.com/bar', None])
225+
226+
b = BytesIO()
227+
fig.savefig(b, format='svg')
228+
b = b.getvalue()
229+
assert b'http://example.com/foo' in b
230+
assert b'http://example.com/bar' in b
231+
232+
233+
def test_url_tick():
234+
fig1, ax = plt.subplots()
235+
ax.scatter([1, 2, 3], [4, 5, 6])
236+
for i, tick in enumerate(ax.yaxis.get_major_ticks()):
237+
tick.set_url(f'http://example.com/{i}')
238+
239+
fig2, ax = plt.subplots()
240+
ax.scatter([1, 2, 3], [4, 5, 6])
241+
for i, tick in enumerate(ax.yaxis.get_major_ticks()):
242+
tick.label1.set_url(f'http://example.com/{i}')
243+
tick.label2.set_url(f'http://example.com/{i}')
244+
245+
b1 = BytesIO()
246+
fig1.savefig(b1, format='svg')
247+
b1 = b1.getvalue()
248+
249+
b2 = BytesIO()
250+
fig2.savefig(b2, format='svg')
251+
b2 = b2.getvalue()
252+
253+
for i in range(len(ax.yaxis.get_major_ticks())):
254+
assert f'http://example.com/{i}'.encode('ascii') in b1
255+
assert b1 == b2

0 commit comments

Comments
 (0)