Takayuki Shimizukawa avatar Takayuki Shimizukawa committed fbfd937

add test for pull request #111: Respect add_autodoc_attrgetter() even when inherited-members is set

Comments (0)

Files changed (2)

 Release 1.2 (in development)
+* PR#111: Respect add_autodoc_attrgetter() even when inherited-members is set.
+  Thanks to A. Jesse Jiryu Davis.
 * #1090: Fix gettext does not extract glossary terms.
 * #1070: Avoid un-pickling issues when running Python 3 and the saved


 from StringIO import StringIO
 from util import *
+from nose.tools import with_setup
 from docutils.statemachine import ViewList
     assert_result_contains('.. py:data:: integer', 'module', 'test_autodoc')
+def cleanup_test_attrgetter_using():
+    del processed_docstrings[:]
+    del processed_signatures[:]
+    del directive.result[:]
+    del _warnings[:]
+    AutoDirective._special_attrgetters.clear()
+    setup_module()
+@with_setup(None, cleanup_test_attrgetter_using)
+def test_attrgetter_using():
+    def assert_getter_works(objtype, name, obj, attrs=[], **kw):
+        getattr_spy = []
+        def special_getattr(obj, name, *defargs):
+            if name in attrs:
+                getattr_spy.append((obj, name))
+                return None
+            return getattr(obj, name, *defargs)
+        AutoDirective._special_attrgetters[type] = special_getattr
+        del getattr_spy[:]
+        inst = AutoDirective._registry[objtype](directive, name)
+        inst.generate(**kw)
+        hooked_members = [s[1] for s in getattr_spy]
+        documented_members = [s[1] for s in processed_signatures]
+        for attr in attrs:
+            fullname = '.'.join((name, attr))
+            assert attr in hooked_members
+            assert fullname not in documented_members, \
+                '%r was not hooked by special_attrgetter function' % fullname
+    options.members = ALL
+    options.inherited_members = False
+    assert_getter_works('class', 'test_autodoc.Class', Class,
+                       ['meth'])
+    options.inherited_members = True
+    assert_getter_works('class', 'test_autodoc.Class', Class,
+                       ['meth', 'inheritedmeth'])
 def test_generate():
     def assert_warns(warn_str, objtype, name, **kw):
         inst = AutoDirective._registry[objtype](directive, name)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.