2016-02-14 00:06:28 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
test_ext_inheritance_diagram
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test sphinx.ext.inheritance_diagram extension.
|
|
|
|
|
|
|
|
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
|
|
|
|
2016-11-22 22:38:20 -06:00
|
|
|
import re
|
2016-11-21 09:00:50 -06:00
|
|
|
import sys
|
|
|
|
from util import with_app, rootdir, raises
|
|
|
|
from sphinx.ext.inheritance_diagram import InheritanceException, import_classes
|
2017-01-03 07:24:00 -06:00
|
|
|
import pytest
|
2016-02-14 00:06:28 -06:00
|
|
|
|
|
|
|
|
|
|
|
@with_app('html', testroot='ext-inheritance_diagram')
|
2017-01-03 07:24:00 -06:00
|
|
|
@pytest.mark.usefixtures('if_graphviz_found')
|
2016-02-14 00:06:28 -06:00
|
|
|
def test_inheritance_diagram_html(app, status, warning):
|
|
|
|
app.builder.build_all()
|
2016-03-10 22:20:05 -06:00
|
|
|
|
|
|
|
content = (app.outdir / 'index.html').text()
|
|
|
|
|
|
|
|
pattern = ('<div class="figure" id="id1">\n'
|
|
|
|
'<img src="_images/inheritance-\w+.png" alt="Inheritance diagram of test.Foo" '
|
|
|
|
'class="inheritance"/>\n<p class="caption"><span class="caption-text">'
|
|
|
|
'Test Foo!</span><a class="headerlink" href="#id1" '
|
|
|
|
'title="Permalink to this image">\xb6</a></p>')
|
|
|
|
assert re.search(pattern, content, re.M)
|
|
|
|
|
|
|
|
|
|
|
|
@with_app('latex', testroot='ext-inheritance_diagram')
|
2017-01-03 07:24:00 -06:00
|
|
|
@pytest.mark.usefixtures('if_graphviz_found')
|
2016-03-10 22:20:05 -06:00
|
|
|
def test_inheritance_diagram_latex(app, status, warning):
|
|
|
|
app.builder.build_all()
|
|
|
|
|
|
|
|
content = (app.outdir / 'Python.tex').text()
|
|
|
|
|
|
|
|
pattern = ('\\\\begin{figure}\\[htbp]\n\\\\centering\n\\\\capstart\n\n'
|
|
|
|
'\\\\includegraphics{inheritance-\\w+.pdf}\n'
|
2016-12-08 15:14:48 -06:00
|
|
|
'\\\\caption{Test Foo!}\\\\label{\\\\detokenize{index:id1}}\\\\end{figure}')
|
2016-03-10 22:20:05 -06:00
|
|
|
assert re.search(pattern, content, re.M)
|
2016-11-22 22:22:38 -06:00
|
|
|
|
2016-11-21 09:00:50 -06:00
|
|
|
|
|
|
|
def test_import_classes():
|
|
|
|
from sphinx.application import Sphinx, TemplateBridge
|
2016-11-22 01:32:03 -06:00
|
|
|
from sphinx.util.i18n import CatalogInfo
|
2016-11-21 09:00:50 -06:00
|
|
|
|
|
|
|
try:
|
|
|
|
sys.path.append(rootdir / 'roots/test-ext-inheritance_diagram')
|
2016-11-22 01:32:03 -06:00
|
|
|
from example.sphinx import DummyClass
|
2016-11-21 09:00:50 -06:00
|
|
|
|
|
|
|
# got exception for unknown class or module
|
|
|
|
raises(InheritanceException, import_classes, 'unknown', None)
|
|
|
|
raises(InheritanceException, import_classes, 'unknown.Unknown', None)
|
|
|
|
|
|
|
|
# a module having no classes
|
|
|
|
classes = import_classes('sphinx', None)
|
|
|
|
assert classes == []
|
|
|
|
|
|
|
|
classes = import_classes('sphinx', 'foo')
|
|
|
|
assert classes == []
|
|
|
|
|
|
|
|
# all of classes in the module
|
|
|
|
classes = import_classes('sphinx.application', None)
|
|
|
|
assert set(classes) == set([Sphinx, TemplateBridge])
|
|
|
|
|
|
|
|
# specified class in the module
|
|
|
|
classes = import_classes('sphinx.application.Sphinx', None)
|
|
|
|
assert classes == [Sphinx]
|
|
|
|
|
|
|
|
# specified class in current module
|
|
|
|
classes = import_classes('Sphinx', 'sphinx.application')
|
|
|
|
assert classes == [Sphinx]
|
|
|
|
|
2016-11-22 01:32:03 -06:00
|
|
|
# relative module name to current module
|
|
|
|
classes = import_classes('i18n.CatalogInfo', 'sphinx.util')
|
|
|
|
assert classes == [CatalogInfo]
|
2016-11-21 09:00:50 -06:00
|
|
|
|
|
|
|
# got exception for functions
|
|
|
|
raises(InheritanceException, import_classes, 'encode_uri', 'sphinx.util')
|
|
|
|
|
2016-11-22 01:32:03 -06:00
|
|
|
# import submodule on current module (refs: #3164)
|
2016-11-21 09:00:50 -06:00
|
|
|
classes = import_classes('sphinx', 'example')
|
2016-11-22 01:32:03 -06:00
|
|
|
assert classes == [DummyClass]
|
2016-11-21 09:00:50 -06:00
|
|
|
finally:
|
|
|
|
sys.path.pop()
|