From 4f24f0fd8837383f4a2abc54946f6f84810807b8 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 17 Dec 2008 23:08:52 -0700 Subject: Plugin.doc instance attribute is now parsed out using inspect.getdoc(); added Plugin.summary instance attribute, created in Plugin.__init__() --- ipalib/plugable.py | 6 +++++- tests/test_ipalib/test_plugable.py | 13 +++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ipalib/plugable.py b/ipalib/plugable.py index 5363a51e9..e6b5c1ac8 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -258,7 +258,11 @@ class Plugin(ReadOnly): self.name = cls.__name__ self.module = cls.__module__ self.fullname = '%s.%s' % (self.module, self.name) - self.doc = cls.__doc__ + self.doc = inspect.getdoc(cls) + if self.doc is None: + self.summary = '<%s>' % self.fullname + else: + self.summary = self.doc.split('\n\n', 1)[0] log = logging.getLogger('ipa') for name in ('debug', 'info', 'warning', 'error', 'critical'): setattr(self, name, getattr(log, name)) diff --git a/tests/test_ipalib/test_plugable.py b/tests/test_ipalib/test_plugable.py index 02df058b8..21c712809 100644 --- a/tests/test_ipalib/test_plugable.py +++ b/tests/test_ipalib/test_plugable.py @@ -21,6 +21,7 @@ Test the `ipalib.plugable` module. """ +import inspect from tests.util import raises, no_set, no_del, read_only from tests.util import getitem, setitem, delitem from tests.util import ClassChecker, create_test_api @@ -313,7 +314,7 @@ class test_Plugin(ClassChecker): assert o.name == 'Plugin' assert o.module == 'ipalib.plugable' assert o.fullname == 'ipalib.plugable.Plugin' - assert o.doc == self.cls.__doc__ + assert o.doc == inspect.getdoc(self.cls) class some_subclass(self.cls): """ Do sub-classy things. @@ -321,12 +322,20 @@ class test_Plugin(ClassChecker): Although it doesn't know how to comport itself and is not for mixed company, this class *is* useful as we all need a little sub-class now and then. + + One more paragraph. """ o = some_subclass() assert o.name == 'some_subclass' assert o.module == __name__ assert o.fullname == '%s.some_subclass' % __name__ - assert o.doc == some_subclass.__doc__ + assert o.doc == inspect.getdoc(some_subclass) + assert o.summary == 'Do sub-classy things.' + class another_subclass(self.cls): + pass + o = another_subclass() + assert o.doc is None + assert o.summary == '<%s>' % o.fullname def test_implements(self): """ -- cgit