Commits

Georg Brandl committed 21acceb

Add a test for a new documenter.

Comments (0)

Files changed (2)

sphinx/ext/autodoc.py

                 try:
                     ret.append((mname, self.get_attr(self.object, mname)))
                 except AttributeError:
-                    self.directive.warn('missing attribute %s in object %s: '
+                    self.directive.warn('missing attribute %s in object %s'
                                         % (mname, self.fullname))
             return False, ret
         elif self.options.inherited_members:

tests/test_autodoc.py

 
 from docutils.statemachine import ViewList
 
-from sphinx.ext.autodoc import AutoDirective, Documenter, ModuleDocumenter, \
-     ClassDocumenter, FunctionDocumenter, DataDocumenter, MethodDocumenter, \
-     AttributeDocumenter, cut_lines, between, ALL
+from sphinx.ext.autodoc import AutoDirective, Documenter, add_documenter, \
+     ModuleLevelDocumenter, FunctionDocumenter, cut_lines, between, ALL
 
 
 def setup_module():
     app.disconnect(lid)
 
 
+def test_new_documenter():
+    class MyDocumenter(ModuleLevelDocumenter):
+        objtype = 'integer'
+        directivetype = 'data'
+        priority = 100
+
+        @classmethod
+        def can_document_member(cls, member, membername, isattr, parent):
+            return isinstance(member, int)
+
+        def document_members(self, all_members=False):
+            return
+
+    add_documenter(MyDocumenter)
+
+    def assert_result_contains(item, objtype, name, **kw):
+        inst = AutoDirective._registry[objtype](directive, name)
+        inst.generate(**kw)
+        #print '\n'.join(directive.result)
+        assert len(_warnings) == 0, _warnings
+        assert item in directive.result
+        del directive.result[:]
+
+    options.members = ['integer']
+    assert_result_contains('.. data:: integer', 'module', 'test_autodoc')
+
+
 def test_generate():
     def assert_warns(warn_str, objtype, name, **kw):
         inst = AutoDirective._registry[objtype](directive, name)
         assert item in directive.result
         del directive.result[:]
 
+    options.members = []
+
     # no module found?
     assert_warns("import for autodocumenting 'foobar'",
                  'function', 'foobar', more_content=None)
 
 __all__ = ['Class']
 
+integer = 1
+
 class CustomEx(Exception):
     """My custom exception."""
 
     def f(self):
         """Exception method."""
 
-
 class Base(object):
     def inheritedmeth(self):
         """Inherited function."""