def test_autosave_remove_autosave_file(mocker, exception): """Test that AutosaveForStack.remove_autosave_file removes the autosave file and that an error dialog is displayed if an exception is raised.""" mock_remove = mocker.patch('os.remove') if exception: mock_remove.side_effect = EnvironmentError() mock_dialog = mocker.patch( 'spyder.plugins.editor.utils.autosave.AutosaveErrorDialog') mock_stack = mocker.Mock() fileinfo = mocker.Mock() fileinfo.filename = 'orig' addon = AutosaveForStack(mock_stack) addon.name_mapping = {'orig': 'autosave'} addon.remove_autosave_file(fileinfo) mock_remove.assert_called_with('autosave') assert mock_dialog.called == exception
def test_autosave_remove_autosave_file(mocker, exception): """Test that AutosaveForStack.remove_autosave_file removes the autosave file, that an error dialog is displayed if an exception is raised, and that the autosave file is removed from `name_mapping` and `file_hashes`.""" mock_remove = mocker.patch('os.remove') if exception: mock_remove.side_effect = OSError() mock_dialog = mocker.patch( 'spyder.plugins.editor.utils.autosave.AutosaveErrorDialog') mock_stack = mocker.Mock() fileinfo = mocker.Mock() fileinfo.filename = 'orig' addon = AutosaveForStack(mock_stack) addon.name_mapping = {'orig': 'autosave'} addon.file_hashes = {'autosave': 42} addon.remove_autosave_file(fileinfo.filename) assert addon.name_mapping == {} assert addon.file_hashes == {} mock_remove.assert_any_call('autosave') assert mock_dialog.called == exception