def test_pickle(self): filename = '/tmp/testdict.pickle' remove(filename) cache = Cache(filename, file_format='pickle') cache['name'] = 'jon' cache.update({'answer': 42}) cache.close() cache2 = Cache(filename, file_format='pickle') self.assertEqual(cache, cache2) self.assertEqual(2, len(cache2.items())) self.assertTrue('name' in cache2.keys()) self.assertTrue('answer' in cache2.keys()) self.assertEqual('jon', cache2.pop('name')) self.assertEqual(42, cache2['answer']) remove(filename)
def test_json(self): filename = '/tmp/testdict.json' remove(filename) cache = Cache(filename, file_format='json') cache['name'] = 'jon' cache.update({'answer': '42'}) cache.close() cache2 = Cache(filename, file_format='json') self.assertEqual(sorted(cache.items()), sorted(cache2.items())) self.assertEqual(2, len(cache2.items())) self.assertTrue('name' in cache2.keys()) self.assertTrue('answer' in cache2.keys()) self.assertEqual('jon', cache2.pop('name')) self.assertEqual('42', cache2['answer']) remove(filename)