mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add tests for between() and cut_lines() and fix them.
Also fix a bug in the application interface.
This commit is contained in:
parent
00b30f6f65
commit
03b12e5d85
@ -159,7 +159,7 @@ class Sphinx(object):
|
||||
return listener_id
|
||||
|
||||
def disconnect(self, listener_id):
|
||||
for event in self._listeners:
|
||||
for event in self._listeners.itervalues():
|
||||
event.pop(listener_id, None)
|
||||
|
||||
def emit(self, event, *args):
|
||||
|
@ -111,7 +111,13 @@ def cut_lines(pre, post=0, what=None):
|
||||
return
|
||||
del lines[:pre]
|
||||
if post:
|
||||
# remove one trailing blank line.
|
||||
if lines and not lines[-1]:
|
||||
lines.pop(-1)
|
||||
del lines[-post:]
|
||||
# make sure there is a blank line at the end
|
||||
if lines and lines[-1]:
|
||||
lines.append('')
|
||||
return process
|
||||
|
||||
def between(marker, what=None, keepempty=False):
|
||||
@ -141,6 +147,9 @@ def between(marker, what=None, keepempty=False):
|
||||
deleted += 1
|
||||
if not lines and not keepempty:
|
||||
lines[:] = orig_lines
|
||||
# make sure there is a blank line at the end
|
||||
if lines and lines[-1]:
|
||||
lines.append('')
|
||||
return process
|
||||
|
||||
|
||||
@ -340,10 +349,14 @@ class RstGenerator(object):
|
||||
if what == 'class':
|
||||
# for classes, the relevant signature is the __init__ method's
|
||||
obj = getattr(obj, '__init__', None)
|
||||
# classes without __init__ method?
|
||||
# classes without __init__ method, default __init__ or
|
||||
# __init__ written in C?
|
||||
if obj is None or obj is object.__init__ or not \
|
||||
(inspect.ismethod(obj) or inspect.isfunction(obj)):
|
||||
getargs = False
|
||||
elif inspect.isbuiltin(obj) or inspect.ismethoddescriptor(obj):
|
||||
# can never get arguments of a C function or method
|
||||
getargs = False
|
||||
if getargs:
|
||||
argspec = inspect.getargspec(obj)
|
||||
if what in ('class', 'method') and argspec[0] and \
|
||||
|
@ -14,7 +14,7 @@ from util import *
|
||||
|
||||
from docutils.statemachine import ViewList
|
||||
|
||||
from sphinx.ext.autodoc import RstGenerator
|
||||
from sphinx.ext.autodoc import RstGenerator, cut_lines, between
|
||||
|
||||
|
||||
def setup_module():
|
||||
@ -222,6 +222,30 @@ def test_get_doc():
|
||||
assert getdocl('class', 'bar', D) == ['Init docstring', '', '42']
|
||||
|
||||
|
||||
def test_docstring_processing_functions():
|
||||
lid = app.connect('autodoc-process-docstring', cut_lines(1, 1, ['function']))
|
||||
def f():
|
||||
"""
|
||||
first line
|
||||
second line
|
||||
third line
|
||||
"""
|
||||
assert list(gen.get_doc('function', 'f', f)) == ['second line', '']
|
||||
app.disconnect(lid)
|
||||
|
||||
lid = app.connect('autodoc-process-docstring', between('---', ['function']))
|
||||
def f():
|
||||
"""
|
||||
first line
|
||||
---
|
||||
second line
|
||||
---
|
||||
third line
|
||||
"""
|
||||
assert list(gen.get_doc('function', 'f', f)) == ['second line', '']
|
||||
app.disconnect(lid)
|
||||
|
||||
|
||||
def test_generate():
|
||||
def assert_warns(warn_str, *args):
|
||||
gen.generate(*args)
|
||||
@ -246,6 +270,7 @@ def test_generate():
|
||||
gen.generate(*args)
|
||||
assert len(gen.warnings) == 0, gen.warnings
|
||||
assert item in gen.result
|
||||
print '\n'.join(gen.result)
|
||||
del gen.result[:]
|
||||
|
||||
# no module found?
|
||||
@ -303,6 +328,10 @@ def test_generate():
|
||||
assert_result_contains(' :noindex:', 'module', 'test_autodoc', [], None)
|
||||
assert_result_contains(' :noindex:', 'class', 'Base', [], None)
|
||||
|
||||
# okay, now let's get serious about mixing Python and C signature stuff
|
||||
assert_result_contains('.. class:: CustomDict', 'class', 'CustomDict',
|
||||
['__all__'], None)
|
||||
|
||||
|
||||
# --- generate fodder ------------
|
||||
|
||||
@ -329,3 +358,6 @@ class Class(Base):
|
||||
@property
|
||||
def prop(self):
|
||||
"""Property."""
|
||||
|
||||
class CustomDict(dict):
|
||||
"""Docstring."""
|
||||
|
Loading…
Reference in New Issue
Block a user