def test_keys(self): """Test getting the keys in a state """ self._setup_basic_state() self.assertEqual(len(state.keys()), 3) self.assertIn('list', state.keys()) self.assertIn('dict', state.keys()) self.assertIn('values.int', state.keys())
def test_lazy_really_lazy(self): """Test lazy loading is really lazy """ self._setup_basic_state() temp = tempfile.NamedTemporaryFile(delete=False) temp2 = tempfile.NamedTemporaryFile(delete=False) state.save(temp.name) # Write bogus info to state state['list'] = 'foo' state['values.int'] = 43 # This should only load the keys state.load(temp.name, lazy=True) self.assertEqual(len(state.keys()), 3) # This should raise an error shutil.move(temp.name, temp2.name) self.assertRaises(IOError, state.__getitem__, 'list') shutil.copyfile(temp2.name, temp.name) # Now it should work list_val = state['list'] self.assertEqual(self.list_val, list_val) # This should raise another error shutil.move(temp.name, temp2.name) self.assertRaises(IOError, state.__getitem__, 'values.int') shutil.copyfile(temp2.name, temp.name) # This should work again int_val = state['values.int'] self.assertEqual(self.int_val, int_val) os.remove(temp.name) os.remove(temp2.name)
def test_empty_keys(self): """Test getting the keys in an empty state """ self.assertEqual(len(state.keys()), 0)
def test_delete_removes_key(self): """Test deleting a value from the state removes the item """ self._setup_basic_state() del state['list'] self.assertNotIn('list', state.keys())