def test_save_rollover(self):
        # Write some stuff to the state
        state['a'] = (-1) ** 2
        state['b'] = (-1) ** 3
        state['c'] = 41

        with tempfile.NamedTemporaryFile() as temp:
            # Save original state
            state.save(temp.name, rotate_n_state_files=2)

            for i in range(10):
                # Write bogus info to state
                state['a'] = i ** 2
                state['b'] = i ** 3
                state['c'] = 42 + i

                state.save(temp.name, rotate_n_state_files=2)

                # Load last file and check contents
                state.load(temp.name + ".1", lazy=True)
                self.assertEqual(state['a'], (i - 1) ** 2)
                self.assertEqual(state['b'], (i - 1) ** 3)
                self.assertEqual(state['c'], 42 + (i - 1))

                if i > 0:
                    # Load previous to last file and check contents
                    state.load(temp.name + ".2", lazy=True)
                    self.assertEqual(state['a'], (i - 2) ** 2)
                    self.assertEqual(state['b'], (i - 2) ** 3)
                    self.assertEqual(state['c'], 42 + (i - 2))

                # Load current state and check contents
                state.load(temp.name, lazy=True)
                self.assertEqual(state['a'], i ** 2)
                self.assertEqual(state['b'], i ** 3)
                self.assertEqual(state['c'], 42 + i)

            # Remove temp files
            os.remove(temp.name + ".1")
            os.remove(temp.name + ".2")
Test saving file with rollover
dataset/ETHPy150Open duerrp/pyexperiment/tests/test_state.py/TestStateIO.test_save_rollover