41: New plugable.NameSpace now has attributes set for each member; updated unit tests

This commit is contained in:
Jason Gerard DeRose 2008-08-01 20:58:48 +00:00
parent f3762a76c0
commit a0f480a414
2 changed files with 9 additions and 2 deletions

View File

@ -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),

View File

@ -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)