summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ipalib/plugable.py1
-rw-r--r--ipalib/tests/test_plugable.py10
2 files changed, 9 insertions, 2 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 4923c621..9025c1db 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -142,6 +142,7 @@ class NameSpace(ReadOnly):
object.__setattr__(self, '_NameSpace__hname', {})
for item in self.__items:
+ object.__setattr__(self, item.name, item)
for (key, d) in [
(item.name, self.__pname),
(str(item), self.__hname),
diff --git a/ipalib/tests/test_plugable.py b/ipalib/tests/test_plugable.py
index 4f92889c..fc7fff98 100644
--- a/ipalib/tests/test_plugable.py
+++ b/ipalib/tests/test_plugable.py
@@ -276,7 +276,7 @@ def test_NameSpace():
assert str(item) == get_cli(i)
assert i == cnt - 1
- # Test __contains__, __getitem__:
+ # Test __contains__, __getitem__, getattr():
for i in xrange(cnt):
name = get_name(i)
cli = get_cli(i)
@@ -288,11 +288,17 @@ def test_NameSpace():
assert str(item) == cli
assert ns[name] is item
assert ns[cli] is item
+ assert read_only(ns, name) is item
- # Check that KeyError is raised:
+ # Test dir():
+ assert set(get_name(i) for i in xrange(cnt)).issubset(set(dir(ns)))
+
+ # Test that KeyError, AttributeError 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)
+ raises(AttributeError, getattr, ns, name)
+ no_set(ns, name)