def test_dup_gen(self): """ allocate id twice """ objrepo = {} mobj = MockIdentifiableObject_1(1) mid_a = dpcore.allocate_object_id(mobj, "T", objrepo) mid_b = dpcore.allocate_object_id(mobj, "T", objrepo) self.assertTrue(mid_a is not None) self.assertTrue(mid_b is not None) self.assertEqual(mid_a, mid_b) self.assertEqual(len(objrepo), 1) self.assertEqual(objrepo[mid_a], mobj)
def test_allocate_for_diffobj(self): """ allocate for different objects """ objrepo = {} mobj_a = MockIdentifiableObject_1(1) mobj_b = MockIdentifiableObject_1("a") mid_a = dpcore.allocate_object_id(mobj_a, "T", objrepo) mid_b = dpcore.allocate_object_id(mobj_b, "T", objrepo) self.assertTrue(mid_a is not None) self.assertTrue(mid_b is not None) self.assertNotEqual(mid_a, mid_b) self.assertEqual(len(objrepo), 2) self.assertEqual(objrepo[mid_a], mobj_a) self.assertEqual(objrepo[mid_b], mobj_b)
def test_allocate_w_empty_object(self): """ allocate id for empty (object signature is None) object """ objrepo = {} mobj = MockIdentifiableObject_1(None) mid = dpcore.allocate_object_id(mobj, "T", objrepo) self.assertTrue(mid is None) self.assertEqual(len(objrepo), 0)