summaryrefslogtreecommitdiff
path: root/tests/test_ext_viewcode.py
diff options
context:
space:
mode:
authorAshley Whetter <asw@dneg.com>2018-04-05 15:40:09 -0700
committerAshley Whetter <asw@dneg.com>2018-04-24 14:45:16 -0700
commit44da51a5641caad93200a1cec6b276d0211f4e1f (patch)
tree74197077fea744a2cbbcd39fe77a990b2be5627e /tests/test_ext_viewcode.py
parent0a0803fd450ec618f24a03cf9ef4309b9db1d36b (diff)
downloadsphinx-git-44da51a5641caad93200a1cec6b276d0211f4e1f.tar.gz
Plugins can find source code for viewcode
Fixes #4035
Diffstat (limited to 'tests/test_ext_viewcode.py')
-rw-r--r--tests/test_ext_viewcode.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test_ext_viewcode.py b/tests/test_ext_viewcode.py
index 3b7dbdafc..4676f488f 100644
--- a/tests/test_ext_viewcode.py
+++ b/tests/test_ext_viewcode.py
@@ -60,3 +60,46 @@ def test_linkcode(app, status, warning):
assert 'http://foobar/js/' in stuff
assert 'http://foobar/c/' in stuff
assert 'http://foobar/cpp/' in stuff
+
+
+@pytest.mark.sphinx(testroot='ext-viewcode-find')
+def test_local_source_files(app, status, warning):
+ def find_source(app, modname):
+ if modname == 'not_a_package':
+ source = (app.srcdir / 'not_a_package/__init__.py').text()
+ tags = {
+ 'func1': ('def', 3, 3),
+ 'Class1': ('class', 3, 3),
+ 'not_a_package.submodule.func1': ('def', 3, 3),
+ 'not_a_package.submodule.Class1': ('class', 3, 3),
+ }
+ else:
+ source = (app.srcdir / 'not_a_package/submodule.py').text()
+ tags = {
+ 'not_a_package.submodule.func1': ('def', 11, 15),
+ 'Class1': ('class', 19, 22),
+ 'not_a_package.submodule.Class1': ('class', 19, 22),
+ 'Class3': ('class', 25, 30),
+ 'not_a_package.submodule.Class3.class_attr': ('other', 29, 29),
+ }
+ return (source, tags)
+
+ app.connect('viewcode-find-source', find_source)
+ 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 .*/not_a_package/__init__.py'",
+ warnings
+ )
+
+ result = (app.outdir / 'index.html').text(encoding='utf-8')
+ assert result.count('href="_modules/not_a_package.html#func1"') == 1
+ assert result.count('href="_modules/not_a_package.html#not_a_package.submodule.func1"') == 1
+ assert result.count('href="_modules/not_a_package/submodule.html#Class1"') == 1
+ assert result.count('href="_modules/not_a_package/submodule.html#Class3"') == 1
+ assert result.count('href="_modules/not_a_package/submodule.html#not_a_package.submodule.Class1"') == 1
+
+ assert result.count('href="_modules/not_a_package/submodule.html#not_a_package.submodule.Class3.class_attr"') == 1
+ assert result.count('This is the class attribute class_attr') == 1