"""
$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/dulcinea/lib/test/utest_keyed.py $
$Id: utest_keyed.py 30485 2008-01-21 21:06:41Z dbinger $
"""
from durus.persistent import Persistent
from qp.lib.keep import Keyed, Keep
from sancho.utest import UTest, raises

class Test (UTest):

    def check_a(self):
        raises(AssertionError, Keep)
        class PKeep(Keep, Persistent):
            pass
        keep = PKeep()
        class PKeyed(Keyed, Persistent):
            pass
        a = PKeyed()
        assert a.get_key() == None
        keep.add(a)
        raises(AssertionError, keep.add, a)
        b = PKeyed()
        b.junk = 1
        raises(TypeError, keep.add, b)
        raises(TypeError, keep.add, 1)
        assert a.get_key() == 1
        assert list(keep.get_mapping().items()) == [(1, a)]
        assert keep.get(1) == a

if __name__ == "__main__":
    Test()
