summaryrefslogtreecommitdiff
path: root/tests/test_autodoc.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_autodoc.py')
-rw-r--r--tests/test_autodoc.py98
1 files changed, 71 insertions, 27 deletions
diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py
index ed906d1c..0025170f 100644
--- a/tests/test_autodoc.py
+++ b/tests/test_autodoc.py
@@ -10,17 +10,15 @@
:license: BSD, see LICENSE for details.
"""
-import sys
-from StringIO import StringIO
-
# "raises" imported for usage by autodoc
from util import TestApp, Struct, raises
from nose.tools import with_setup
+from six import StringIO
from docutils.statemachine import ViewList
from sphinx.ext.autodoc import AutoDirective, add_documenter, \
- ModuleLevelDocumenter, FunctionDocumenter, cut_lines, between, ALL
+ ModuleLevelDocumenter, FunctionDocumenter, cut_lines, between, ALL
app = None
@@ -125,24 +123,24 @@ def test_parse_name():
directive.env.temp_data['autodoc:module'] = 'util'
verify('function', 'raises', ('util', ['raises'], None, None))
del directive.env.temp_data['autodoc:module']
- directive.env.temp_data['py:module'] = 'util'
+ directive.env.ref_context['py:module'] = 'util'
verify('function', 'raises', ('util', ['raises'], None, None))
verify('class', 'TestApp', ('util', ['TestApp'], None, None))
# for members
- directive.env.temp_data['py:module'] = 'foo'
+ directive.env.ref_context['py:module'] = 'foo'
verify('method', 'util.TestApp.cleanup',
('util', ['TestApp', 'cleanup'], None, None))
- directive.env.temp_data['py:module'] = 'util'
- directive.env.temp_data['py:class'] = 'Foo'
+ directive.env.ref_context['py:module'] = 'util'
+ directive.env.ref_context['py:class'] = 'Foo'
directive.env.temp_data['autodoc:class'] = 'TestApp'
verify('method', 'cleanup', ('util', ['TestApp', 'cleanup'], None, None))
verify('method', 'TestApp.cleanup',
('util', ['TestApp', 'cleanup'], None, None))
# and clean up
- del directive.env.temp_data['py:module']
- del directive.env.temp_data['py:class']
+ del directive.env.ref_context['py:module']
+ del directive.env.ref_context['py:class']
del directive.env.temp_data['autodoc:class']
@@ -157,7 +155,7 @@ def test_format_signature():
inst.args = args
inst.retann = retann
res = inst.format_signature()
- print res
+ print(res)
return res
# no signatures for modules
@@ -257,7 +255,7 @@ def test_get_doc():
ds = inst.get_doc(encoding)
# for testing purposes, concat them and strip the empty line at the end
res = sum(ds, [])[:-1]
- print res
+ print(res)
return res
# objects without docstring
@@ -436,6 +434,43 @@ def test_docstring_processing():
@with_setup(setup_test)
+def test_docstring_property_processing():
+ def genarate_docstring(objtype, name, **kw):
+ del processed_docstrings[:]
+ del processed_signatures[:]
+ inst = AutoDirective._registry[objtype](directive, name)
+ inst.generate(**kw)
+ results = list(directive.result)
+ docstrings = inst.get_doc()[0]
+ del directive.result[:]
+ return results, docstrings
+
+ directive.env.config.autodoc_docstring_signature = False
+ results, docstrings = \
+ genarate_docstring('attribute', 'test_autodoc.DocstringSig.prop1')
+ assert '.. py:attribute:: DocstringSig.prop1' in results
+ assert 'First line of docstring' in docstrings
+ assert 'DocstringSig.prop1(self)' in docstrings
+ results, docstrings = \
+ genarate_docstring('attribute', 'test_autodoc.DocstringSig.prop2')
+ assert '.. py:attribute:: DocstringSig.prop2' in results
+ assert 'First line of docstring' in docstrings
+ assert 'Second line of docstring' in docstrings
+
+ directive.env.config.autodoc_docstring_signature = True
+ results, docstrings = \
+ genarate_docstring('attribute', 'test_autodoc.DocstringSig.prop1')
+ assert '.. py:attribute:: DocstringSig.prop1' in results
+ assert 'First line of docstring' in docstrings
+ assert 'DocstringSig.prop1(self)' not in docstrings
+ results, docstrings = \
+ genarate_docstring('attribute', 'test_autodoc.DocstringSig.prop2')
+ assert '.. py:attribute:: DocstringSig.prop2' in results
+ assert 'First line of docstring' in docstrings
+ assert 'Second line of docstring' in docstrings
+
+
+@with_setup(setup_test)
def test_new_documenter():
class MyDocumenter(ModuleLevelDocumenter):
objtype = 'integer'
@@ -565,7 +600,7 @@ def test_generate():
'method', 'test_autodoc.Class.foobar', more_content=None)
# test auto and given content mixing
- directive.env.temp_data['py:module'] = 'test_autodoc'
+ directive.env.ref_context['py:module'] = 'test_autodoc'
assert_result_contains(' Function.', 'method', 'Class.meth')
add_content = ViewList()
add_content.append('Content.', '', 0)
@@ -663,12 +698,12 @@ def test_generate():
'attribute', 'test_autodoc.Class.descr')
# test generation for C modules (which have no source file)
- directive.env.temp_data['py:module'] = 'time'
+ directive.env.ref_context['py:module'] = 'time'
assert_processes([('function', 'time.asctime')], 'function', 'asctime')
assert_processes([('function', 'time.asctime')], 'function', 'asctime')
# test autodoc_member_order == 'source'
- directive.env.temp_data['py:module'] = 'test_autodoc'
+ directive.env.ref_context['py:module'] = 'test_autodoc'
assert_order(['.. py:class:: Class(arg)',
' .. py:attribute:: Class.descr',
' .. py:method:: Class.meth()',
@@ -685,7 +720,7 @@ def test_generate():
' .. py:method:: Class.inheritedmeth()',
],
'class', 'Class', member_order='bysource', all_members=True)
- del directive.env.temp_data['py:module']
+ del directive.env.ref_context['py:module']
# test attribute initialized to class instance from other module
directive.env.temp_data['autodoc:class'] = 'test_autodoc.Class'
@@ -710,7 +745,7 @@ def test_generate():
'test_autodoc.Class.moore')
# test new attribute documenter behavior
- directive.env.temp_data['py:module'] = 'test_autodoc'
+ directive.env.ref_context['py:module'] = 'test_autodoc'
options.undoc_members = True
assert_processes([('class', 'test_autodoc.AttCls'),
('attribute', 'test_autodoc.AttCls.a1'),
@@ -724,7 +759,7 @@ def test_generate():
# test explicit members with instance attributes
del directive.env.temp_data['autodoc:class']
del directive.env.temp_data['autodoc:module']
- directive.env.temp_data['py:module'] = 'test_autodoc'
+ directive.env.ref_context['py:module'] = 'test_autodoc'
options.inherited_members = False
options.undoc_members = False
options.members = ALL
@@ -746,7 +781,7 @@ def test_generate():
], 'class', 'InstAttCls')
del directive.env.temp_data['autodoc:class']
del directive.env.temp_data['autodoc:module']
- del directive.env.temp_data['py:module']
+ del directive.env.ref_context['py:module']
# test descriptor class documentation
options.members = ['CustomDataDescriptor']
@@ -788,12 +823,8 @@ def _funky_classmethod(name, b, c, d, docstring=None):
some arguments."""
def template(cls, a, b, c, d=4, e=5, f=6):
return a, b, c, d, e, f
- if sys.version_info >= (2, 5):
- from functools import partial
- function = partial(template, b=b, c=c, d=d)
- else:
- def function(cls, a, e=5, f=6):
- return template(a, b, c, d, e, f)
+ from functools import partial
+ function = partial(template, b=b, c=c, d=d)
function.__name__ = name
function.__doc__ = docstring
return classmethod(function)
@@ -825,10 +856,9 @@ class Class(Base):
#: should be documented -- süß
attr = 'bar'
+ @property
def prop(self):
"""Property."""
- # stay 2.4 compatible (docstring!)
- prop = property(prop, doc="Property.")
docattr = 'baz'
"""should likewise be documented -- süß"""
@@ -898,6 +928,20 @@ First line of docstring
indented line
"""
+ @property
+ def prop1(self):
+ """DocstringSig.prop1(self)
+ First line of docstring
+ """
+ return 123
+
+ @property
+ def prop2(self):
+ """First line of docstring
+ Second line of docstring
+ """
+ return 456
+
class StrRepr(str):
def __repr__(self):
return self