diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-01 20:42:35 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-01 20:42:35 +0000 |
commit | f3762a76c0824296e90385eac27455aaf06af32d (patch) | |
tree | a4683b6b4b19a49882cc810799c7cb6f8515b0af /ipalib/tests/test_plugable.py | |
parent | 4fe8e52ecb61088bcff2a7c91db454621d6755f1 (diff) | |
download | freeipa.git-f3762a76c0824296e90385eac27455aaf06af32d.tar.gz freeipa.git-f3762a76c0824296e90385eac27455aaf06af32d.tar.xz freeipa.git-f3762a76c0824296e90385eac27455aaf06af32d.zip |
40: Rewrote dictionary interface for plugable.NameSpace to better suite new architecture
Diffstat (limited to 'ipalib/tests/test_plugable.py')
-rw-r--r-- | ipalib/tests/test_plugable.py | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/ipalib/tests/test_plugable.py b/ipalib/tests/test_plugable.py index 99c9a4f6..4f92889c 100644 --- a/ipalib/tests/test_plugable.py +++ b/ipalib/tests/test_plugable.py @@ -21,7 +21,7 @@ Unit tests for `ipalib.plugable` module. """ -from tstutil import raises, no_set, no_del, read_only +from tstutil import raises, getitem, no_set, no_del, read_only from ipalib import plugable, errors @@ -236,3 +236,63 @@ def test_Registrar(): assert len(d) == 3 assert r[base] == d assert r[base.__name__] == d + + +def test_NameSpace(): + assert issubclass(plugable.NameSpace, plugable.ReadOnly) + + class DummyProxy(object): + def __init__(self, name): + self.__name = name + + def __get_name(self): + return self.__name + name = property(__get_name) + + def __str__(self): + return plugable.to_cli(self.__name) + + def get_name(i): + return 'noun_verb%d' % i + + def get_cli(i): + return 'noun-verb%d' % i + + def get_proxies(n): + for i in xrange(n): + yield DummyProxy(get_name(i)) + + cnt = 20 + ns = plugable.NameSpace(get_proxies(cnt)) + + # Test __len__ + assert len(ns) == cnt + + # Test __iter__ + i = None + for (i, item) in enumerate(ns): + assert type(item) is DummyProxy + assert item.name == get_name(i) + assert str(item) == get_cli(i) + assert i == cnt - 1 + + # Test __contains__, __getitem__: + for i in xrange(cnt): + name = get_name(i) + cli = get_cli(i) + assert name in ns + assert cli in ns + item = ns[name] + assert isinstance(item, DummyProxy) + assert item.name == name + assert str(item) == cli + assert ns[name] is item + assert ns[cli] is item + + # Check that KeyError is raised: + name = get_name(cnt) + cli = get_cli(cnt) + assert name not in ns + assert cli not in ns + raises(KeyError, getitem, ns, name) + raises(KeyError, getitem, ns, cli) |