2015-06-26 07:23:03 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
test_ext_graphviz
|
|
|
|
~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test sphinx.ext.graphviz extension.
|
|
|
|
|
2016-01-14 15:54:04 -06:00
|
|
|
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
2015-06-26 07:23:03 -05:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
2016-02-21 23:52:01 -06:00
|
|
|
import subprocess
|
|
|
|
from functools import wraps
|
2015-07-25 09:43:08 -05:00
|
|
|
|
|
|
|
from util import with_app, SkipTest
|
2015-06-26 07:23:03 -05:00
|
|
|
|
|
|
|
|
2016-02-21 23:52:01 -06:00
|
|
|
def skip_if_graphviz_not_found(fn):
|
|
|
|
@wraps(fn)
|
|
|
|
def decorator(app, *args, **kwargs):
|
|
|
|
found = False
|
|
|
|
graphviz_dot = getattr(app.config, 'graphviz_dot', '')
|
|
|
|
try:
|
|
|
|
if graphviz_dot:
|
|
|
|
dot = subprocess.Popen([graphviz_dot, '-V'],
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE) # show version
|
2016-12-14 22:12:13 -06:00
|
|
|
dot.communicate()
|
2016-02-21 23:52:01 -06:00
|
|
|
found = True
|
|
|
|
except OSError: # No such file or directory
|
|
|
|
pass
|
|
|
|
|
|
|
|
if not found:
|
|
|
|
raise SkipTest('graphviz "dot" is not available')
|
|
|
|
|
|
|
|
return fn(app, *args, **kwargs)
|
|
|
|
|
|
|
|
return decorator
|
|
|
|
|
|
|
|
|
2015-06-26 07:23:03 -05:00
|
|
|
@with_app('html', testroot='ext-graphviz')
|
2016-02-21 23:52:01 -06:00
|
|
|
@skip_if_graphviz_not_found
|
2016-01-06 06:56:21 -06:00
|
|
|
def test_graphviz_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()
|
2016-01-06 06:56:21 -06:00
|
|
|
html = ('<div class="figure" .*?>\s*<img .*?/>\s*<p class="caption">'
|
|
|
|
'<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
|
|
|
|
|
|
|
html = 'Hello <img .*?/>\n graphviz world'
|
|
|
|
assert re.search(html, content, re.S)
|
|
|
|
|
2016-01-28 07:12:28 -06:00
|
|
|
html = '<img src=".*?" alt="digraph {\n bar -> baz\n}" />'
|
|
|
|
assert re.search(html, content, re.M)
|
|
|
|
|
2016-05-25 11:50:21 -05:00
|
|
|
html = ('<div class="figure align-right" .*?>\s*<img .*?/>\s*<p class="caption">'
|
|
|
|
'<span class="caption-text">on right</span>.*</p>\s*</div>')
|
|
|
|
assert re.search(html, content, re.S)
|
|
|
|
|
2016-01-06 06:56:21 -06:00
|
|
|
|
|
|
|
@with_app('latex', testroot='ext-graphviz')
|
2016-02-21 23:52:01 -06:00
|
|
|
@skip_if_graphviz_not_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()
|
|
|
|
macro = ('\\\\begin{figure}\[htbp\]\n\\\\centering\n\\\\capstart\n\n'
|
|
|
|
'\\\\includegraphics{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)
|
|
|
|
|
|
|
|
macro = 'Hello \\\\includegraphics{graphviz-\w+.pdf} graphviz world'
|
|
|
|
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'
|
|
|
|
'\\\\includegraphics{graphviz-\w+.pdf}\n'
|
|
|
|
'\\\\caption{on right}\\\\label{.*}\\\\end{wrapfigure}')
|
|
|
|
assert re.search(macro, content, re.S)
|
|
|
|
|
2016-01-28 07:12:28 -06:00
|
|
|
|
|
|
|
@with_app('html', testroot='ext-graphviz', confoverrides={'language': 'xx'})
|
|
|
|
@skip_if_graphviz_not_found
|
|
|
|
def test_graphviz_i18n(app, status, warning):
|
|
|
|
app.builder.build_all()
|
|
|
|
|
|
|
|
content = (app.outdir / 'index.html').text()
|
|
|
|
html = '<img src=".*?" alt="digraph {\n BAR -> BAZ\n}" />'
|
|
|
|
assert re.search(html, content, re.M)
|