2019-06-02 11:32:01 -05:00
|
|
|
"""
|
|
|
|
test_ext_autodoc_events
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test the autodoc extension. This tests mainly for autodoc events
|
|
|
|
|
2019-12-31 23:27:43 -06:00
|
|
|
:copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
|
2019-06-02 11:32:01 -05:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from sphinx.ext.autodoc import between, cut_lines
|
2020-05-05 23:46:45 -05:00
|
|
|
from test_ext_autodoc import do_autodoc
|
2019-06-02 11:32:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_process_docstring(app):
|
|
|
|
def on_process_docstring(app, what, name, obj, options, lines):
|
|
|
|
lines.clear()
|
|
|
|
lines.append('my docstring')
|
|
|
|
|
|
|
|
app.connect('autodoc-process-docstring', on_process_docstring)
|
|
|
|
|
|
|
|
actual = do_autodoc(app, 'function', 'target.process_docstring.func')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:function:: func()',
|
|
|
|
' :module: target.process_docstring',
|
|
|
|
'',
|
2020-09-12 02:04:41 -05:00
|
|
|
' my docstring',
|
|
|
|
'',
|
2019-06-02 11:32:01 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_cut_lines(app):
|
|
|
|
app.connect('autodoc-process-docstring',
|
|
|
|
cut_lines(2, 2, ['function']))
|
|
|
|
|
|
|
|
actual = do_autodoc(app, 'function', 'target.process_docstring.func')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:function:: func()',
|
|
|
|
' :module: target.process_docstring',
|
|
|
|
'',
|
|
|
|
' second line',
|
2020-03-08 00:31:14 -06:00
|
|
|
'',
|
2019-06-02 11:32:01 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_between(app):
|
|
|
|
app.connect('autodoc-process-docstring',
|
|
|
|
between('---', ['function']))
|
|
|
|
|
|
|
|
actual = do_autodoc(app, 'function', 'target.process_docstring.func')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:function:: func()',
|
|
|
|
' :module: target.process_docstring',
|
|
|
|
'',
|
|
|
|
' second line',
|
2020-03-08 00:31:14 -06:00
|
|
|
'',
|
2019-06-02 11:32:01 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_between_exclude(app):
|
|
|
|
app.connect('autodoc-process-docstring',
|
|
|
|
between('---', ['function'], exclude=True))
|
|
|
|
|
|
|
|
actual = do_autodoc(app, 'function', 'target.process_docstring.func')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:function:: func()',
|
|
|
|
' :module: target.process_docstring',
|
|
|
|
'',
|
|
|
|
' first line',
|
|
|
|
' third line',
|
2020-03-08 00:31:14 -06:00
|
|
|
'',
|
2019-06-02 11:32:01 -05:00
|
|
|
]
|