Skip to content

Commit ac8feee

Browse files
committed
Test automodsumm_private_methods_of option
Signed-off-by: Conor MacBride <[email protected]>
1 parent 3ab214b commit ac8feee

9 files changed

+193
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Documenting a module with classes, also including private methods
2+
for a particular list of classes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. automodapi:: sphinx_automodapi.tests.example_module.private_classes
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Banana
2+
======
3+
4+
.. currentmodule:: sphinx_automodapi.tests.example_module.private_classes
5+
6+
.. autoclass:: Banana
7+
:show-inheritance:
8+
9+
.. rubric:: Methods Summary
10+
11+
.. autosummary::
12+
13+
~Banana._energy
14+
~Banana.eat
15+
16+
.. rubric:: Methods Documentation
17+
18+
.. automethod:: _energy
19+
.. automethod:: eat
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Fruit
2+
=====
3+
4+
.. currentmodule:: sphinx_automodapi.tests.example_module.private_classes
5+
6+
.. autoclass:: Fruit
7+
:show-inheritance:
8+
9+
.. rubric:: Attributes Summary
10+
11+
.. autosummary::
12+
13+
~Fruit.weight
14+
15+
.. rubric:: Methods Summary
16+
17+
.. autosummary::
18+
19+
~Fruit._out_of_date
20+
~Fruit.buy
21+
~Fruit.eat
22+
23+
.. rubric:: Attributes Documentation
24+
25+
.. autoattribute:: weight
26+
27+
.. rubric:: Methods Documentation
28+
29+
.. automethod:: _out_of_date
30+
.. automethod:: buy
31+
.. automethod:: eat
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Orange
2+
======
3+
4+
.. currentmodule:: sphinx_automodapi.tests.example_module.private_classes
5+
6+
.. autoclass:: Orange
7+
:show-inheritance:
8+
9+
.. rubric:: Methods Summary
10+
11+
.. autosummary::
12+
13+
~Orange.eat
14+
15+
.. rubric:: Methods Documentation
16+
17+
.. automethod:: eat
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
sphinx_automodapi.tests.example_module.private_classes Module
3+
-------------------------------------------------------------
4+
5+
.. automodule:: sphinx_automodapi.tests.example_module.private_classes
6+
7+
Classes
8+
^^^^^^^
9+
10+
.. automodsumm:: sphinx_automodapi.tests.example_module.private_classes
11+
:classes-only:
12+
:toctree: api
13+
14+
Class Inheritance Diagram
15+
^^^^^^^^^^^^^^^^^^^^^^^^^
16+
17+
.. automod-diagram:: sphinx_automodapi.tests.example_module.private_classes
18+
:private-bases:
19+
:parts: 1
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.. currentmodule:: sphinx_automodapi.tests.example_module.private_classes
2+
3+
.. autosummary::
4+
:toctree: api
5+
6+
Fruit
7+
Banana
8+
Orange
9+
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
__all__ = ['Fruit', 'Banana', 'Orange']
2+
3+
4+
class Fruit(object):
5+
"""
6+
An fruit
7+
"""
8+
def eat(self, time):
9+
"""
10+
Eat apple.
11+
"""
12+
pass
13+
14+
def buy(self, price):
15+
"""
16+
Buy apple.
17+
"""
18+
pass
19+
20+
@property
21+
def weight(self):
22+
"""
23+
The weight of the apple.
24+
"""
25+
return 0
26+
27+
@property
28+
def _age(self):
29+
"""
30+
The age of the fruit.
31+
"""
32+
return 0
33+
34+
def __len__(self):
35+
"""
36+
The length the fruit.
37+
"""
38+
return 0
39+
40+
def _out_of_date(self, date):
41+
"""
42+
Is it out of date?
43+
"""
44+
pass
45+
46+
47+
class Banana(Fruit):
48+
"""
49+
A banana
50+
"""
51+
def eat(self, time):
52+
"""
53+
Eat banana.
54+
"""
55+
pass
56+
57+
def _energy(self, units='kcal'):
58+
"""
59+
The energy in the banana.
60+
"""
61+
pass
62+
63+
def __add__(self, other):
64+
"""
65+
How to add the banana to something.
66+
"""
67+
pass
68+
69+
70+
class Orange(Fruit):
71+
"""
72+
An orange
73+
"""
74+
def eat(self, time):
75+
"""
76+
Eat orange.
77+
"""
78+
pass
79+
80+
def _energy(self, units='kcal'):
81+
"""
82+
The energy in the orange.
83+
"""
84+
pass
85+
86+
def __add__(self, other):
87+
"""
88+
How to add the orange to something.
89+
"""
90+
pass

sphinx_automodapi/tests/test_cases.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ def test_run_full_case(tmpdir, case_dir, parallel):
7878
'allowed_names'):
7979
conf['extensions'].append('sphinx_automodapi.smart_resolver')
8080

81+
if os.path.basename(case_dir) == 'private_methods':
82+
conf['automodsumm_private_methods_of'] = [
83+
'sphinx_automodapi.tests.example_module.private_classes.Fruit',
84+
'sphinx_automodapi.tests.example_module.private_classes.Banana',
85+
]
8186
start_dir = os.path.abspath('.')
8287

8388
src_dir = 'src' if 'source_dir' in case_dir else '.'

0 commit comments

Comments
 (0)