Fix handling of __all__ for modules and add a test.

This commit is contained in:
Georg Brandl 2008-09-06 20:11:04 +00:00
parent 679cdb3348
commit 7679af3ae4
2 changed files with 21 additions and 2 deletions

View File

@ -499,7 +499,14 @@ class RstGenerator(object):
if what == 'module': if what == 'module':
if hasattr(todoc, '__all__'): if hasattr(todoc, '__all__'):
members_check_module = False 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: else:
# for implicit module members, check __module__ to avoid # for implicit module members, check __module__ to avoid
# documenting imported objects # documenting imported objects

View File

@ -268,9 +268,9 @@ def test_generate():
def assert_result_contains(item, *args): def assert_result_contains(item, *args):
gen.generate(*args) gen.generate(*args)
print '\n'.join(gen.result)
assert len(gen.warnings) == 0, gen.warnings assert len(gen.warnings) == 0, gen.warnings
assert item in gen.result assert item in gen.result
print '\n'.join(gen.result)
del gen.result[:] del gen.result[:]
# no module found? # no module found?
@ -322,6 +322,16 @@ def test_generate():
assert_result_contains(' :deprecated:', 'module', 'test_autodoc', [], None) assert_result_contains(' :deprecated:', 'module', 'test_autodoc', [], None)
options.platform = 'Platform' options.platform = 'Platform'
assert_result_contains(' :platform: Platform', 'module', 'test_autodoc', [], None) 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 # test noindex flag
options.noindex = True options.noindex = True
@ -335,6 +345,8 @@ def test_generate():
# --- generate fodder ------------ # --- generate fodder ------------
__all__ = ['Class']
class CustomEx(Exception): class CustomEx(Exception):
"""My custom exception.""" """My custom exception."""