MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_svgid

Function test_svgid

lib/matplotlib/tests/test_backend_svg.py:679–707  ·  view source on GitHub ↗

Test that `svg.id` rcparam appears in output svg if not None.

()

Source from the content-addressed store, hash-verified

677
678
679def test_svgid():
680 """Test that `svg.id` rcparam appears in output svg if not None."""
681
682 fig, ax = plt.subplots()
683 ax.plot([1, 2, 3], [3, 2, 1])
684 fig.canvas.draw()
685
686 # Default: svg.id = None
687 with BytesIO() as fd:
688 fig.savefig(fd, format='svg')
689 buf = fd.getvalue().decode()
690
691 tree = xml.etree.ElementTree.fromstring(buf)
692
693 assert plt.rcParams['svg.id'] is None
694 assert not tree.findall('.[@id]')
695
696 # String: svg.id = str
697 svg_id = 'a test for issue 28535'
698 plt.rc('svg', id=svg_id)
699
700 with BytesIO() as fd:
701 fig.savefig(fd, format='svg')
702 buf = fd.getvalue().decode()
703
704 tree = xml.etree.ElementTree.fromstring(buf)
705
706 assert plt.rcParams['svg.id'] == svg_id
707 assert tree.findall(f'.[@id="{svg_id}"]')

Callers

nothing calls this directly

Calls 4

subplotsMethod · 0.45
plotMethod · 0.45
drawMethod · 0.45
savefigMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…