From e863fd965dd6253243c3342bd6f0adc4fc8aec4d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 13:31:33 +0200 Subject: Adding upstream version 5.3.0. Signed-off-by: Daniel Baumann --- tests/test_ext_graphviz.py | 209 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 tests/test_ext_graphviz.py (limited to 'tests/test_ext_graphviz.py') diff --git a/tests/test_ext_graphviz.py b/tests/test_ext_graphviz.py new file mode 100644 index 0000000..649cf18 --- /dev/null +++ b/tests/test_ext_graphviz.py @@ -0,0 +1,209 @@ +"""Test sphinx.ext.graphviz extension.""" + +import re + +import docutils +import pytest + +from sphinx.ext.graphviz import ClickableMapDefinition + + +@pytest.mark.sphinx('html', testroot='ext-graphviz') +@pytest.mark.usefixtures('if_graphviz_found') +def test_graphviz_png_html(app, status, warning): + app.builder.build_all() + + content = (app.outdir / 'index.html').read_text(encoding='utf8') + if docutils.__version_info__ < (0, 17): + html = (r'
\s*' + r'
\s*

' + r'caption of graph.*

\s*
') + else: + html = (r'
\s*' + r'
\s*
\s*' + r'

caption of graph.*

\s*' + r'
\s*
') + assert re.search(html, content, re.S) + + html = 'Hello
\n graphviz world' + assert re.search(html, content, re.S) + + html = ('digraph foo {\nbaz -> qux\n}') + assert re.search(html, content, re.S) + + if docutils.__version_info__ < (0, 17): + html = (r'
\s*' + r'
\s*

' + r'on right.*

\s*
') + else: + html = (r'
\s*' + r'
\s*
\s*' + r'

on right.*

\s*' + r'
\s*
') + assert re.search(html, content, re.S) + + html = (r'
' + r'
\"digraph
\n
') + assert re.search(html, content, re.S) + + +@pytest.mark.sphinx('html', testroot='ext-graphviz', + confoverrides={'graphviz_output_format': 'svg'}) +@pytest.mark.usefixtures('if_graphviz_found') +def test_graphviz_svg_html(app, status, warning): + app.builder.build_all() + + content = (app.outdir / 'index.html').read_text(encoding='utf8') + + if docutils.__version_info__ < (0, 17): + html = (r'
\n' + r'
\n' + r'\s*

digraph foo {\n' + r'bar -> baz\n' + r'}

\n' + r'

' + r'caption of graph.*

\n
') + else: + html = (r'
\n' + r'
\n' + r'\s*

digraph foo {\n' + r'bar -> baz\n' + r'}

\n' + r'
\n' + r'

caption of graph.*

\n' + r'
\n' + r'
') + assert re.search(html, content, re.S) + + html = (r'Hello
\n' + r'\s*

graph

\n' + r' graphviz world') + assert re.search(html, content, re.S) + + if docutils.__version_info__ < (0, 17): + html = (r'
\n' + r'
\n' + r'\s*

digraph bar {\n' + r'foo -> bar\n' + r'}

\n' + r'

' + r'on right.*

\n' + r'
') + else: + html = (r'
\n' + r'
\n' + r'\s*

digraph bar {\n' + r'foo -> bar\n' + r'}

\n' + r'
\n' + r'

on right.*

\n' + r'
\n' + r'
') + assert re.search(html, content, re.S) + + html = (r'
' + r'
\n' + r'\s*

digraph foo {\n' + r'centered\n' + r'}

\n' + r'
') + assert re.search(html, content, re.S) + + +@pytest.mark.sphinx('latex', testroot='ext-graphviz') +@pytest.mark.usefixtures('if_graphviz_found') +def test_graphviz_latex(app, status, warning): + app.builder.build_all() + + content = (app.outdir / 'python.tex').read_text(encoding='utf8') + macro = ('\\\\begin{figure}\\[htbp\\]\n\\\\centering\n\\\\capstart\n\n' + '\\\\sphinxincludegraphics\\[\\]{graphviz-\\w+.pdf}\n' + '\\\\caption{caption of graph}\\\\label{.*}\\\\end{figure}') + assert re.search(macro, content, re.S) + + macro = 'Hello \\\\sphinxincludegraphics\\[\\]{graphviz-\\w+.pdf} graphviz world' + assert re.search(macro, content, re.S) + + macro = ('\\\\begin{wrapfigure}{r}{0pt}\n\\\\centering\n' + '\\\\sphinxincludegraphics\\[\\]{graphviz-\\w+.pdf}\n' + '\\\\caption{on \\\\sphinxstyleemphasis{right}}' + '\\\\label{.*}\\\\end{wrapfigure}') + assert re.search(macro, content, re.S) + + macro = (r'\{\\hfill' + r'\\sphinxincludegraphics\[\]{graphviz-.*}' + r'\\hspace\*{\\fill}}') + assert re.search(macro, content, re.S) + + +@pytest.mark.sphinx('html', testroot='ext-graphviz', confoverrides={'language': 'xx'}) +@pytest.mark.usefixtures('if_graphviz_found') +def test_graphviz_i18n(app, status, warning): + app.builder.build_all() + + content = (app.outdir / 'index.html').read_text(encoding='utf8') + html = 'digraph {\n  BAR -> BAZ\n}' + assert re.search(html, content, re.M) + + +def test_graphviz_parse_mapfile(): + # empty graph + code = ('# digraph {\n' + '# }\n') + content = ('\n' + '') + cmap = ClickableMapDefinition('dummy.map', content, code) + assert cmap.filename == 'dummy.map' + assert cmap.id == 'grapvizb08107169e' + assert len(cmap.clickable) == 0 + assert cmap.generate_clickable_map() == '' + + # normal graph + code = ('digraph {\n' + ' foo [href="http://www.google.com/"];\n' + ' foo -> bar;\n' + '}\n') + content = ('\n' + '\n' + '') + cmap = ClickableMapDefinition('dummy.map', content, code) + assert cmap.filename == 'dummy.map' + assert cmap.id == 'grapviza4ccdd48ce' + assert len(cmap.clickable) == 1 + assert cmap.generate_clickable_map() == content.replace('%3', cmap.id) + + # inheritance-diagram:: sphinx.builders.html + content = ( + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '' + ) + cmap = ClickableMapDefinition('dummy.map', content, 'dummy_code') + assert cmap.filename == 'dummy.map' + assert cmap.id == 'inheritance66ff5471b9' + assert len(cmap.clickable) == 0 + assert cmap.generate_clickable_map() == '' -- cgit v1.2.3