2014-11-06 02:11:20 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
test_apidoc
|
|
|
|
~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test the sphinx.apidoc module.
|
|
|
|
|
2017-03-22 06:21:12 -05:00
|
|
|
:copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
|
2014-11-06 02:11:20 -06:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
from collections import namedtuple
|
2014-11-06 02:11:20 -06:00
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
import pytest
|
2014-11-06 02:11:20 -06:00
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
from sphinx.apidoc import main as apidoc_main
|
2014-11-06 02:11:20 -06:00
|
|
|
|
2017-05-07 02:46:44 -05:00
|
|
|
from sphinx.testing.util import remove_unicode_literals
|
2014-11-06 02:11:20 -06:00
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
|
|
|
|
@pytest.fixture()
|
2017-05-07 02:46:44 -05:00
|
|
|
def apidoc(rootdir, tempdir, apidoc_params):
|
2017-01-03 07:24:00 -06:00
|
|
|
_, kwargs = apidoc_params
|
2017-05-07 02:46:44 -05:00
|
|
|
coderoot = rootdir / kwargs.get('coderoot', 'test-root')
|
2014-11-06 02:11:20 -06:00
|
|
|
outdir = tempdir / 'out'
|
2017-04-25 13:05:28 -05:00
|
|
|
args = ['-o', outdir, '-F', coderoot] + kwargs.get('options', [])
|
2017-01-03 07:24:00 -06:00
|
|
|
apidoc_main(args)
|
|
|
|
return namedtuple('apidoc', 'coderoot,outdir')(coderoot, outdir)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def apidoc_params(request):
|
|
|
|
markers = request.node.get_marker("apidoc")
|
|
|
|
pargs = {}
|
|
|
|
kwargs = {}
|
|
|
|
|
|
|
|
if markers is not None:
|
|
|
|
for info in reversed(list(markers)):
|
|
|
|
for i, a in enumerate(info.args):
|
|
|
|
pargs[i] = a
|
|
|
|
kwargs.update(info.kwargs)
|
2014-11-06 02:11:20 -06:00
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
args = [pargs[i] for i in sorted(pargs.keys())]
|
|
|
|
return args, kwargs
|
|
|
|
|
|
|
|
|
2017-05-07 02:46:44 -05:00
|
|
|
@pytest.mark.apidoc(coderoot='test-root')
|
2017-01-03 07:24:00 -06:00
|
|
|
def test_simple(make_app, apidoc):
|
|
|
|
outdir = apidoc.outdir
|
2014-11-06 02:11:20 -06:00
|
|
|
assert (outdir / 'conf.py').isfile()
|
|
|
|
assert (outdir / 'autodoc_fodder.rst').isfile()
|
|
|
|
assert (outdir / 'index.rst').isfile()
|
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
app = make_app('text', srcdir=outdir)
|
|
|
|
app.build()
|
|
|
|
print(app._status.getvalue())
|
|
|
|
print(app._warning.getvalue())
|
2015-12-25 00:52:51 -06:00
|
|
|
|
2016-09-12 17:17:03 -05:00
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
@pytest.mark.apidoc(
|
2017-07-29 00:59:51 -05:00
|
|
|
coderoot='test-apidoc-pep420/a',
|
2017-01-03 07:24:00 -06:00
|
|
|
options=["--implicit-namespaces"],
|
|
|
|
)
|
|
|
|
def test_pep_0420_enabled(make_app, apidoc):
|
|
|
|
outdir = apidoc.outdir
|
2016-09-12 17:17:03 -05:00
|
|
|
assert (outdir / 'conf.py').isfile()
|
|
|
|
assert (outdir / 'a.b.c.rst').isfile()
|
|
|
|
assert (outdir / 'a.b.x.rst').isfile()
|
|
|
|
|
|
|
|
with open(outdir / 'a.b.c.rst') as f:
|
|
|
|
rst = f.read()
|
|
|
|
assert "automodule:: a.b.c.d\n" in rst
|
|
|
|
assert "automodule:: a.b.c\n" in rst
|
|
|
|
|
|
|
|
with open(outdir / 'a.b.x.rst') as f:
|
|
|
|
rst = f.read()
|
|
|
|
assert "automodule:: a.b.x.y\n" in rst
|
|
|
|
assert "automodule:: a.b.x\n" not in rst
|
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
app = make_app('text', srcdir=outdir)
|
|
|
|
app.build()
|
|
|
|
print(app._status.getvalue())
|
|
|
|
print(app._warning.getvalue())
|
2016-09-12 17:17:03 -05:00
|
|
|
|
2017-03-24 04:53:01 -05:00
|
|
|
builddir = outdir / '_build' / 'text'
|
|
|
|
assert (builddir / 'a.b.c.txt').isfile()
|
|
|
|
assert (builddir / 'a.b.x.txt').isfile()
|
2016-09-12 17:17:03 -05:00
|
|
|
|
2017-03-24 04:53:01 -05:00
|
|
|
with open(builddir / 'a.b.c.txt') as f:
|
|
|
|
txt = f.read()
|
|
|
|
assert "a.b.c package\n" in txt
|
|
|
|
|
|
|
|
with open(builddir / 'a.b.x.txt') as f:
|
|
|
|
txt = f.read()
|
|
|
|
assert "a.b.x namespace\n" in txt
|
|
|
|
|
2016-09-12 17:17:03 -05:00
|
|
|
|
2017-07-29 00:59:51 -05:00
|
|
|
@pytest.mark.apidoc(coderoot='test-apidoc-pep420/a')
|
2017-01-03 07:24:00 -06:00
|
|
|
def test_pep_0420_disabled(make_app, apidoc):
|
|
|
|
outdir = apidoc.outdir
|
2016-09-12 17:17:03 -05:00
|
|
|
assert (outdir / 'conf.py').isfile()
|
|
|
|
assert not (outdir / 'a.b.c.rst').exists()
|
|
|
|
assert not (outdir / 'a.b.x.rst').exists()
|
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
app = make_app('text', srcdir=outdir)
|
|
|
|
app.build()
|
|
|
|
print(app._status.getvalue())
|
|
|
|
print(app._warning.getvalue())
|
|
|
|
|
2016-09-12 17:17:03 -05:00
|
|
|
|
2017-03-24 04:44:36 -05:00
|
|
|
@pytest.mark.apidoc(
|
2017-05-07 02:46:44 -05:00
|
|
|
coderoot='test-apidoc-pep420/a/b')
|
2017-01-03 07:24:00 -06:00
|
|
|
def test_pep_0420_disabled_top_level_verify(make_app, apidoc):
|
|
|
|
outdir = apidoc.outdir
|
2016-09-12 17:17:03 -05:00
|
|
|
assert (outdir / 'conf.py').isfile()
|
|
|
|
assert (outdir / 'c.rst').isfile()
|
|
|
|
assert not (outdir / 'x.rst').exists()
|
|
|
|
|
|
|
|
with open(outdir / 'c.rst') as f:
|
|
|
|
rst = f.read()
|
|
|
|
assert "c package\n" in rst
|
|
|
|
assert "automodule:: c.d\n" in rst
|
|
|
|
assert "automodule:: c\n" in rst
|
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
app = make_app('text', srcdir=outdir)
|
|
|
|
app.build()
|
|
|
|
print(app._status.getvalue())
|
|
|
|
print(app._warning.getvalue())
|
|
|
|
|
2017-05-09 07:57:36 -05:00
|
|
|
|
2017-03-24 04:44:36 -05:00
|
|
|
@pytest.mark.apidoc(
|
2017-05-07 02:46:44 -05:00
|
|
|
coderoot='test-apidoc-trailing-underscore')
|
2017-03-22 19:21:04 -05:00
|
|
|
def test_trailing_underscore(make_app, apidoc):
|
|
|
|
outdir = apidoc.outdir
|
|
|
|
assert (outdir / 'conf.py').isfile()
|
|
|
|
assert (outdir / 'package_.rst').isfile()
|
2017-03-24 04:53:01 -05:00
|
|
|
|
|
|
|
app = make_app('text', srcdir=outdir)
|
|
|
|
app.build()
|
|
|
|
print(app._status.getvalue())
|
|
|
|
print(app._warning.getvalue())
|
|
|
|
|
|
|
|
builddir = outdir / '_build' / 'text'
|
|
|
|
with open(builddir / 'package_.txt') as f:
|
2017-03-22 19:21:04 -05:00
|
|
|
rst = f.read()
|
2017-03-24 04:53:01 -05:00
|
|
|
assert "package_ package\n" in rst
|
|
|
|
assert "package_.module_ module\n" in rst
|
2017-01-03 07:24:00 -06:00
|
|
|
|
2017-05-09 07:57:36 -05:00
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
@pytest.mark.apidoc(
|
2017-05-07 02:46:44 -05:00
|
|
|
coderoot='test-root',
|
2017-01-03 07:24:00 -06:00
|
|
|
options=[
|
|
|
|
'--doc-project', u'プロジェクト名'.encode('utf-8'),
|
|
|
|
'--doc-author', u'著者名'.encode('utf-8'),
|
|
|
|
'--doc-version', u'バージョン'.encode('utf-8'),
|
|
|
|
'--doc-release', u'リリース'.encode('utf-8'),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_multibyte_parameters(make_app, apidoc):
|
|
|
|
outdir = apidoc.outdir
|
2015-12-25 00:52:51 -06:00
|
|
|
assert (outdir / 'conf.py').isfile()
|
|
|
|
assert (outdir / 'autodoc_fodder.rst').isfile()
|
|
|
|
assert (outdir / 'index.rst').isfile()
|
|
|
|
|
|
|
|
conf_py = (outdir / 'conf.py').text()
|
2017-01-03 07:24:00 -06:00
|
|
|
conf_py_ = remove_unicode_literals(conf_py)
|
|
|
|
assert u"project = 'プロジェクト名'" in conf_py_
|
|
|
|
assert u"author = '著者名'" in conf_py_
|
|
|
|
assert u"version = 'バージョン'" in conf_py_
|
|
|
|
assert u"release = 'リリース'" in conf_py_
|
|
|
|
|
|
|
|
app = make_app('text', srcdir=outdir)
|
|
|
|
app.build()
|
|
|
|
print(app._status.getvalue())
|
|
|
|
print(app._warning.getvalue())
|
2017-01-11 04:23:34 -06:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.apidoc(
|
2017-05-07 02:46:44 -05:00
|
|
|
coderoot='test-root',
|
2017-01-11 04:23:34 -06:00
|
|
|
options=['--ext-mathjax'],
|
|
|
|
)
|
|
|
|
def test_extension_parsed(make_app, apidoc):
|
|
|
|
outdir = apidoc.outdir
|
|
|
|
assert (outdir / 'conf.py').isfile()
|
|
|
|
|
|
|
|
with open(outdir / 'conf.py') as f:
|
|
|
|
rst = f.read()
|
|
|
|
assert "sphinx.ext.mathjax" in rst
|