mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
[autosummary] tests for autosummary modules and packages
This commit is contained in:
10
tests/roots/test-ext-autosummary-package/conf.py
Normal file
10
tests/roots/test-ext-autosummary-package/conf.py
Normal file
@@ -0,0 +1,10 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
extensions = ['sphinx.ext.autosummary']
|
||||
autosummary_generate = True
|
||||
|
||||
# The suffix of source filenames.
|
||||
source_suffix = '.rst'
|
||||
9
tests/roots/test-ext-autosummary-package/index.rst
Normal file
9
tests/roots/test-ext-autosummary-package/index.rst
Normal file
@@ -0,0 +1,9 @@
|
||||
API Reference
|
||||
=============
|
||||
|
||||
.. rubric:: Packages
|
||||
|
||||
.. autosummary::
|
||||
:toctree: generated
|
||||
|
||||
package
|
||||
13
tests/roots/test-ext-autosummary-package/package/module.py
Normal file
13
tests/roots/test-ext-autosummary-package/package/module.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from os import * # NOQA
|
||||
|
||||
|
||||
class Foo:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def bar(self):
|
||||
pass
|
||||
|
||||
@property
|
||||
def baz(self):
|
||||
pass
|
||||
@@ -0,0 +1,4 @@
|
||||
import sys
|
||||
|
||||
# Fail module import in a catastrophic way
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,13 @@
|
||||
from os import * # NOQA
|
||||
|
||||
|
||||
class Foo:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def bar(self):
|
||||
pass
|
||||
|
||||
@property
|
||||
def baz(self):
|
||||
pass
|
||||
@@ -0,0 +1,4 @@
|
||||
import sys
|
||||
|
||||
# Fail module import in a catastrophic way
|
||||
sys.exit(1)
|
||||
@@ -9,6 +9,7 @@
|
||||
"""
|
||||
|
||||
from io import StringIO
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -177,7 +178,6 @@ def test_escaping(app, status, warning):
|
||||
@pytest.mark.sphinx('dummy', testroot='ext-autosummary')
|
||||
def test_autosummary_generate(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
module = (app.srcdir / 'generated' / 'autosummary_dummy_module.rst').text()
|
||||
assert (' .. autosummary::\n'
|
||||
' \n'
|
||||
@@ -197,6 +197,64 @@ def test_autosummary_generate(app, status, warning):
|
||||
' \n' in Foo)
|
||||
|
||||
|
||||
@pytest.mark.sphinx('dummy', testroot='ext-autosummary-package')
|
||||
def test_autosummary_generate_package(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
# Check generated .rst files
|
||||
root = app.srcdir / 'generated'
|
||||
n = len(root)+1
|
||||
generated = set()
|
||||
for path, subdirs, files in os.walk(str(root)):
|
||||
base = path[n:]
|
||||
for name in files:
|
||||
generated.add(os.path.join(base, name))
|
||||
for name in subdirs:
|
||||
generated.add(os.path.join(base, name))
|
||||
expected = set(['package.rst', 'modules', 'packages',
|
||||
os.path.join('modules', 'package.module.rst'),
|
||||
os.path.join('packages', 'package.subpackage.rst'),
|
||||
os.path.join('packages', 'modules'),
|
||||
os.path.join('packages', 'modules', 'package.subpackage.module.rst'),
|
||||
])
|
||||
assert generated == expected
|
||||
|
||||
content = (root / 'package.rst').text()
|
||||
assert '.. automodule:: package' in content
|
||||
assert '.. rubric:: modules' in content
|
||||
assert ('.. autosummary::\n'
|
||||
' :toctree: modules\n'
|
||||
'\n'
|
||||
' package.module\n' in content)
|
||||
assert '.. rubric:: packages' in content
|
||||
assert ('.. autosummary::\n'
|
||||
' :toctree: packages\n'
|
||||
'\n'
|
||||
' package.subpackage\n' in content)
|
||||
|
||||
content = (root / 'packages' / 'package.subpackage.rst').text()
|
||||
assert '.. automodule:: package.subpackage' in content
|
||||
assert '.. rubric:: modules' in content
|
||||
assert ('.. autosummary::\n'
|
||||
' :toctree: modules\n'
|
||||
'\n'
|
||||
' package.subpackage.module\n' in content)
|
||||
|
||||
modules = [('modules', 'package.module.rst'),
|
||||
('packages', 'modules', 'package.subpackage.module.rst')]
|
||||
for module in modules:
|
||||
path = root
|
||||
for sub in module:
|
||||
path /= sub
|
||||
content = path.text()
|
||||
assert '.. automodule:: '+module[-1][:-4] in content
|
||||
assert ' .. rubric:: Classes' in content
|
||||
assert (' .. autosummary::\n'
|
||||
' \n'
|
||||
' Foo\n'
|
||||
' \n' in content)
|
||||
|
||||
|
||||
@pytest.mark.sphinx('latex', **default_kw)
|
||||
def test_autosummary_latex_table_colspec(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
Reference in New Issue
Block a user