Esempio n. 1
0
def test_save_autosave_mapping_with_nonempty_mapping(mocker, tmpdir):
    """Test that save_autosave_mapping() writes the current autosave mapping
    to the correct file if the mapping is not empty."""
    mocker.patch('os.getpid', return_value=42)
    mocker.patch('spyder.plugins.editor.utils.autosave.get_conf_path',
                 return_value=str(tmpdir))
    addon = AutosaveForStack(None)
    addon.name_mapping = {'orig': 'autosave'}

    addon.save_autosave_mapping()

    pidfile = tmpdir.join('pid42.txt')
    assert ast.literal_eval(pidfile.read()) == addon.name_mapping
Esempio n. 2
0
def test_save_autosave_mapping_with_empty_mapping(mocker, tmpdir,
                                                  pidfile_exists):
    """Test that save_autosave_mapping() does not write the pidfile if the
    mapping is empty, and that is removes the pidfile if it exists."""
    mocker.patch('os.getpid', return_value=42)
    mocker.patch('spyder.plugins.editor.utils.autosave.get_conf_path',
                 return_value=str(tmpdir))
    addon = AutosaveForStack(None)
    addon.name_mapping = {}
    pidfile = tmpdir.join('pid42.txt')
    if pidfile_exists:
        pidfile.write('This is an ex-parrot!')

    addon.save_autosave_mapping()

    assert not pidfile.check()