def setUp(self): self.dict_inst = SynchronizedDict()
class SynchronizedDict_test(unittest.TestCase): def setUp(self): self.dict_inst = SynchronizedDict() def test_put(self): self.dict_inst.put('Babar', 'éléphant') self.assertEqual(self.dict_inst.get(), ('Babar', ['éléphant'])) def test_add(self): self.dict_inst.put('Babar', 'éléphant') self.dict_inst.add_item_to_key('Babar', 'roi') self.assertEqual(self.dict_inst.get(), ('Babar', ['éléphant', 'roi'])) def test_get_key(self): self.dict_inst.put('Babar', 'éléphant') self.dict_inst.put('Céleste', 'femme de babar') self.assertEqual(self.dict_inst.get_with_key('Céleste'), ['femme de babar']) def test_replace(self): self.dict_inst.put('Babar', 'éléphant') self.dict_inst.put('Babar', 'roi') self.assertEqual(self.dict_inst.get(), ('Babar', ['roi'])) def test_add_failed(self): self.assertRaises(KeyError, self.dict_inst.add_item_to_key, 1, 2) def test_get_failed(self): self.dict_inst.put(2, 3) self.assertRaises(KeyError, self.dict_inst.get_with_key, 1) def test_empty_get_nowait(self): self.assertRaises(Empty, self.dict_inst.get_nowait) def test_empty_get_timeout(self): print '\ntesting get from empty dict, probably waiting 2 seconds' self.assertRaises(Empty, self.dict_inst.get, timeout=2) def test_empty_get_key(self): self.assertRaises(Empty, self.dict_inst.get_with_key, 1)