def test_picklecache_flush_data(self): """Tests that flush saves data to the file object.""" if os.path.exists('datastore.pkl'): os.unlink('datastore.pkl') data = ['Winkin', 'Blinkin', 'Nod'] fpath = 'datastore.pkl' pcache = PickleCache(fpath) pcache['data'] = data pcache.flush() fhandler = open(fpath, 'r') retrieved = pickle.load(fhandler) fhandler.close() self.assertEqual(retrieved, {'data': data})
def test_picklecache_autosync_del(self): """Tests that autosync triggers when deleting an item.""" if os.path.exists('datastore.pkl'): os.unlink('datastore.pkl') data = ['Winkin', 'Blinkin', 'Nod'] fpath = 'datastore.pkl' pcache = PickleCache(fpath) pcache['data'] = data pcache.flush() pcache.autosync = True del pcache['data'] fhandler = open(fpath, 'r') retrieved = pickle.load(fhandler) fhandler.close() self.assertEqual(retrieved, {})