mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-01-11 00:31:56 -06:00
94: Renamed Proxy._clone() method to Proxy.__clone__(); updated unit tests
This commit is contained in:
parent
cc5b017494
commit
3495c67d57
@ -139,6 +139,14 @@ class Proxy(ReadOnly):
|
||||
def implements(self, arg):
|
||||
return self.__base.implements(arg)
|
||||
|
||||
def __clone__(self, name_attr):
|
||||
"""
|
||||
Returns a Proxy instance identical to this one except the proxy name
|
||||
might be derived from a different attribute on the target. The same
|
||||
base and target will be used.
|
||||
"""
|
||||
return self.__class__(self.__base, self.__target, name_attr)
|
||||
|
||||
def __iter__(self):
|
||||
"""
|
||||
Iterates (in ascending order) though the attribute names this proxy is
|
||||
@ -168,8 +176,6 @@ class Proxy(ReadOnly):
|
||||
def __call__(self, *args, **kw):
|
||||
return self['__call__'](*args, **kw)
|
||||
|
||||
def _clone(self, name_attr):
|
||||
return self.__class__(self.__base, self.__target, name_attr)
|
||||
|
||||
def __repr__(self):
|
||||
return '%s(%s, %r, %r)' % (
|
||||
|
@ -226,7 +226,7 @@ class obj(plugable.Plugin):
|
||||
def __filter(self, name):
|
||||
for i in getattr(self.api, name):
|
||||
if i.obj_name == self.name:
|
||||
yield i._clone('attr_name')
|
||||
yield i.__clone__('attr_name')
|
||||
|
||||
|
||||
class attr(plugable.Plugin):
|
||||
|
@ -174,12 +174,12 @@ class test_ProxyTarget(ClassChecker):
|
||||
|
||||
class test_Proxy(ClassChecker):
|
||||
"""
|
||||
Test the `Proxy` class.
|
||||
Tests the `Proxy` class.
|
||||
"""
|
||||
_cls = plugable.Proxy
|
||||
|
||||
def test_class(self):
|
||||
assert self.cls.__bases__ == (plugable.ReadOnly,)
|
||||
assert self.cls.__bases__ == (plugable.ReadOnly,)
|
||||
|
||||
def test_proxy(self):
|
||||
# Setup:
|
||||
@ -242,19 +242,9 @@ class test_Proxy(ClassChecker):
|
||||
p = self.cls(base, i, 'attr_name')
|
||||
assert read_only(p, 'name') == 'add'
|
||||
|
||||
# Test _clone():
|
||||
i = plugin()
|
||||
p = self.cls(base, i)
|
||||
assert read_only(p, 'name') == 'user_add'
|
||||
c = p._clone('attr_name')
|
||||
assert isinstance(c, self.cls)
|
||||
assert read_only(c, 'name') == 'add'
|
||||
assert c is not p
|
||||
assert c('whoever') == p('whoever')
|
||||
|
||||
def test_implements(self):
|
||||
"""
|
||||
Test the `implements` method.
|
||||
Tests the `implements` method.
|
||||
"""
|
||||
class base(object):
|
||||
__public__ = frozenset()
|
||||
@ -276,6 +266,23 @@ class test_Proxy(ClassChecker):
|
||||
p = self.cls(base, o)
|
||||
assert p.implements(3) == 10
|
||||
|
||||
def test_clone(self):
|
||||
"""
|
||||
Tests the `__clone__` method.
|
||||
"""
|
||||
class base(object):
|
||||
__public__ = frozenset()
|
||||
class sub(base):
|
||||
name = 'some_name'
|
||||
label = 'another_name'
|
||||
|
||||
p = self.cls(base, sub())
|
||||
assert read_only(p, 'name') == 'some_name'
|
||||
c = p.__clone__('label')
|
||||
assert isinstance(c, self.cls)
|
||||
assert c is not p
|
||||
assert read_only(c, 'name') == 'another_name'
|
||||
|
||||
|
||||
def test_Plugin():
|
||||
cls = plugable.Plugin
|
||||
|
Loading…
Reference in New Issue
Block a user