Split viewcode and linkcode tests out of main test root.

This commit is contained in:
Georg Brandl 2014-09-21 17:34:16 +02:00
parent 78af37370c
commit a73ab32bc5
7 changed files with 250 additions and 95 deletions

View File

@ -5,8 +5,7 @@ import sys, os
sys.path.append(os.path.abspath('.'))
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.jsmath', 'sphinx.ext.todo',
'sphinx.ext.coverage', 'sphinx.ext.doctest', 'sphinx.ext.extlinks',
'sphinx.ext.viewcode', 'ext']
'sphinx.ext.coverage', 'sphinx.ext.extlinks', 'ext']
jsmath_path = 'dummy.js'
@ -43,15 +42,15 @@ html_context = {'hckey': 'hcval', 'hckey_co': 'wrong_hcval_co'}
htmlhelp_basename = 'SphinxTestsdoc'
latex_documents = [
('contents', 'SphinxTests.tex', 'Sphinx Tests Documentation',
'Georg Brandl \\and someone else', 'manual'),
('contents', 'SphinxTests.tex', 'Sphinx Tests Documentation',
'Georg Brandl \\and someone else', 'manual'),
]
latex_additional_files = ['svgimg.svg']
texinfo_documents = [
('contents', 'SphinxTests', 'Sphinx Tests',
'Georg Brandl \\and someone else', 'Sphinx Testing', 'Miscellaneous'),
('contents', 'SphinxTests', 'Sphinx Tests',
'Georg Brandl \\and someone else', 'Sphinx Testing', 'Miscellaneous'),
]
man_pages = [
@ -77,35 +76,13 @@ autodoc_mock_imports = [
# 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
from docutils import nodes
from sphinx import addnodes
from sphinx.util.compat import Directive
def userdesc_parse(env, sig, signode):
x, y = sig.split(':')
signode += addnodes.desc_name(x, x)
@ -113,15 +90,19 @@ def userdesc_parse(env, sig, signode):
signode[-1] += addnodes.desc_parameter(y, y)
return x
def functional_directive(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
return [nodes.strong(text='from function: %s' % options['opt'])]
class ClassDirective(Directive):
option_spec = {'opt': lambda x: x}
def run(self):
return [nodes.strong(text='from class: %s' % self.options['opt'])]
def setup(app):
app.add_config_value('value_from_conf_py', 42, False)
app.add_directive('funcdir', functional_directive, opt=lambda x: x)

View File

@ -1,8 +1,24 @@
# -*- coding: utf-8 -*-
import sys
import os
sys.path.insert(0, os.path.abspath('.'))
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
master_doc = 'index'
# -*- coding: utf-8 -*-
import sys
import os
sys.path.insert(0, os.path.abspath('.'))
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
master_doc = 'index'
if 'test_linkcode' in tags:
extensions.remove('sphinx.ext.viewcode')
extensions.append('sphinx.ext.linkcode')
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()

View File

@ -1,29 +1,34 @@
viewcode
========
.. py:module:: spam
.. autofunction:: func1
.. autofunction:: func2
.. autofunction:: spam.mod1.func1
.. autofunction:: spam.mod2.func2
.. autofunction:: Class1
.. autofunction:: Class2
.. autofunction:: spam.mod1.Class1
.. autofunction:: spam.mod2.Class2
.. literalinclude:: spam/__init__.py
:language: python
:pyobject: func1
.. literalinclude:: spam/mod1.py
:language: python
:pyobject: func1
viewcode
========
.. py:module:: spam
.. autofunction:: func1
.. autofunction:: func2
.. autofunction:: spam.mod1.func1
.. autofunction:: spam.mod2.func2
.. autofunction:: Class1
.. autofunction:: Class2
.. autofunction:: spam.mod1.Class1
.. autofunction:: spam.mod2.Class2
.. literalinclude:: spam/__init__.py
:language: python
:pyobject: func1
.. literalinclude:: spam/mod1.py
:language: python
:pyobject: func1
.. toctree::
objects

View File

@ -0,0 +1,169 @@
Testing object descriptions
===========================
.. function:: func_without_module(a, b, *c[, d])
Does something.
.. function:: func_without_body()
.. function:: func_noindex
:noindex:
.. function:: func_with_module
:module: foolib
Referring to :func:`func with no index <func_noindex>`.
Referring to :func:`nothing <>`.
.. module:: mod
:synopsis: Module synopsis.
:platform: UNIX
.. function:: func_in_module
.. class:: Cls
.. method:: meth1
.. staticmethod:: meths
.. attribute:: attr
.. explicit class given
.. method:: Cls.meth2
.. explicit module given
.. exception:: Error(arg1, arg2)
:module: errmod
.. data:: var
.. currentmodule:: None
.. function:: func_without_module2() -> annotation
.. object:: long(parameter, \
list)
another one
.. class:: TimeInt
Has only one parameter (triggers special behavior...)
:param moo: |test|
:type moo: |test|
.. |test| replace:: Moo
.. class:: Time(hour, minute, isdst)
:param year: The year.
:type year: TimeInt
:param TimeInt minute: The minute.
:param isdst: whether it's DST
:type isdst: * some complex
* expression
:returns: a new :class:`Time` instance
:rtype: :class:`Time`
:raises ValueError: if the values are out of range
:ivar int hour: like *hour*
:ivar minute: like *minute*
:vartype minute: int
:param hour: Some parameter
:type hour: DuplicateType
:param hour: Duplicate param. Should not lead to crashes.
:type hour: DuplicateType
:param .Cls extcls: A class from another module.
C items
=======
.. c:function:: Sphinx_DoSomething()
.. c:member:: SphinxStruct.member
.. c:macro:: SPHINX_USE_PYTHON
.. c:type:: SphinxType
.. c:var:: sphinx_global
Javascript items
================
.. js:function:: foo()
.. js:data:: bar
.. documenting the method of any object
.. js:function:: bar.baz(href, callback[, errback])
:param string href: The location of the resource.
:param callback: Get's called with the data returned by the resource.
:throws InvalidHref: If the `href` is invalid.
:returns: `undefined`
.. js:attribute:: bar.spam
References
==========
Referencing :class:`mod.Cls` or :Class:`mod.Cls` should be the same.
With target: :c:func:`Sphinx_DoSomething()` (parentheses are handled),
:c:member:`SphinxStruct.member`, :c:macro:`SPHINX_USE_PYTHON`,
:c:type:`SphinxType *` (pointer is handled), :c:data:`sphinx_global`.
Without target: :c:func:`CFunction`. :c:func:`!malloc`.
:js:func:`foo()`
:js:func:`foo`
:js:data:`bar`
:js:func:`bar.baz()`
:js:func:`bar.baz`
:js:func:`~bar.baz()`
:js:attr:`bar.baz`
Others
======
.. envvar:: HOME
.. program:: python
.. cmdoption:: -c command
.. program:: perl
.. cmdoption:: -c
.. option:: +p
Link to :option:`perl +p`.
User markup
===========
.. userdesc:: myobj:parameter
Description of userdesc.
Referencing :userdescrole:`myobj`.
CPP domain
==========
.. cpp:class:: n::Array<T,d>
.. cpp:function:: T& operator[]( unsigned j )
const T& operator[]( unsigned j ) const

View File

@ -8,13 +8,9 @@
:copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from __future__ import print_function
import sys
from util import with_app
cleanup_called = 0

View File

@ -1,24 +0,0 @@
# -*- coding: utf-8 -*-
"""
test_linkcode
~~~~~~~~~~~~~
Test the sphinx.ext.linkcode extension.
:copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from util import with_app
@with_app('html', tags=['test_linkcode'])
def test_html(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

View File

@ -15,7 +15,7 @@ from util import with_app
@with_app(testroot='ext-viewcode')
def test_simple(app, status, warning):
def test_viewcode(app, status, warning):
app.builder.build_all()
warnings = re.sub(r'\\+', '/', warning.getvalue())
@ -30,3 +30,15 @@ def test_simple(app, status, warning):
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
@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