2015-06-26 07:23:03 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
test_ext_graphviz
|
|
|
|
~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test sphinx.ext.graphviz extension.
|
|
|
|
|
2019-01-02 01:00:30 -06:00
|
|
|
:copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
|
2015-06-26 07:23:03 -05:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
2015-07-25 09:43:08 -05:00
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
import pytest
|
2016-02-21 23:52:01 -06:00
|
|
|
|
2018-01-29 06:09:27 -06:00
|
|
|
from sphinx.ext.graphviz import ClickableMapDefinition
|
|
|
|
|
2016-02-21 23:52:01 -06:00
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('html', testroot='ext-graphviz')
|
2017-01-03 07:24:00 -06:00
|
|
|
@pytest.mark.usefixtures('if_graphviz_found')
|
2017-09-18 05:10:19 -05:00
|
|
|
def test_graphviz_png_html(app, status, warning):
|
2015-06-26 07:23:03 -05:00
|
|
|
app.builder.build_all()
|
2015-07-25 09:43:08 -05:00
|
|
|
|
|
|
|
content = (app.outdir / 'index.html').text()
|
2018-04-20 01:10:30 -05:00
|
|
|
html = (r'<div class="figure" .*?>\s*'
|
|
|
|
r'<div class="graphviz"><img .*?/></div>\s*<p class="caption">'
|
2017-02-12 11:02:51 -06:00
|
|
|
r'<span class="caption-text">caption of graph</span>.*</p>\s*</div>')
|
2015-07-25 09:43:08 -05:00
|
|
|
assert re.search(html, content, re.S)
|
2016-01-06 06:56:21 -06:00
|
|
|
|
2018-04-20 01:10:30 -05:00
|
|
|
html = 'Hello <div class="graphviz"><img .*?/></div>\n graphviz world'
|
2016-01-06 06:56:21 -06:00
|
|
|
assert re.search(html, content, re.S)
|
|
|
|
|
2018-08-04 04:38:39 -05:00
|
|
|
html = '<img src=".*?" alt="digraph {\n bar -> baz\n}" class="graphviz" />'
|
2016-01-28 07:12:28 -06:00
|
|
|
assert re.search(html, content, re.M)
|
|
|
|
|
2018-04-20 01:10:30 -05:00
|
|
|
html = (r'<div class="figure align-right" .*?>\s*'
|
|
|
|
r'<div class="graphviz"><img .*?/></div>\s*<p class="caption">'
|
2017-02-12 11:02:51 -06:00
|
|
|
r'<span class="caption-text">on right</span>.*</p>\s*</div>')
|
2016-05-25 11:50:21 -05:00
|
|
|
assert re.search(html, content, re.S)
|
|
|
|
|
2017-09-18 05:10:19 -05:00
|
|
|
html = (r'<div align=\"center\" class=\"align-center\">'
|
2018-04-20 01:10:30 -05:00
|
|
|
r'<div class="graphviz"><img src=\".*\.png\" alt=\"digraph foo {\n'
|
2017-09-18 05:10:19 -05:00
|
|
|
r'centered\n'
|
2018-08-04 04:38:39 -05:00
|
|
|
r'}\" class="graphviz" /></div>\n</div>')
|
2017-09-18 05:10:19 -05:00
|
|
|
assert re.search(html, content, re.S)
|
|
|
|
|
2017-12-23 06:20:32 -06:00
|
|
|
|
2017-09-18 05:10:19 -05:00
|
|
|
@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'<div class=\"figure\" .*?>\n'
|
2018-04-20 01:10:30 -05:00
|
|
|
r'<div class="graphviz"><object data=\".*\.svg\".*>\n'
|
2018-04-20 23:59:27 -05:00
|
|
|
r'\s*<p class=\"warning\">digraph foo {\n'
|
2017-09-18 05:10:19 -05:00
|
|
|
r'bar -> baz\n'
|
2018-04-20 01:10:30 -05:00
|
|
|
r'}</p></object></div>\n'
|
2017-09-18 05:10:19 -05:00
|
|
|
r'<p class=\"caption\"><span class=\"caption-text\">'
|
|
|
|
r'caption of graph</span>.*</p>\n</div>')
|
|
|
|
assert re.search(html, content, re.S)
|
|
|
|
|
2018-04-20 01:10:30 -05:00
|
|
|
html = (r'Hello <div class="graphviz"><object.*>\n'
|
2018-04-20 23:59:27 -05:00
|
|
|
r'\s*<p class=\"warning\">graph</p></object></div>\n'
|
2017-09-18 05:10:19 -05:00
|
|
|
r' graphviz world')
|
|
|
|
assert re.search(html, content, re.S)
|
|
|
|
|
|
|
|
html = (r'<div class=\"figure align-right\" .*\>\n'
|
2018-04-20 01:10:30 -05:00
|
|
|
r'<div class="graphviz"><object data=\".*\.svg\".*>\n'
|
2018-04-20 23:59:27 -05:00
|
|
|
r'\s*<p class=\"warning\">digraph bar {\n'
|
2017-09-18 05:10:19 -05:00
|
|
|
r'foo -> bar\n'
|
2018-04-20 01:10:30 -05:00
|
|
|
r'}</p></object></div>\n'
|
2017-09-18 05:10:19 -05:00
|
|
|
r'<p class=\"caption\"><span class=\"caption-text\">'
|
|
|
|
r'on right</span>.*</p>\n'
|
|
|
|
r'</div>')
|
|
|
|
assert re.search(html, content, re.S)
|
|
|
|
|
|
|
|
html = (r'<div align=\"center\" class=\"align-center\">'
|
2018-04-20 01:10:30 -05:00
|
|
|
r'<div class="graphviz"><object data=\".*\.svg\".*>\n'
|
2018-04-20 23:59:27 -05:00
|
|
|
r'\s*<p class=\"warning\">digraph foo {\n'
|
2017-09-18 05:10:19 -05:00
|
|
|
r'centered\n'
|
2018-04-20 01:10:30 -05:00
|
|
|
r'}</p></object></div>\n'
|
2017-09-18 05:10:19 -05:00
|
|
|
r'</div>')
|
|
|
|
assert re.search(html, content, re.S)
|
2016-01-06 06:56:21 -06:00
|
|
|
|
2017-12-23 06:20:32 -06:00
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('latex', testroot='ext-graphviz')
|
2017-01-03 07:24:00 -06:00
|
|
|
@pytest.mark.usefixtures('if_graphviz_found')
|
2016-01-06 06:56:21 -06:00
|
|
|
def test_graphviz_latex(app, status, warning):
|
|
|
|
app.builder.build_all()
|
|
|
|
|
|
|
|
content = (app.outdir / 'SphinxTests.tex').text()
|
2017-02-12 11:02:51 -06:00
|
|
|
macro = ('\\\\begin{figure}\\[htbp\\]\n\\\\centering\n\\\\capstart\n\n'
|
2018-02-11 08:32:59 -06:00
|
|
|
'\\\\sphinxincludegraphics\\[\\]{graphviz-\\w+.pdf}\n'
|
2016-02-12 10:18:39 -06:00
|
|
|
'\\\\caption{caption of graph}\\\\label{.*}\\\\end{figure}')
|
2016-01-06 06:56:21 -06:00
|
|
|
assert re.search(macro, content, re.S)
|
|
|
|
|
2018-02-11 08:32:59 -06:00
|
|
|
macro = 'Hello \\\\sphinxincludegraphics\\[\\]{graphviz-\\w+.pdf} graphviz world'
|
2016-01-06 06:56:21 -06:00
|
|
|
assert re.search(macro, content, re.S)
|
2016-01-28 07:12:28 -06:00
|
|
|
|
2016-05-25 11:50:21 -05:00
|
|
|
macro = ('\\\\begin{wrapfigure}{r}{0pt}\n\\\\centering\n'
|
2018-02-11 08:32:59 -06:00
|
|
|
'\\\\sphinxincludegraphics\\[\\]{graphviz-\\w+.pdf}\n'
|
2016-05-25 11:50:21 -05:00
|
|
|
'\\\\caption{on right}\\\\label{.*}\\\\end{wrapfigure}')
|
|
|
|
assert re.search(macro, content, re.S)
|
|
|
|
|
2017-09-18 05:10:19 -05:00
|
|
|
macro = (r'\{\\hfill'
|
2018-02-11 08:32:59 -06:00
|
|
|
r'\\sphinxincludegraphics\[\]{graphviz-.*}'
|
2017-09-18 05:10:19 -05:00
|
|
|
r'\\hspace\*{\\fill}}')
|
|
|
|
assert re.search(macro, content, re.S)
|
|
|
|
|
2016-01-28 07:12:28 -06:00
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('html', testroot='ext-graphviz', confoverrides={'language': 'xx'})
|
2017-01-03 07:24:00 -06:00
|
|
|
@pytest.mark.usefixtures('if_graphviz_found')
|
2016-01-28 07:12:28 -06:00
|
|
|
def test_graphviz_i18n(app, status, warning):
|
|
|
|
app.builder.build_all()
|
|
|
|
|
|
|
|
content = (app.outdir / 'index.html').text()
|
2018-08-04 04:38:39 -05:00
|
|
|
html = '<img src=".*?" alt="digraph {\n BAR -> BAZ\n}" class="graphviz" />'
|
2016-01-28 07:12:28 -06:00
|
|
|
assert re.search(html, content, re.M)
|
2018-01-29 06:09:27 -06:00
|
|
|
|
|
|
|
|
|
|
|
def test_graphviz_parse_mapfile():
|
2018-01-29 06:09:28 -06:00
|
|
|
# empty graph
|
|
|
|
code = ('# digraph {\n'
|
|
|
|
'# }\n')
|
2018-01-29 06:09:27 -06:00
|
|
|
content = ('<map id="%3" name="%3">\n'
|
|
|
|
'</map>')
|
2018-01-29 06:09:28 -06:00
|
|
|
cmap = ClickableMapDefinition('dummy.map', content, code)
|
2018-01-29 06:09:27 -06:00
|
|
|
assert cmap.filename == 'dummy.map'
|
2018-01-29 06:09:28 -06:00
|
|
|
assert cmap.id == 'grapvizb08107169e'
|
2018-01-29 06:09:27 -06:00
|
|
|
assert len(cmap.clickable) == 0
|
|
|
|
assert cmap.generate_clickable_map() == ''
|
|
|
|
|
2018-01-29 06:09:28 -06:00
|
|
|
# normal graph
|
|
|
|
code = ('digraph {\n'
|
|
|
|
' foo [href="http://www.google.com/"];\n'
|
|
|
|
' foo -> bar;\n'
|
|
|
|
'}\n')
|
2018-01-29 06:09:27 -06:00
|
|
|
content = ('<map id="%3" name="%3">\n'
|
|
|
|
'<area shape="poly" id="node1" href="http://www.google.com/" title="foo" alt=""'
|
|
|
|
' coords="77,29,76,22,70,15,62,10,52,7,41,5,30,7,20,10,12,15,7,22,5,29,7,37,12,'
|
|
|
|
'43,20,49,30,52,41,53,52,52,62,49,70,43,76,37"/>\n'
|
|
|
|
'</map>')
|
2018-01-29 06:09:28 -06:00
|
|
|
cmap = ClickableMapDefinition('dummy.map', content, code)
|
2018-01-29 06:09:27 -06:00
|
|
|
assert cmap.filename == 'dummy.map'
|
2018-01-29 06:09:28 -06:00
|
|
|
assert cmap.id == 'grapviza4ccdd48ce'
|
2018-01-29 06:09:27 -06:00
|
|
|
assert len(cmap.clickable) == 1
|
2018-01-29 06:09:28 -06:00
|
|
|
assert cmap.generate_clickable_map() == content.replace('%3', cmap.id)
|
2018-01-29 06:09:27 -06:00
|
|
|
|
|
|
|
# inheritance-diagram:: sphinx.builders.html
|
|
|
|
content = (
|
|
|
|
'<map id="inheritance66ff5471b9" name="inheritance66ff5471b9">\n'
|
|
|
|
'<area shape="rect" id="node1" title="Builds target formats from the reST sources."'
|
|
|
|
' alt="" coords="26,95,125,110"/>\n'
|
|
|
|
'<area shape="rect" id="node5" title="Builds standalone HTML docs."'
|
|
|
|
' alt="" coords="179,95,362,110"/>\n'
|
|
|
|
'<area shape="rect" id="node2" title="buildinfo file manipulator." '
|
|
|
|
' alt="" coords="14,64,138,80"/>\n'
|
|
|
|
'<area shape="rect" id="node3" title="The container of stylesheets."'
|
|
|
|
' alt="" coords="3,34,148,49"/>\n'
|
|
|
|
'<area shape="rect" id="node4" title="A StandaloneHTMLBuilder that creates all HTML'
|
|
|
|
' pages as "index.html" in" alt="" coords="395,64,569,80"/>\n'
|
|
|
|
'<area shape="rect" id="node7" title="An abstract builder that serializes'
|
|
|
|
' the generated HTML." alt="" coords="392,95,571,110"/>\n'
|
|
|
|
'<area shape="rect" id="node9" title="A StandaloneHTMLBuilder subclass that puts'
|
|
|
|
' the whole document tree on one" alt="" coords="393,125,570,141"/>\n'
|
|
|
|
'<area shape="rect" id="node6" title="A builder that dumps the generated HTML'
|
|
|
|
' into JSON files." alt="" coords="602,80,765,95"/>\n'
|
|
|
|
'<area shape="rect" id="node8" title="A Builder that dumps the generated HTML'
|
|
|
|
' into pickle files." alt="" coords="602,110,765,125"/>\n'
|
|
|
|
'<area shape="rect" id="node10" title="The metadata of stylesheet."'
|
|
|
|
' alt="" coords="11,3,141,19"/>\n'
|
|
|
|
'</map>'
|
|
|
|
)
|
2018-01-29 06:09:28 -06:00
|
|
|
cmap = ClickableMapDefinition('dummy.map', content, 'dummy_code')
|
2018-01-29 06:09:27 -06:00
|
|
|
assert cmap.filename == 'dummy.map'
|
|
|
|
assert cmap.id == 'inheritance66ff5471b9'
|
|
|
|
assert len(cmap.clickable) == 0
|
|
|
|
assert cmap.generate_clickable_map() == ''
|