Test that `svg.id` rcparam appears in output svg if not None.
()
| 677 | |
| 678 | |
| 679 | def 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}"]') |