mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix handling of __all__ for modules and add a test.
This commit is contained in:
parent
679cdb3348
commit
7679af3ae4
@ -499,7 +499,14 @@ class RstGenerator(object):
|
||||
if what == 'module':
|
||||
if hasattr(todoc, '__all__'):
|
||||
members_check_module = False
|
||||
all_members = inspect.getmembers(todoc, lambda x: x in todoc.__all__)
|
||||
all_members = []
|
||||
for mname in todoc.__all__:
|
||||
try:
|
||||
all_members.append((mname, getattr(todoc, mname)))
|
||||
except AttributeError:
|
||||
self.warn('missing attribute mentioned in __all__: '
|
||||
'module %s, attribute %s' %
|
||||
(todoc.__name__, mname))
|
||||
else:
|
||||
# for implicit module members, check __module__ to avoid
|
||||
# documenting imported objects
|
||||
|
@ -268,9 +268,9 @@ def test_generate():
|
||||
|
||||
def assert_result_contains(item, *args):
|
||||
gen.generate(*args)
|
||||
print '\n'.join(gen.result)
|
||||
assert len(gen.warnings) == 0, gen.warnings
|
||||
assert item in gen.result
|
||||
print '\n'.join(gen.result)
|
||||
del gen.result[:]
|
||||
|
||||
# no module found?
|
||||
@ -322,6 +322,16 @@ def test_generate():
|
||||
assert_result_contains(' :deprecated:', 'module', 'test_autodoc', [], None)
|
||||
options.platform = 'Platform'
|
||||
assert_result_contains(' :platform: Platform', 'module', 'test_autodoc', [], None)
|
||||
# test if __all__ is respected for modules
|
||||
assert_result_contains('.. class:: Class', 'module', 'test_autodoc',
|
||||
['__all__'], None)
|
||||
try:
|
||||
assert_result_contains('.. exception:: CustomEx', 'module', 'test_autodoc',
|
||||
['__all__'], None)
|
||||
except AssertionError:
|
||||
pass
|
||||
else:
|
||||
assert False, 'documented CustomEx which is not in __all__'
|
||||
|
||||
# test noindex flag
|
||||
options.noindex = True
|
||||
@ -335,6 +345,8 @@ def test_generate():
|
||||
|
||||
# --- generate fodder ------------
|
||||
|
||||
__all__ = ['Class']
|
||||
|
||||
class CustomEx(Exception):
|
||||
"""My custom exception."""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user