def try_recover_from_autosave(self): """Offer to recover files from autosave.""" autosave_dir = get_conf_path('autosave') autosave_mapping = CONF.get('editor', 'autosave_mapping', {}) dialog = RecoveryDialog(autosave_dir, autosave_mapping, parent=self.editor) dialog.exec_if_nonempty() self.recover_files_to_open = dialog.files_to_open[:]
def test_recoverydialog_exec_if_nonempty_when_nonempty( qtbot, recovery_env, mocker): """Test that exec_if_nonempty executes dialog if autosave dir not empty.""" orig_dir, autosave_dir, autosave_mapping = recovery_env dialog = RecoveryDialog(autosave_dir, autosave_mapping) mocker.patch.object(dialog, 'exec_', return_value='eggs') assert dialog.exec_if_nonempty() == 'eggs' assert dialog.exec_.called
def try_recover_from_autosave(self): """ Offer to recover files from autosave. Read pid files to get a list of files that can possibly be recovered, then ask the user what to do with these files, and finally remove the pid files. """ files_to_recover, pidfiles = self.get_files_to_recover() dialog = RecoveryDialog(files_to_recover, parent=self.editor) dialog.exec_if_nonempty() self.recover_files_to_open = dialog.files_to_open[:] for pidfile in pidfiles: try: os.remove(pidfile) except (IOError, OSError): pass
def test_recoverydialog_exec_if_nonempty_when_empty(qtbot, tmpdir, mocker): """ Test that exec_if_nonempty does nothing if autosave dir is empty. Specifically, test that it does not `exec_()` the dialog. """ dialog = RecoveryDialog(str(tmpdir), {'ham': 'spam'}) mocker.patch.object(dialog, 'exec_') assert dialog.exec_if_nonempty() == dialog.Accepted dialog.exec_.assert_not_called()
def test_recoverydialog_exec_if_nonempty_when_no_autosave_dir( qtbot, recovery_env, mocker): """ Test that exec_if_nonempty does nothing if autosave dir does not exist. Specifically, test that it does not `exec_()` the dialog. """ orig_dir, autosave_dir, autosave_mapping = recovery_env shutil.rmtree(autosave_dir) dialog = RecoveryDialog(autosave_dir, autosave_mapping) mocker.patch.object(dialog, 'exec_') assert dialog.exec_if_nonempty() == dialog.Accepted dialog.exec_.assert_not_called()