def test_need_saving(self): """Test the state.need_saving method """ self._setup_basic_state() self.assertTrue(state.need_saving()) with tempfile.NamedTemporaryFile() as temp: state.save(temp.name) self.assertFalse(state.need_saving()) state['list'] = 'foo2' self.assertTrue(state.need_saving())
def test_no_unnecessary_save(self): """Test saving the state only saves when necessary """ self.assertFalse(state.need_saving()) with tempfile.NamedTemporaryFile() as temp: state.save(temp.name) self.assertEqual(os.stat(temp.name).st_size, 0) self.assertFalse(state.need_saving()) state['bla'] = 'bla' self.assertTrue(state.need_saving()) with tempfile.NamedTemporaryFile() as temp: state.save(temp.name) self.assertNotEqual(os.stat(temp.name).st_size, 0) self.assertFalse(state.need_saving())
def test_no_unnecessary_save_lazy(self): """Test saving the state does not save just after loading lazily """ self.assertFalse(state.need_saving()) state['bla'] = 'bla' self.assertTrue(state.need_saving()) with tempfile.NamedTemporaryFile() as temp: state.save(temp.name) self.assertFalse(state.need_saving()) state.reset_instance() self.assertFalse(state.need_saving()) state.load(temp.name, lazy=True) self.assertFalse(state.need_saving()) self.assertEqual(state['bla'], 'bla') self.assertFalse(state.need_saving())