예제 #1
0
    def test(c):
        with tempdir() as tmp:
            state_path = os.path.join(tmp, const.STATE_DIR)
            if c.previous:
                # setup previous state
                m = Mocker()
                app = Application(tmp)
                mock_windows(m.method(app.iter_windows), c.previous)
                with m:
                    app.save_window_states()
                assert os.listdir(state_path), state_path

            m = Mocker()
            app = Application(tmp)
            mock_windows(m.method(app.iter_windows), c.windows)
            with m:
                app.save_window_states()
            assert os.path.isdir(state_path), state_path
            states = sorted(set(os.listdir(state_path)) - {const.CLOSED_DIR})
            eq_(len(states), len(c.windows), states)
            for ident, state in zip(c.windows, states):
                with open(os.path.join(state_path, state)) as f:
                    eq_(load_yaml(f), [ident])
예제 #2
0
 def test(states, error=None):
     with tempdir() as tmp:
         state_path = os.path.join(tmp, const.STATE_DIR)
         if states:
             # setup previous state
             m = Mocker()
             app = Application(tmp)
             def iter_windows():
                 for ident in states:
                     yield TestConfig(state=[ident])
             m.method(app.iter_windows)() >> iter_windows()
             with m:
                 app.save_window_states()
             assert os.listdir(state_path), state_path
             if error is not None:
                 fail_path = os.path.join(
                     state_path, const.EDITOR_STATE.format(error))
                 with open(fail_path, "w") as fh:
                     fh.write('!!invalid "yaml"')
         app = Application(tmp)
         result = list(app.iter_saved_window_states())
         eq_(result, [[id] if error != i else mod.StateLoadFailure(fail_path)
                      for i, id in enumerate(states)])