2014-09-21 10:17:02 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
test_ext_viewcode
|
|
|
|
~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test sphinx.ext.viewcode extension.
|
|
|
|
|
2017-12-31 10:06:58 -06:00
|
|
|
:copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS.
|
2014-09-21 10:17:02 -05:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
import pytest
|
2014-09-21 10:17:02 -05:00
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx(testroot='ext-viewcode')
|
2014-09-21 10:34:16 -05:00
|
|
|
def test_viewcode(app, status, warning):
|
2014-09-21 10:17:02 -05:00
|
|
|
app.builder.build_all()
|
|
|
|
|
|
|
|
warnings = re.sub(r'\\+', '/', warning.getvalue())
|
|
|
|
assert re.findall(
|
|
|
|
r"index.rst:\d+: WARNING: Object named 'func1' not found in include " +
|
|
|
|
r"file .*/spam/__init__.py'",
|
|
|
|
warnings
|
|
|
|
)
|
|
|
|
|
|
|
|
result = (app.outdir / 'index.html').text(encoding='utf-8')
|
|
|
|
assert result.count('href="_modules/spam/mod1.html#func1"') == 2
|
|
|
|
assert result.count('href="_modules/spam/mod2.html#func2"') == 2
|
|
|
|
assert result.count('href="_modules/spam/mod1.html#Class1"') == 2
|
|
|
|
assert result.count('href="_modules/spam/mod2.html#Class2"') == 2
|
2017-03-11 15:16:23 -06:00
|
|
|
assert result.count('@decorator') == 1
|
2014-09-21 10:34:16 -05:00
|
|
|
|
2016-02-05 10:15:27 -06:00
|
|
|
# test that the class attribute is correctly documented
|
|
|
|
assert result.count('this is Class3') == 2
|
|
|
|
assert 'this is the class attribute class_attr' in result
|
|
|
|
# the next assert fails, until the autodoc bug gets fixed
|
|
|
|
assert result.count('this is the class attribute class_attr') == 2
|
|
|
|
|
2014-09-21 10:34:16 -05:00
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx(testroot='ext-viewcode', tags=['test_linkcode'])
|
2014-09-21 10:34:16 -05:00
|
|
|
def test_linkcode(app, status, warning):
|
|
|
|
app.builder.build(['objects'])
|
|
|
|
|
|
|
|
stuff = (app.outdir / 'objects.html').text(encoding='utf-8')
|
|
|
|
|
|
|
|
assert 'http://foobar/source/foolib.py' in stuff
|
|
|
|
assert 'http://foobar/js/' in stuff
|
|
|
|
assert 'http://foobar/c/' in stuff
|
|
|
|
assert 'http://foobar/cpp/' in stuff
|