#!/www/python/bin/python
"""
$URL: svn+ssh://svn/repos/trunk/dulcinea/lib/test/utest_keyed.py $
$Id: utest_keyed.py 25054 2004-09-09 18:04:30Z dbinger $
"""

from sancho.utest import UTest
from dulcinea.keyed import Keyed, KeyedMap


class Test (UTest):

    def check_a(self):
        self.map = KeyedMap()
        self.a = Keyed()
        assert self.a.get_key() == None
        self.map.add(self.a)
        try:
            self.map.add(self.a)
            assert 0
        except AssertionError: pass
        self.b = Keyed()
        self.b.junk = 1
        try:
            self.map.add(self.b)
            assert 0
        except TypeError: pass
        try:
            self.map.add(1)
            assert 0
        except TypeError: pass
        assert self.a.get_key() == 1
        assert self.map.get_mapping().items() == [(1, self.a)]
        assert self.map.get(1) == self.a

if __name__ == "__main__":
    Test()
