summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-12-21 19:34:32 -0700
committerJason Gerard DeRose <jderose@redhat.com>2008-12-21 19:34:32 -0700
commit9d091c98f1f1bf7bacf49e9eaaa18ba8bb1bfd70 (patch)
treed8cf4dc86356ca8a13d769845de73f5b8b1371c8
parent4390523b7f854cefcb91843e1df3ca7575d43fea (diff)
downloadfreeipa-9d091c98f1f1bf7bacf49e9eaaa18ba8bb1bfd70.tar.gz
freeipa-9d091c98f1f1bf7bacf49e9eaaa18ba8bb1bfd70.tar.xz
freeipa-9d091c98f1f1bf7bacf49e9eaaa18ba8bb1bfd70.zip
Plugin.__init__() now checks that subclass hasn't defined attributes that conflict with the logger methods; added corresponding unit test
-rw-r--r--ipalib/frontend.py1
-rw-r--r--ipalib/plugable.py9
-rw-r--r--tests/test_ipalib/test_plugable.py8
3 files changed, 15 insertions, 3 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index 4ff77c59..c614e547 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -1087,7 +1087,6 @@ class Property(Attribute):
rules=self.rules,
normalize=self.normalize,
)
- super(Property, self).__init__()
def __rules_iter(self):
"""
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index f3b35d30..019386c3 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -263,8 +263,13 @@ class Plugin(ReadOnly):
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'):
+ log = logging.getLogger(self.fullname)
+ for name in ('debug', 'info', 'warning', 'error', 'critical', 'exception'):
+ if hasattr(self, name):
+ raise StandardError(
+ '%s.%s attribute (%r) conflicts with Plugin logger' % (
+ self.name, name, getattr(self, name))
+ )
setattr(self, name, getattr(log, name))
def __get_api(self):
diff --git a/tests/test_ipalib/test_plugable.py b/tests/test_ipalib/test_plugable.py
index b381675b..b0594323 100644
--- a/tests/test_ipalib/test_plugable.py
+++ b/tests/test_ipalib/test_plugable.py
@@ -337,6 +337,14 @@ class test_Plugin(ClassChecker):
assert o.doc is None
assert o.summary == '<%s>' % o.fullname
+ # Test that Plugin makes sure the subclass hasn't defined attributes
+ # whose names conflict with the logger methods set in Plugin.__init__():
+ class check(self.cls):
+ info = 'whatever'
+ e = raises(StandardError, check)
+ assert str(e) == \
+ "check.info attribute ('whatever') conflicts with Plugin logger"
+
def test_implements(self):
"""
Test the `ipalib.plugable.Plugin.implements` classmethod.