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

Function test_tinypages

lib/matplotlib/tests/test_sphinxext.py:42–124  ·  view source on GitHub ↗
(tmp_path)

Source from the content-addressed store, hash-verified

40
41
42def test_tinypages(tmp_path):
43 shutil.copytree(tinypages, tmp_path, dirs_exist_ok=True,
44 ignore=shutil.ignore_patterns('_build', 'doctrees',
45 'plot_directive'))
46 html_dir = tmp_path / '_build' / 'html'
47 img_dir = html_dir / '_images'
48 doctree_dir = tmp_path / 'doctrees'
49
50 # Build the pages with warnings turned into errors
51 build_sphinx_html(tmp_path, doctree_dir, html_dir)
52
53 def plot_file(num):
54 return img_dir / f'some_plots-{num}.png'
55
56 def plot_directive_file(num):
57 # This is always next to the doctree dir.
58 return doctree_dir.parent / 'plot_directive' / f'some_plots-{num}.png'
59
60 range_10, range_6, range_4 = (plot_file(i) for i in range(1, 4))
61 # Plot 5 is range(6) plot
62 assert filecmp.cmp(range_6, plot_file(5))
63 # Plot 7 is range(4) plot
64 assert filecmp.cmp(range_4, plot_file(7))
65 # Plot 11 is range(10) plot
66 assert filecmp.cmp(range_10, plot_file(11))
67 # Plot 12 uses the old range(10) figure and the new range(6) figure
68 assert filecmp.cmp(range_10, plot_file('12_00'))
69 assert filecmp.cmp(range_6, plot_file('12_01'))
70 # Plot 13 shows close-figs in action
71 assert filecmp.cmp(range_4, plot_file(13))
72 # Plot 14 has included source
73 html_contents = (html_dir / 'some_plots.html').read_text(encoding='utf-8')
74
75 assert '# Only a comment' in html_contents
76 # check plot defined in external file.
77 assert filecmp.cmp(range_4, img_dir / 'range4.png')
78 assert filecmp.cmp(range_6, img_dir / 'range6_range6.png')
79 # check if figure caption made it into html file
80 assert 'This is the caption for plot 15.' in html_contents
81 # check if figure caption using :caption: made it into html file (because this plot
82 # doesn't use srcset, the caption preserves newlines in the output.)
83 assert 'Plot 17 uses the caption option,\nwith multi-line input.' in html_contents
84 # check if figure alt text using :alt: made it into html file
85 assert 'Plot 17 uses the alt option, with multi-line input.' in html_contents
86 # check if figure caption made it into html file
87 assert 'This is the caption for plot 18.' in html_contents
88 # check if the custom classes made it into the html file
89 assert 'plot-directive my-class my-other-class' in html_contents
90 # check that the multi-image caption is applied twice
91 assert html_contents.count('This caption applies to both plots.') == 2
92 # Plot 21 is range(6) plot via an include directive. But because some of
93 # the previous plots are repeated, the argument to plot_file() is only 17.
94 assert filecmp.cmp(range_6, plot_file(17))
95 # plot 22 is from the range6.py file again, but a different function
96 assert filecmp.cmp(range_10, img_dir / 'range6_range10.png')
97 # plots 23--25 use a custom basename
98 assert filecmp.cmp(range_6, img_dir / 'custom-basename-6.png')
99 assert filecmp.cmp(range_4, img_dir / 'custom-basename-4.png')

Callers

nothing calls this directly

Calls 4

build_sphinx_htmlFunction · 0.85
plot_fileFunction · 0.85
plot_directive_fileFunction · 0.85
countMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…