mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
test: Move descriptor example to independent file
This commit is contained in:
parent
ef4ad32025
commit
6cbee7de3c
@ -22,31 +22,6 @@ class CustomEx(Exception):
|
|||||||
"""Exception method."""
|
"""Exception method."""
|
||||||
|
|
||||||
|
|
||||||
class CustomDataDescriptor(object):
|
|
||||||
"""Descriptor class docstring."""
|
|
||||||
|
|
||||||
def __init__(self, doc):
|
|
||||||
self.__doc__ = doc
|
|
||||||
|
|
||||||
def __get__(self, obj, type=None):
|
|
||||||
if obj is None:
|
|
||||||
return self
|
|
||||||
return 42
|
|
||||||
|
|
||||||
def meth(self):
|
|
||||||
"""Function."""
|
|
||||||
return "The Answer"
|
|
||||||
|
|
||||||
|
|
||||||
class CustomDataDescriptorMeta(type):
|
|
||||||
"""Descriptor metaclass docstring."""
|
|
||||||
|
|
||||||
|
|
||||||
class CustomDataDescriptor2(CustomDataDescriptor):
|
|
||||||
"""Descriptor class with custom metaclass docstring."""
|
|
||||||
__metaclass__ = CustomDataDescriptorMeta
|
|
||||||
|
|
||||||
|
|
||||||
def _funky_classmethod(name, b, c, d, docstring=None):
|
def _funky_classmethod(name, b, c, d, docstring=None):
|
||||||
"""Generates a classmethod for a class from a template by filling out
|
"""Generates a classmethod for a class from a template by filling out
|
||||||
some arguments."""
|
some arguments."""
|
||||||
@ -81,8 +56,6 @@ class Derived(Base):
|
|||||||
class Class(Base):
|
class Class(Base):
|
||||||
"""Class to document."""
|
"""Class to document."""
|
||||||
|
|
||||||
descr = CustomDataDescriptor("Descriptor instance docstring.")
|
|
||||||
|
|
||||||
def meth(self):
|
def meth(self):
|
||||||
"""Function."""
|
"""Function."""
|
||||||
|
|
||||||
@ -101,10 +74,6 @@ class Class(Base):
|
|||||||
#: should be documented -- süß
|
#: should be documented -- süß
|
||||||
attr = 'bar'
|
attr = 'bar'
|
||||||
|
|
||||||
@property
|
|
||||||
def prop(self):
|
|
||||||
"""Property."""
|
|
||||||
|
|
||||||
docattr = 'baz'
|
docattr = 'baz'
|
||||||
"""should likewise be documented -- süß"""
|
"""should likewise be documented -- süß"""
|
||||||
|
|
||||||
|
31
tests/roots/test-ext-autodoc/target/descriptor.py
Normal file
31
tests/roots/test-ext-autodoc/target/descriptor.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
class CustomDataDescriptor(object):
|
||||||
|
"""Descriptor class docstring."""
|
||||||
|
|
||||||
|
def __init__(self, doc):
|
||||||
|
self.__doc__ = doc
|
||||||
|
|
||||||
|
def __get__(self, obj, type=None):
|
||||||
|
if obj is None:
|
||||||
|
return self
|
||||||
|
return 42
|
||||||
|
|
||||||
|
def meth(self):
|
||||||
|
"""Function."""
|
||||||
|
return "The Answer"
|
||||||
|
|
||||||
|
|
||||||
|
class CustomDataDescriptorMeta(type):
|
||||||
|
"""Descriptor metaclass docstring."""
|
||||||
|
|
||||||
|
|
||||||
|
class CustomDataDescriptor2(CustomDataDescriptor):
|
||||||
|
"""Descriptor class with custom metaclass docstring."""
|
||||||
|
__metaclass__ = CustomDataDescriptorMeta
|
||||||
|
|
||||||
|
|
||||||
|
class Class:
|
||||||
|
descr = CustomDataDescriptor("Descriptor instance docstring.")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def prop(self):
|
||||||
|
"""Property."""
|
@ -752,7 +752,6 @@ def test_autodoc_undoc_members(app):
|
|||||||
assert list(filter(lambda l: '::' in l, actual)) == [
|
assert list(filter(lambda l: '::' in l, actual)) == [
|
||||||
'.. py:class:: Class(arg)',
|
'.. py:class:: Class(arg)',
|
||||||
' .. py:attribute:: Class.attr',
|
' .. py:attribute:: Class.attr',
|
||||||
' .. py:attribute:: Class.descr',
|
|
||||||
' .. py:attribute:: Class.docattr',
|
' .. py:attribute:: Class.docattr',
|
||||||
' .. py:method:: Class.excludemeth()',
|
' .. py:method:: Class.excludemeth()',
|
||||||
' .. py:attribute:: Class.inst_attr_comment',
|
' .. py:attribute:: Class.inst_attr_comment',
|
||||||
@ -761,7 +760,6 @@ def test_autodoc_undoc_members(app):
|
|||||||
' .. py:attribute:: Class.mdocattr',
|
' .. py:attribute:: Class.mdocattr',
|
||||||
' .. py:method:: Class.meth()',
|
' .. py:method:: Class.meth()',
|
||||||
' .. py:method:: Class.moore(a, e, f) -> happiness',
|
' .. py:method:: Class.moore(a, e, f) -> happiness',
|
||||||
' .. py:method:: Class.prop',
|
|
||||||
' .. py:method:: Class.roger(a, *, b=2, c=3, d=4, e=5, f=6)',
|
' .. py:method:: Class.roger(a, *, b=2, c=3, d=4, e=5, f=6)',
|
||||||
' .. py:attribute:: Class.skipattr',
|
' .. py:attribute:: Class.skipattr',
|
||||||
' .. py:method:: Class.skipmeth()',
|
' .. py:method:: Class.skipmeth()',
|
||||||
@ -782,7 +780,6 @@ def test_autodoc_inherited_members(app):
|
|||||||
' .. py:method:: Class.inheritedstaticmeth(cls)',
|
' .. py:method:: Class.inheritedstaticmeth(cls)',
|
||||||
' .. py:method:: Class.meth()',
|
' .. py:method:: Class.meth()',
|
||||||
' .. py:method:: Class.moore(a, e, f) -> happiness',
|
' .. py:method:: Class.moore(a, e, f) -> happiness',
|
||||||
' .. py:method:: Class.prop',
|
|
||||||
' .. py:method:: Class.skipmeth()'
|
' .. py:method:: Class.skipmeth()'
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -833,7 +830,6 @@ def test_autodoc_special_members(app):
|
|||||||
' .. py:method:: Class.__special1__()',
|
' .. py:method:: Class.__special1__()',
|
||||||
' .. py:method:: Class.__special2__()',
|
' .. py:method:: Class.__special2__()',
|
||||||
' .. py:attribute:: Class.attr',
|
' .. py:attribute:: Class.attr',
|
||||||
' .. py:attribute:: Class.descr',
|
|
||||||
' .. py:attribute:: Class.docattr',
|
' .. py:attribute:: Class.docattr',
|
||||||
' .. py:method:: Class.excludemeth()',
|
' .. py:method:: Class.excludemeth()',
|
||||||
' .. py:attribute:: Class.inst_attr_comment',
|
' .. py:attribute:: Class.inst_attr_comment',
|
||||||
@ -842,7 +838,6 @@ def test_autodoc_special_members(app):
|
|||||||
' .. py:attribute:: Class.mdocattr',
|
' .. py:attribute:: Class.mdocattr',
|
||||||
' .. py:method:: Class.meth()',
|
' .. py:method:: Class.meth()',
|
||||||
' .. py:method:: Class.moore(a, e, f) -> happiness',
|
' .. py:method:: Class.moore(a, e, f) -> happiness',
|
||||||
' .. py:method:: Class.prop',
|
|
||||||
' .. py:method:: Class.roger(a, *, b=2, c=3, d=4, e=5, f=6)',
|
' .. py:method:: Class.roger(a, *, b=2, c=3, d=4, e=5, f=6)',
|
||||||
' .. py:attribute:: Class.skipattr',
|
' .. py:attribute:: Class.skipattr',
|
||||||
' .. py:method:: Class.skipmeth()',
|
' .. py:method:: Class.skipmeth()',
|
||||||
@ -866,9 +861,6 @@ def test_autodoc_ignore_module_all(app):
|
|||||||
actual = do_autodoc(app, 'module', 'target', options)
|
actual = do_autodoc(app, 'module', 'target', options)
|
||||||
assert list(filter(lambda l: 'class::' in l, actual)) == [
|
assert list(filter(lambda l: 'class::' in l, actual)) == [
|
||||||
'.. py:class:: Class(arg)',
|
'.. py:class:: Class(arg)',
|
||||||
'.. py:class:: CustomDataDescriptor(doc)',
|
|
||||||
'.. py:class:: CustomDataDescriptor2(doc)',
|
|
||||||
'.. py:class:: CustomDataDescriptorMeta',
|
|
||||||
'.. py:class:: CustomDict',
|
'.. py:class:: CustomDict',
|
||||||
'.. py:class:: InstAttCls()',
|
'.. py:class:: InstAttCls()',
|
||||||
'.. py:class:: Outer',
|
'.. py:class:: Outer',
|
||||||
@ -991,13 +983,26 @@ def test_autodoc_staticmethod(app):
|
|||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||||
def test_autodoc_descriptor(app):
|
def test_autodoc_descriptor(app):
|
||||||
actual = do_autodoc(app, 'attribute', 'target.Class.descr')
|
options = {"members": None,
|
||||||
|
"undoc-members": True}
|
||||||
|
actual = do_autodoc(app, 'class', 'target.descriptor.Class', options)
|
||||||
assert list(actual) == [
|
assert list(actual) == [
|
||||||
'',
|
'',
|
||||||
'.. py:attribute:: Class.descr',
|
'.. py:class:: Class',
|
||||||
' :module: target',
|
' :module: target.descriptor',
|
||||||
'',
|
'',
|
||||||
|
' ',
|
||||||
|
' .. py:attribute:: Class.descr',
|
||||||
|
' :module: target.descriptor',
|
||||||
|
' ',
|
||||||
' Descriptor instance docstring.',
|
' Descriptor instance docstring.',
|
||||||
|
' ',
|
||||||
|
' ',
|
||||||
|
' .. py:method:: Class.prop',
|
||||||
|
' :module: target.descriptor',
|
||||||
|
' :property:',
|
||||||
|
' ',
|
||||||
|
' Property.',
|
||||||
' '
|
' '
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1027,14 +1032,12 @@ def test_autodoc_member_order(app):
|
|||||||
actual = do_autodoc(app, 'class', 'target.Class', options)
|
actual = do_autodoc(app, 'class', 'target.Class', options)
|
||||||
assert list(filter(lambda l: '::' in l, actual)) == [
|
assert list(filter(lambda l: '::' in l, actual)) == [
|
||||||
'.. py:class:: Class(arg)',
|
'.. py:class:: Class(arg)',
|
||||||
' .. py:attribute:: Class.descr',
|
|
||||||
' .. py:method:: Class.meth()',
|
' .. py:method:: Class.meth()',
|
||||||
' .. py:method:: Class.undocmeth()',
|
' .. py:method:: Class.undocmeth()',
|
||||||
' .. py:method:: Class.skipmeth()',
|
' .. py:method:: Class.skipmeth()',
|
||||||
' .. py:method:: Class.excludemeth()',
|
' .. py:method:: Class.excludemeth()',
|
||||||
' .. py:attribute:: Class.skipattr',
|
' .. py:attribute:: Class.skipattr',
|
||||||
' .. py:attribute:: Class.attr',
|
' .. py:attribute:: Class.attr',
|
||||||
' .. py:method:: Class.prop',
|
|
||||||
' .. py:attribute:: Class.docattr',
|
' .. py:attribute:: Class.docattr',
|
||||||
' .. py:attribute:: Class.udocattr',
|
' .. py:attribute:: Class.udocattr',
|
||||||
' .. py:attribute:: Class.mdocattr',
|
' .. py:attribute:: Class.mdocattr',
|
||||||
@ -1062,13 +1065,11 @@ def test_autodoc_member_order(app):
|
|||||||
' .. py:method:: Class.undocmeth()',
|
' .. py:method:: Class.undocmeth()',
|
||||||
' .. py:attribute:: Class._private_inst_attr',
|
' .. py:attribute:: Class._private_inst_attr',
|
||||||
' .. py:attribute:: Class.attr',
|
' .. py:attribute:: Class.attr',
|
||||||
' .. py:attribute:: Class.descr',
|
|
||||||
' .. py:attribute:: Class.docattr',
|
' .. py:attribute:: Class.docattr',
|
||||||
' .. py:attribute:: Class.inst_attr_comment',
|
' .. py:attribute:: Class.inst_attr_comment',
|
||||||
' .. py:attribute:: Class.inst_attr_inline',
|
' .. py:attribute:: Class.inst_attr_inline',
|
||||||
' .. py:attribute:: Class.inst_attr_string',
|
' .. py:attribute:: Class.inst_attr_string',
|
||||||
' .. py:attribute:: Class.mdocattr',
|
' .. py:attribute:: Class.mdocattr',
|
||||||
' .. py:method:: Class.prop',
|
|
||||||
' .. py:attribute:: Class.skipattr',
|
' .. py:attribute:: Class.skipattr',
|
||||||
' .. py:attribute:: Class.udocattr'
|
' .. py:attribute:: Class.udocattr'
|
||||||
]
|
]
|
||||||
@ -1082,7 +1083,6 @@ def test_autodoc_member_order(app):
|
|||||||
'.. py:class:: Class(arg)',
|
'.. py:class:: Class(arg)',
|
||||||
' .. py:attribute:: Class._private_inst_attr',
|
' .. py:attribute:: Class._private_inst_attr',
|
||||||
' .. py:attribute:: Class.attr',
|
' .. py:attribute:: Class.attr',
|
||||||
' .. py:attribute:: Class.descr',
|
|
||||||
' .. py:attribute:: Class.docattr',
|
' .. py:attribute:: Class.docattr',
|
||||||
' .. py:method:: Class.excludemeth()',
|
' .. py:method:: Class.excludemeth()',
|
||||||
' .. py:attribute:: Class.inst_attr_comment',
|
' .. py:attribute:: Class.inst_attr_comment',
|
||||||
@ -1091,7 +1091,6 @@ def test_autodoc_member_order(app):
|
|||||||
' .. py:attribute:: Class.mdocattr',
|
' .. py:attribute:: Class.mdocattr',
|
||||||
' .. py:method:: Class.meth()',
|
' .. py:method:: Class.meth()',
|
||||||
' .. py:method:: Class.moore(a, e, f) -> happiness',
|
' .. py:method:: Class.moore(a, e, f) -> happiness',
|
||||||
' .. py:method:: Class.prop',
|
|
||||||
' .. py:method:: Class.roger(a, *, b=2, c=3, d=4, e=5, f=6)',
|
' .. py:method:: Class.roger(a, *, b=2, c=3, d=4, e=5, f=6)',
|
||||||
' .. py:attribute:: Class.skipattr',
|
' .. py:attribute:: Class.skipattr',
|
||||||
' .. py:method:: Class.skipmeth()',
|
' .. py:method:: Class.skipmeth()',
|
||||||
@ -1422,26 +1421,26 @@ def test_enum_class(app):
|
|||||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||||
def test_descriptor_class(app):
|
def test_descriptor_class(app):
|
||||||
options = {"members": 'CustomDataDescriptor,CustomDataDescriptor2'}
|
options = {"members": 'CustomDataDescriptor,CustomDataDescriptor2'}
|
||||||
actual = do_autodoc(app, 'module', 'target', options)
|
actual = do_autodoc(app, 'module', 'target.descriptor', options)
|
||||||
assert list(actual) == [
|
assert list(actual) == [
|
||||||
'',
|
'',
|
||||||
'.. py:module:: target',
|
'.. py:module:: target.descriptor',
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
'.. py:class:: CustomDataDescriptor(doc)',
|
'.. py:class:: CustomDataDescriptor(doc)',
|
||||||
' :module: target',
|
' :module: target.descriptor',
|
||||||
'',
|
'',
|
||||||
' Descriptor class docstring.',
|
' Descriptor class docstring.',
|
||||||
' ',
|
' ',
|
||||||
' ',
|
' ',
|
||||||
' .. py:method:: CustomDataDescriptor.meth()',
|
' .. py:method:: CustomDataDescriptor.meth()',
|
||||||
' :module: target',
|
' :module: target.descriptor',
|
||||||
' ',
|
' ',
|
||||||
' Function.',
|
' Function.',
|
||||||
' ',
|
' ',
|
||||||
'',
|
'',
|
||||||
'.. py:class:: CustomDataDescriptor2(doc)',
|
'.. py:class:: CustomDataDescriptor2(doc)',
|
||||||
' :module: target',
|
' :module: target.descriptor',
|
||||||
'',
|
'',
|
||||||
' Descriptor class with custom metaclass docstring.',
|
' Descriptor class with custom metaclass docstring.',
|
||||||
' '
|
' '
|
||||||
@ -1888,12 +1887,10 @@ def test_autodoc_default_options_with_values(app):
|
|||||||
actual = do_autodoc(app, 'class', 'target.Class')
|
actual = do_autodoc(app, 'class', 'target.Class')
|
||||||
assert list(filter(lambda l: '::' in l, actual)) == [
|
assert list(filter(lambda l: '::' in l, actual)) == [
|
||||||
'.. py:class:: Class(arg)',
|
'.. py:class:: Class(arg)',
|
||||||
' .. py:attribute:: Class.descr',
|
|
||||||
' .. py:method:: Class.meth()',
|
' .. py:method:: Class.meth()',
|
||||||
' .. py:method:: Class.skipmeth()',
|
' .. py:method:: Class.skipmeth()',
|
||||||
' .. py:method:: Class.excludemeth()',
|
' .. py:method:: Class.excludemeth()',
|
||||||
' .. py:attribute:: Class.attr',
|
' .. py:attribute:: Class.attr',
|
||||||
' .. py:method:: Class.prop',
|
|
||||||
' .. py:attribute:: Class.docattr',
|
' .. py:attribute:: Class.docattr',
|
||||||
' .. py:attribute:: Class.udocattr',
|
' .. py:attribute:: Class.udocattr',
|
||||||
' .. py:attribute:: Class.mdocattr',
|
' .. py:attribute:: Class.mdocattr',
|
||||||
|
Loading…
Reference in New Issue
Block a user