sphinx/tests/test_ext_viewcode.py
Anselm Kruis de356149cd Test for bug #2298: automodule fails to document a class attribute
This test case demonstrates a bug, where automodule:: with option
:members: fails to document a class attribute of a class, that was
imported into the documented module.

This commit extends test_ext_viewcode, instead of creating a separate
test module, because the development guide recommends it for performance
reasons.
2016-02-05 17:42:14 +01:00

51 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
"""
test_ext_viewcode
~~~~~~~~~~~~~~~~~
Test sphinx.ext.viewcode extension.
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
from util import with_app
@with_app(testroot='ext-viewcode')
def test_viewcode(app, status, warning):
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
# 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
@with_app(testroot='ext-viewcode', tags=['test_linkcode'])
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