"""Test sphinx.ext.graphviz extension."""
import re
import sys
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')
html = (r'')
assert re.search(html, content, re.S)
html = 'Hello
\n graphviz world'
assert re.search(html, content, re.S)
html = ('')
assert re.search(html, content, re.S)
html = (r'')
assert re.search(html, content, re.S)
html = (r'')
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')
html = (r'')
assert re.search(html, content, re.S)
html = (r'Hello \n'
r' graphviz world')
assert re.search(html, content, re.S)
html = (r'')
assert re.search(html, content, re.S)
html = (r''
r'
\n'
r'
')
assert re.search(html, content, re.S)
image_re = r'.*data="([^"]+)".*?digraph test'
image_path_match = re.search(image_re, content, re.S)
assert image_path_match
image_path = image_path_match.group(1)
image_content = (app.outdir / image_path).read_text(encoding='utf8')
if sys.platform == 'win32':
assert '".\\_static\\' not in image_content
assert r'\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 = ('')
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 = (
''
)
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() == ''