예제 #1
0
    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())
예제 #2
0
    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())
예제 #3
0
    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())
예제 #4
0
    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())
예제 #5
0
    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())
예제 #6
0
    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())