mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
100: Cleaned up NameSpace docstrings; cleanup up NameSpace unit tests
This commit is contained in:
@@ -278,13 +278,17 @@ class Plugin(ProxyTarget):
|
|||||||
|
|
||||||
class NameSpace(ReadOnly):
|
class NameSpace(ReadOnly):
|
||||||
"""
|
"""
|
||||||
A read-only namespace of (key, value) pairs that can be accessed
|
A read-only namespace of Proxy instances. Proxy.name is used to name the
|
||||||
both as instance attributes and as dictionary items.
|
attributes pointing to the Proxy instances, which can also be accesses
|
||||||
|
through a dictionary interface, for example:
|
||||||
|
|
||||||
|
>>> assert namespace.my_proxy is namespace['my_proxy'] # True
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, proxies):
|
def __init__(self, proxies):
|
||||||
"""
|
"""
|
||||||
NameSpace
|
`proxies` - an iterable returning the Proxy instances to be contained
|
||||||
|
in this NameSpace.
|
||||||
"""
|
"""
|
||||||
self.__proxies = tuple(proxies)
|
self.__proxies = tuple(proxies)
|
||||||
self.__d = dict()
|
self.__d = dict()
|
||||||
@@ -299,7 +303,7 @@ class NameSpace(ReadOnly):
|
|||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
"""
|
"""
|
||||||
Iterates through the proxies in this NameSpace in the same order they
|
Iterates through the proxies in this NameSpace in the same order they
|
||||||
were passed in the contructor.
|
were passed to the constructor.
|
||||||
"""
|
"""
|
||||||
for proxy in self.__proxies:
|
for proxy in self.__proxies:
|
||||||
yield proxy
|
yield proxy
|
||||||
|
|||||||
@@ -332,62 +332,69 @@ class test_Plugin(ClassChecker):
|
|||||||
raises(AssertionError, sub.finalize, api)
|
raises(AssertionError, sub.finalize, api)
|
||||||
|
|
||||||
|
|
||||||
def test_NameSpace():
|
class test_NameSpace(ClassChecker):
|
||||||
cls = plugable.NameSpace
|
"""
|
||||||
assert issubclass(cls, plugable.ReadOnly)
|
Tests the `NameSpace` class.
|
||||||
|
"""
|
||||||
|
_cls = plugable.NameSpace
|
||||||
|
|
||||||
class base(object):
|
def test_class(self):
|
||||||
__public__ = frozenset((
|
assert self.cls.__bases__ == (plugable.ReadOnly,)
|
||||||
'plusplus',
|
|
||||||
))
|
|
||||||
|
|
||||||
def plusplus(self, n):
|
def test_namespace(self):
|
||||||
return n + 1
|
class base(object):
|
||||||
|
__public__ = frozenset((
|
||||||
|
'plusplus',
|
||||||
|
))
|
||||||
|
|
||||||
class plugin(base):
|
def plusplus(self, n):
|
||||||
def __init__(self, name):
|
return n + 1
|
||||||
self.name = name
|
|
||||||
|
|
||||||
def get_name(i):
|
class plugin(base):
|
||||||
return 'noun_verb%d' % i
|
def __init__(self, name):
|
||||||
|
self.name = name
|
||||||
|
|
||||||
def get_proxies(n):
|
def get_name(i):
|
||||||
for i in xrange(n):
|
return 'noun_verb%d' % i
|
||||||
yield plugable.Proxy(base, plugin(get_name(i)))
|
|
||||||
|
|
||||||
cnt = 20
|
def get_proxies(n):
|
||||||
ns = cls(get_proxies(cnt))
|
for i in xrange(n):
|
||||||
|
yield plugable.Proxy(base, plugin(get_name(i)))
|
||||||
|
|
||||||
# Test __len__
|
cnt = 20
|
||||||
assert len(ns) == cnt
|
ns = self.cls(get_proxies(cnt))
|
||||||
|
assert ns.__islocked__() is True
|
||||||
|
|
||||||
# Test __iter__
|
# Test __len__
|
||||||
i = None
|
assert len(ns) == cnt
|
||||||
for (i, proxy) in enumerate(ns):
|
|
||||||
assert type(proxy) is plugable.Proxy
|
|
||||||
assert proxy.name == get_name(i)
|
|
||||||
assert i == cnt - 1
|
|
||||||
|
|
||||||
# Test __contains__, __getitem__, getattr():
|
# Test __iter__
|
||||||
proxies = frozenset(ns)
|
i = None
|
||||||
for i in xrange(cnt):
|
for (i, proxy) in enumerate(ns):
|
||||||
name = get_name(i)
|
assert type(proxy) is plugable.Proxy
|
||||||
assert name in ns
|
assert proxy.name == get_name(i)
|
||||||
proxy = ns[name]
|
assert i == cnt - 1
|
||||||
assert proxy.name == name
|
|
||||||
assert type(proxy) is plugable.Proxy
|
|
||||||
assert proxy in proxies
|
|
||||||
assert read_only(ns, name) is proxy
|
|
||||||
|
|
||||||
# Test dir():
|
# Test __contains__, __getitem__, getattr():
|
||||||
assert set(get_name(i) for i in xrange(cnt)).issubset(set(dir(ns)))
|
proxies = frozenset(ns)
|
||||||
|
for i in xrange(cnt):
|
||||||
|
name = get_name(i)
|
||||||
|
assert name in ns
|
||||||
|
proxy = ns[name]
|
||||||
|
assert proxy.name == name
|
||||||
|
assert type(proxy) is plugable.Proxy
|
||||||
|
assert proxy in proxies
|
||||||
|
assert read_only(ns, name) is proxy
|
||||||
|
|
||||||
# Test that KeyError, AttributeError is raised:
|
# Test dir():
|
||||||
name = get_name(cnt)
|
assert set(get_name(i) for i in xrange(cnt)).issubset(dir(ns))
|
||||||
assert name not in ns
|
|
||||||
raises(KeyError, getitem, ns, name)
|
# Test that KeyError, AttributeError is raised:
|
||||||
raises(AttributeError, getattr, ns, name)
|
name = get_name(cnt)
|
||||||
no_set(ns, name)
|
assert name not in ns
|
||||||
|
raises(KeyError, getitem, ns, name)
|
||||||
|
raises(AttributeError, getattr, ns, name)
|
||||||
|
no_set(ns, name)
|
||||||
|
|
||||||
|
|
||||||
def test_Registrar():
|
def test_Registrar():
|
||||||
|
|||||||
Reference in New Issue
Block a user