From 5bb0bb4be543fd5eca41673696a62ed80d493591 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 5 Jun 2024 18:20:58 +0200 Subject: Adding upstream version 7.3.7. Signed-off-by: Daniel Baumann --- tests/test_extensions/test_ext_graphviz.py | 196 +++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 tests/test_extensions/test_ext_graphviz.py (limited to 'tests/test_extensions/test_ext_graphviz.py') diff --git a/tests/test_extensions/test_ext_graphviz.py b/tests/test_extensions/test_ext_graphviz.py new file mode 100644 index 0000000..866a92a --- /dev/null +++ b/tests/test_extensions/test_ext_graphviz.py @@ -0,0 +1,196 @@ +"""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.build(force_all=True) + + content = (app.outdir / 'index.html').read_text(encoding='utf8') + html = (r'
\s*' + r'
\s*
\s*' + r'

caption of graph.*

\s*' + r'
\s*
') + assert re.search(html, content, re.DOTALL) + + html = 'Hello
\n graphviz world' + assert re.search(html, content, re.DOTALL) + + html = ('digraph foo {\nbaz -> qux\n}') + assert re.search(html, content, re.DOTALL) + + html = (r'
\s*' + r'
\s*
\s*' + r'

on right.*

\s*' + r'
\s*
') + assert re.search(html, content, re.DOTALL) + + html = (r'
' + r'
\"digraph
\n
') + assert re.search(html, content, re.DOTALL) + + +@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.build(force_all=True) + + content = (app.outdir / 'index.html').read_text(encoding='utf8') + + html = (r'
\n' + r'
\n' + r'\s*

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

\n' + r'
\n' + r'

caption of graph.*

\n' + r'
\n' + r'
') + assert re.search(html, content, re.DOTALL) + + html = (r'Hello
\n' + r'\s*

graph

\n' + r' graphviz world') + assert re.search(html, content, re.DOTALL) + + html = (r'
\n' + r'
\n' + r'\s*

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

\n' + r'
\n' + r'

on right.*

\n' + r'
\n' + r'
') + assert re.search(html, content, re.DOTALL) + + html = (r'
' + r'
\n' + r'\s*

digraph foo {\n' + r'centered\n' + r'}

\n' + r'
') + assert re.search(html, content, re.DOTALL) + + image_re = r'.*data="([^"]+)".*?digraph test' + image_path_match = re.search(image_re, content, re.DOTALL) + 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="https://www.google.com/"];\n' + ' foo -> bar;\n' + '}\n') + content = ('\n' + '\n' + '') + cmap = ClickableMapDefinition('dummy.map', content, code) + assert cmap.filename == 'dummy.map' + assert cmap.id == 'grapvizff087ab863' + assert len(cmap.clickable) == 1 + assert cmap.generate_clickable_map() == content.replace('%3', cmap.id) + + # inheritance-diagram:: sphinx.builders.html + content = ( + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '' + ) + 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() == '' -- cgit v1.2.3