mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
test: Move class inheritance samples into target.inheritance module
This commit is contained in:
parent
806fa22f34
commit
42e9fd896e
@ -34,26 +34,7 @@ def _funky_classmethod(name, b, c, d, docstring=None):
|
||||
return classmethod(function)
|
||||
|
||||
|
||||
class Base(object):
|
||||
def inheritedmeth(self):
|
||||
"""Inherited function."""
|
||||
|
||||
@classmethod
|
||||
def inheritedclassmeth(cls):
|
||||
"""Inherited class method."""
|
||||
|
||||
@staticmethod
|
||||
def inheritedstaticmeth(cls):
|
||||
"""Inherited static method."""
|
||||
|
||||
|
||||
class Derived(Base):
|
||||
def inheritedmeth(self):
|
||||
# no docstring here
|
||||
pass
|
||||
|
||||
|
||||
class Class(Base):
|
||||
class Class(object):
|
||||
"""Class to document."""
|
||||
|
||||
def meth(self):
|
||||
|
19
tests/roots/test-ext-autodoc/target/inheritance.py
Normal file
19
tests/roots/test-ext-autodoc/target/inheritance.py
Normal file
@ -0,0 +1,19 @@
|
||||
class Base(object):
|
||||
def inheritedmeth(self):
|
||||
"""Inherited function."""
|
||||
|
||||
@classmethod
|
||||
def inheritedclassmeth(cls):
|
||||
"""Inherited class method."""
|
||||
|
||||
@staticmethod
|
||||
def inheritedstaticmeth(cls):
|
||||
"""Inherited static method."""
|
||||
|
||||
|
||||
class Derived(Base):
|
||||
def inheritedmeth(self):
|
||||
# no docstring here
|
||||
pass
|
||||
|
||||
|
@ -454,7 +454,7 @@ def test_get_doc():
|
||||
assert getdocl('method', J.foo) == ['Method docstring']
|
||||
assert getdocl('function', J().foo) == ['Method docstring']
|
||||
|
||||
from target import Base, Derived
|
||||
from target.inheritance import Base, Derived
|
||||
|
||||
# NOTE: inspect.getdoc seems not to work with locally defined classes
|
||||
directive.env.config.autodoc_inherit_docstrings = False
|
||||
@ -498,6 +498,7 @@ def test_new_documenter(app):
|
||||
@pytest.mark.usefixtures('setup_test')
|
||||
def test_attrgetter_using():
|
||||
from target import Class
|
||||
from target.inheritance import Derived
|
||||
|
||||
def assert_getter_works(objtype, name, obj, attrs=[], **kw):
|
||||
getattr_spy = []
|
||||
@ -527,7 +528,7 @@ def test_attrgetter_using():
|
||||
assert_getter_works('class', 'target.Class', Class, ['meth'])
|
||||
|
||||
options.inherited_members = True
|
||||
assert_getter_works('class', 'target.Class', Class, ['meth', 'inheritedmeth'])
|
||||
assert_getter_works('class', 'target.inheritance.Derived', Derived, ['inheritedmeth'])
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||
@ -630,14 +631,14 @@ def test_autodoc_attributes(app):
|
||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||
def test_autodoc_members(app):
|
||||
# default (no-members)
|
||||
actual = do_autodoc(app, 'class', 'target.Base')
|
||||
actual = do_autodoc(app, 'class', 'target.inheritance.Base')
|
||||
assert list(filter(lambda l: '::' in l, actual)) == [
|
||||
'.. py:class:: Base',
|
||||
]
|
||||
|
||||
# default ALL-members
|
||||
options = {"members": None}
|
||||
actual = do_autodoc(app, 'class', 'target.Base', options)
|
||||
actual = do_autodoc(app, 'class', 'target.inheritance.Base', options)
|
||||
assert list(filter(lambda l: '::' in l, actual)) == [
|
||||
'.. py:class:: Base',
|
||||
' .. py:method:: Base.inheritedclassmeth()',
|
||||
@ -647,7 +648,7 @@ def test_autodoc_members(app):
|
||||
|
||||
# default specific-members
|
||||
options = {"members": "inheritedmeth,inheritedstaticmeth"}
|
||||
actual = do_autodoc(app, 'class', 'target.Base', options)
|
||||
actual = do_autodoc(app, 'class', 'target.inheritance.Base', options)
|
||||
assert list(filter(lambda l: '::' in l, actual)) == [
|
||||
'.. py:class:: Base',
|
||||
' .. py:method:: Base.inheritedmeth()',
|
||||
@ -659,7 +660,7 @@ def test_autodoc_members(app):
|
||||
def test_autodoc_exclude_members(app):
|
||||
options = {"members": None,
|
||||
"exclude-members": "inheritedmeth,inheritedstaticmeth"}
|
||||
actual = do_autodoc(app, 'class', 'target.Base', options)
|
||||
actual = do_autodoc(app, 'class', 'target.inheritance.Base', options)
|
||||
assert list(filter(lambda l: '::' in l, actual)) == [
|
||||
'.. py:class:: Base',
|
||||
' .. py:method:: Base.inheritedclassmeth()'
|
||||
@ -668,7 +669,7 @@ def test_autodoc_exclude_members(app):
|
||||
# members vs exclude-members
|
||||
options = {"members": "inheritedmeth",
|
||||
"exclude-members": "inheritedmeth"}
|
||||
actual = do_autodoc(app, 'class', 'target.Base', options)
|
||||
actual = do_autodoc(app, 'class', 'target.inheritance.Base', options)
|
||||
assert list(filter(lambda l: '::' in l, actual)) == [
|
||||
'.. py:class:: Base',
|
||||
]
|
||||
@ -702,15 +703,11 @@ def test_autodoc_undoc_members(app):
|
||||
def test_autodoc_inherited_members(app):
|
||||
options = {"members": None,
|
||||
"inherited-members": None}
|
||||
actual = do_autodoc(app, 'class', 'target.Class', options)
|
||||
actual = do_autodoc(app, 'class', 'target.inheritance.Derived', options)
|
||||
assert list(filter(lambda l: 'method::' in l, actual)) == [
|
||||
' .. py:method:: Class.excludemeth()',
|
||||
' .. py:method:: Class.inheritedclassmeth()',
|
||||
' .. py:method:: Class.inheritedmeth()',
|
||||
' .. py:method:: Class.inheritedstaticmeth(cls)',
|
||||
' .. py:method:: Class.meth()',
|
||||
' .. py:method:: Class.moore(a, e, f) -> happiness',
|
||||
' .. py:method:: Class.skipmeth()'
|
||||
' .. py:method:: Derived.inheritedclassmeth()',
|
||||
' .. py:method:: Derived.inheritedmeth()',
|
||||
' .. py:method:: Derived.inheritedstaticmeth(cls)',
|
||||
]
|
||||
|
||||
|
||||
@ -755,10 +752,12 @@ def test_autodoc_special_members(app):
|
||||
actual = do_autodoc(app, 'class', 'target.Class', options)
|
||||
assert list(filter(lambda l: '::' in l, actual)) == [
|
||||
'.. py:class:: Class(arg)',
|
||||
' .. py:attribute:: Class.__dict__',
|
||||
' .. py:method:: Class.__init__(arg)',
|
||||
' .. py:attribute:: Class.__module__',
|
||||
' .. py:method:: Class.__special1__()',
|
||||
' .. py:method:: Class.__special2__()',
|
||||
' .. py:attribute:: Class.__weakref__',
|
||||
' .. py:attribute:: Class.attr',
|
||||
' .. py:attribute:: Class.docattr',
|
||||
' .. py:method:: Class.excludemeth()',
|
||||
@ -812,12 +811,12 @@ def test_autodoc_noindex(app):
|
||||
|
||||
# TODO: :noindex: should be propagated to children of target item.
|
||||
|
||||
actual = do_autodoc(app, 'class', 'target.Base', options)
|
||||
actual = do_autodoc(app, 'class', 'target.inheritance.Base', options)
|
||||
assert list(actual) == [
|
||||
'',
|
||||
'.. py:class:: Base',
|
||||
' :noindex:',
|
||||
' :module: target',
|
||||
' :module: target.inheritance',
|
||||
''
|
||||
]
|
||||
|
||||
@ -885,11 +884,11 @@ def test_autodoc_inner_class(app):
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||
def test_autodoc_classmethod(app):
|
||||
actual = do_autodoc(app, 'method', 'target.Base.inheritedclassmeth')
|
||||
actual = do_autodoc(app, 'method', 'target.inheritance.Base.inheritedclassmeth')
|
||||
assert list(actual) == [
|
||||
'',
|
||||
'.. py:method:: Base.inheritedclassmeth()',
|
||||
' :module: target',
|
||||
' :module: target.inheritance',
|
||||
' :classmethod:',
|
||||
'',
|
||||
' Inherited class method.',
|
||||
@ -899,11 +898,11 @@ def test_autodoc_classmethod(app):
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||
def test_autodoc_staticmethod(app):
|
||||
actual = do_autodoc(app, 'method', 'target.Base.inheritedstaticmeth')
|
||||
actual = do_autodoc(app, 'method', 'target.inheritance.Base.inheritedstaticmeth')
|
||||
assert list(actual) == [
|
||||
'',
|
||||
'.. py:method:: Base.inheritedstaticmeth(cls)',
|
||||
' :module: target',
|
||||
' :module: target.inheritance',
|
||||
' :staticmethod:',
|
||||
'',
|
||||
' Inherited static method.',
|
||||
|
Loading…
Reference in New Issue
Block a user