summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2012-03-11 17:48:51 +0100
committerPauli Virtanen <pav@iki.fi>2012-03-11 17:48:51 +0100
commite85f2467852ec4d42e4f4ed147bd64ef2907517d (patch)
tree5c2fc418a1845dd24722b1e5917a35b45ea52bb0 /tests
parent3137157ebafefaedad02cfc780957b3adb59e826 (diff)
downloadsphinx-e85f2467852ec4d42e4f4ed147bd64ef2907517d.tar.gz
ENH: add a linkcode extension
Diffstat (limited to 'tests')
-rw-r--r--tests/root/conf.py22
-rw-r--r--tests/test_linkcode.py28
2 files changed, 50 insertions, 0 deletions
diff --git a/tests/root/conf.py b/tests/root/conf.py
index b97ddfcc..37d5e91a 100644
--- a/tests/root/conf.py
+++ b/tests/root/conf.py
@@ -67,6 +67,28 @@ extlinks = {'issue': ('http://bugs.python.org/issue%s', 'issue '),
# modify tags from conf.py
tags.add('confpytag')
+# -- linkcode
+
+if 'test_linkcode' in tags:
+ import glob
+
+ extensions.remove('sphinx.ext.viewcode')
+ extensions.append('sphinx.ext.linkcode')
+
+ exclude_patterns.extend(glob.glob('*.txt') + glob.glob('*/*.txt'))
+ exclude_patterns.remove('contents.txt')
+ exclude_patterns.remove('objects.txt')
+
+ def linkcode_resolve(domain, info):
+ if domain == 'py':
+ fn = info['module'].replace('.', '/')
+ return "http://foobar/source/%s.py" % fn
+ elif domain == "js":
+ return "http://foobar/js/" + info['fullname']
+ elif domain in ("c", "cpp"):
+ return "http://foobar/%s/%s" % (domain, "".join(info['names']))
+ else:
+ raise AssertionError()
# -- extension API
diff --git a/tests/test_linkcode.py b/tests/test_linkcode.py
new file mode 100644
index 00000000..b4b33332
--- /dev/null
+++ b/tests/test_linkcode.py
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+"""
+ test_linkcode
+ ~~~~~~~~~~~~~
+
+ Test the sphinx.ext.linkcode extension.
+
+ :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+import os
+from util import *
+
+@with_app(srcdir='(temp)', buildername='html', tags=['test_linkcode'])
+def test_html(app):
+ app.builder.build_all()
+
+ fp = open(os.path.join(app.outdir, 'objects.html'), 'rb')
+ try:
+ stuff = fp.read()
+ finally:
+ fp.close()
+
+ 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