mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Plugin.__init__() now checks that subclass hasn't defined attributes that conflict with the logger methods; added corresponding unit test
This commit is contained in:
@@ -1087,7 +1087,6 @@ class Property(Attribute):
|
||||
rules=self.rules,
|
||||
normalize=self.normalize,
|
||||
)
|
||||
super(Property, self).__init__()
|
||||
|
||||
def __rules_iter(self):
|
||||
"""
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user