# -*- coding: utf-8 -*- """ test_ext_graphviz ~~~~~~~~~~~~~~~~~ Test sphinx.ext.graphviz extension. :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ import re 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').text() html = (r'
\s*\s*

' r'caption of graph.*

\s*
') assert re.search(html, content, re.S) html = 'Hello \n graphviz world' assert re.search(html, content, re.S) html = 'digraph {\n  bar -> baz\n}' assert re.search(html, content, re.M) html = (r'
\s*\s*

' r'on right.*

\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').text() html = (r'
\n' r'\n' r'\s+

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

\n' r'

' r'caption of graph.*

\n
') 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) html = (r'
\n' r'\n' r'\s+

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

\n' r'

' r'on right.*

\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 / 'SphinxTests.tex').text() macro = ('\\\\begin{figure}\\[htbp\\]\n\\\\centering\n\\\\capstart\n\n' '\\\\includegraphics{graphviz-\\w+.pdf}\n' '\\\\caption{caption of graph}\\\\label{.*}\\\\end{figure}') assert re.search(macro, content, re.S) macro = 'Hello \\\\includegraphics{graphviz-\\w+.pdf} graphviz world' assert re.search(macro, content, re.S) macro = ('\\\\begin{wrapfigure}{r}{0pt}\n\\\\centering\n' '\\\\includegraphics{graphviz-\\w+.pdf}\n' '\\\\caption{on right}\\\\label{.*}\\\\end{wrapfigure}') assert re.search(macro, content, re.S) macro = (r'\{\\hfill' r'\\includegraphics{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').text() html = 'digraph {\n  BAR -> BAZ\n}' assert re.search(html, content, re.M) def test_graphviz_parse_mapfile(): # digraph { # } content = ('\n' '') cmap = ClickableMapDefinition('dummy.map', content) assert cmap.filename == 'dummy.map' assert cmap.id == '%3' assert len(cmap.clickable) == 0 assert cmap.generate_clickable_map() == '' # digraph { # foo [href="http://www.google.com/"]; # foo -> bar; # } content = ('\n' '\n' '') cmap = ClickableMapDefinition('dummy.map', content) assert cmap.filename == 'dummy.map' assert cmap.id == '%3' assert len(cmap.clickable) == 1 assert cmap.generate_clickable_map() == content # inheritance-diagram:: sphinx.builders.html content = ( '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '' ) cmap = ClickableMapDefinition('dummy.map', content) assert cmap.filename == 'dummy.map' assert cmap.id == 'inheritance66ff5471b9' assert len(cmap.clickable) == 0 assert cmap.generate_clickable_map() == ''