sphinx/tests/test_ext_graphviz.py

66 lines
2.2 KiB
Python
Raw Normal View History

2015-06-26 07:23:03 -05:00
# -*- coding: utf-8 -*-
"""
test_ext_graphviz
~~~~~~~~~~~~~~~~~
Test sphinx.ext.graphviz extension.
2017-03-22 06:21:12 -05:00
:copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
2015-06-26 07:23:03 -05:00
:license: BSD, see LICENSE for details.
"""
import re
2017-01-03 07:24:00 -06:00
import pytest
@pytest.mark.sphinx('html', testroot='ext-graphviz')
2017-01-03 07:24:00 -06:00
@pytest.mark.usefixtures('if_graphviz_found')
def test_graphviz_html(app, status, warning):
2015-06-26 07:23:03 -05:00
app.builder.build_all()
content = (app.outdir / 'index.html').text()
2017-02-12 11:02:51 -06:00
html = (r'<div class="figure" .*?>\s*<img .*?/>\s*<p class="caption">'
r'<span class="caption-text">caption of graph</span>.*</p>\s*</div>')
assert re.search(html, content, re.S)
html = 'Hello <img .*?/>\n graphviz world'
assert re.search(html, content, re.S)
html = '<img src=".*?" alt="digraph {\n bar -&gt; baz\n}" />'
assert re.search(html, content, re.M)
2017-02-12 11:02:51 -06:00
html = (r'<div class="figure align-right" .*?>\s*<img .*?/>\s*<p class="caption">'
r'<span class="caption-text">on right</span>.*</p>\s*</div>')
assert re.search(html, content, re.S)
@pytest.mark.sphinx('latex', testroot='ext-graphviz')
2017-01-03 07:24:00 -06:00
@pytest.mark.usefixtures('if_graphviz_found')
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'
'\\\\includegraphics{graphviz-\\w+.pdf}\n'
'\\\\caption{caption of graph}\\\\label{.*}\\\\end{figure}')
assert re.search(macro, content, re.S)
2017-02-12 11:02:51 -06:00
macro = 'Hello \\\\includegraphics{graphviz-\\w+.pdf} graphviz world'
assert re.search(macro, content, re.S)
macro = ('\\\\begin{wrapfigure}{r}{0pt}\n\\\\centering\n'
2017-02-12 11:02:51 -06:00
'\\\\includegraphics{graphviz-\\w+.pdf}\n'
'\\\\caption{on right}\\\\label{.*}\\\\end{wrapfigure}')
assert re.search(macro, content, re.S)
@pytest.mark.sphinx('html', testroot='ext-graphviz', confoverrides={'language': 'xx'})
2017-01-03 07:24:00 -06:00
@pytest.mark.usefixtures('if_graphviz_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 -&gt; BAZ\n}" />'
assert re.search(html, content, re.M)