def test(self): u = IntIds() obj = P() obj._p_jar = ConnectionStub() self.assertRaises(KeyError, u.getId, obj) self.assertRaises(KeyError, u.getId, P()) self.assert_(u.queryId(obj) is None) self.assert_(u.queryId(obj, 42) is 42) self.assert_(u.queryId(P(), 42) is 42) self.assert_(u.queryObject(42) is None) self.assert_(u.queryObject(42, obj) is obj) uid = u.register(obj) self.assert_(u.getObject(uid) is obj) self.assert_(u.queryObject(uid) is obj) self.assertEquals(u.getId(obj), uid) self.assertEquals(u.queryId(obj), uid) uid2 = u.register(obj) self.assertEquals(uid, uid2) u.unregister(obj) self.assertRaises(KeyError, u.getObject, uid) self.assertRaises(KeyError, u.getId, obj)
def test_non_keyreferences(self): u = IntIds() obj = object() self.assert_(u.queryId(obj) is None) self.assert_(u.unregister(obj) is None) self.assertRaises(KeyError, u.getId, obj)