示例#1
0
def test_symlink_conflict_replace(df_paths: FixturePaths, settings: Settings):
    s = attr.evolve(settings, conflicting_symlink_strategy='replace')
    bashrcpath = df_paths.home_dir.joinpath('.bashrc')
    link_data = "settings/dotfiles/WHAT"
    bashrcpath.symlink_to(link_data)
    apply_settings(s)
    assert os.readlink(bashrcpath) == "settings/dotfiles/bashrc"
示例#2
0
def test_detect_symlink_loops(df_paths: FixturePaths, settings: Settings):
    bashrcpath = df_paths.home_dir.joinpath('.bashrc')
    base_bashrc = df_paths.dotfiles_dir.joinpath('bashrc')
    bashrcpath.symlink_to("evil_link")
    df_paths.home_dir.joinpath('evil_link').symlink_to('.bashrc')

    with pytest.raises(TooManySymbolicLinks):
        apply_settings(settings)
示例#3
0
def test_symlink_conflict_fail(df_paths: FixturePaths, settings: Settings):
    s = attr.evolve(settings, conflicting_symlink_strategy='fail')
    bashrcpath = df_paths.home_dir.joinpath('.bashrc')
    link_data = "settings/dotfiles/WHAT"
    bashrcpath.symlink_to(link_data)

    with pytest.raises(FatalConflict):
        apply_settings(s)

    assert os.readlink(bashrcpath) == link_data
示例#4
0
def test_file_conflict_fail(df_paths: FixturePaths, settings: Settings):
    s = attr.evolve(settings, conflicting_file_strategy='fail')
    bashrcpath = df_paths.home_dir.joinpath('.bashrc')
    contents = 'export THIS_IS_ONE=1'
    bashrcpath.write_text(contents, encoding='utf8')

    with pytest.raises(FatalConflict):
        apply_settings(s)

    assert bashrcpath.read_text(encoding='utf8') == contents
示例#5
0
def test_file_conflict_delete(df_paths: FixturePaths, settings: Settings):
    s = attr.evolve(settings, conflicting_file_strategy='delete')
    bashrcpath = df_paths.home_dir.joinpath('.bashrc')
    contents = 'export THIS_IS_ONE=1'
    bashrcpath.write_text(contents, encoding='utf8')
    apply_settings(s)

    backup: List[Path] = list(df_paths.home_dir.glob('.bashrc.dfi_*'))
    assert len(backup) == 0
    assert bashrcpath.read_text() == "file: bashrc"
示例#6
0
def test_file_conflict_backup(df_paths: FixturePaths, settings: Settings):
    s = settings
    bashrcpath = df_paths.home_dir.joinpath('.bashrc')
    contents = 'export YOUR_MOM=1'
    bashrcpath.write_text(contents, encoding='utf8')
    apply_settings(s)

    backup: List[Path] = list(df_paths.home_dir.glob('.bashrc.dfi_*'))
    assert len(backup) > 0

    assert backup[0].read_text() == contents
示例#7
0
def test_backup_failed(df_paths: FixturePaths, settings: Settings,
                       monkeypatch):
    def timestamp():
        return "itstime"

    monkeypatch.setattr(fs, 'timestamp', timestamp)
    bashrcpath = df_paths.home_dir.joinpath('.bashrc')
    for n in range(0, 100):
        bashrcpath.parent.joinpath(f".bashrc.dfi_itstime_{n:03}").touch()
    bashrcpath.touch()

    with pytest.raises(BackupFailed):
        apply_settings(settings)
示例#8
0
def test_symlink_conflict_warn(df_paths: FixturePaths, settings: Settings,
                               caplog):
    s = attr.evolve(settings, conflicting_symlink_strategy='warn')
    bashrcpath = df_paths.home_dir.joinpath('.bashrc')
    link_data = "settings/dotfiles/WHAT"
    bashrcpath.symlink_to(link_data)
    apply_settings(s)
    assert os.readlink(bashrcpath) == link_data

    rtup: Sequence[Tuple[str, int, str]] = caplog.record_tuples
    assert len(rtup) >= 1
    file, line, msg = next((t for t in rtup if t[0] == "dfi.fs"))

    assert msg.startswith("File location")
    assert msg.endswith("'warn' strategy selected, continuing.")
示例#9
0
def test_file_conflict_warn(df_paths: FixturePaths, settings: Settings,
                            caplog: Any):
    s = attr.evolve(settings, conflicting_file_strategy='warn')
    bashrcpath = df_paths.home_dir.joinpath('.bashrc')
    contents = 'export THIS_IS_ONE=1'
    bashrcpath.write_text(contents, encoding='utf8')
    apply_settings(s)

    rtup: Sequence[Tuple[str, int, str]] = caplog.record_tuples
    assert len(rtup) >= 1
    file, line, msg = next((t for t in rtup if t[0] == "dfi.fs"))
    assert file == "dfi.fs"
    assert msg.startswith("File location")
    assert msg.endswith("'warn' strategy selected, continuing.")
    assert bashrcpath.read_text(encoding='utf8') == contents
示例#10
0
def test_Settings_install(df_paths: FixturePaths, settings: Settings):
    s = settings
    apply_settings(s)
    print(df_paths.home_dir)

    print(df_paths.home_dir.glob("*"))

    for df in ['.bash_profile', '.bashrc', '.inputrc', '.tux', '.vimrc']:
        link_location = df_paths.home_dir.joinpath(df)
        assert link_location.exists()
        assert link_location.is_symlink()

    for bin in ['ctags', 'pants', 'pip']:
        link_location = df_paths.home_dir.joinpath('.local', 'bin', bin)
        assert link_location.exists()
        assert link_location.is_symlink()
示例#11
0
def test_filesystem_conflict_error_ie_wtf_is_that_node(df_paths: FixturePaths,
                                                       settings: Settings):
    bashrcpath = df_paths.home_dir.joinpath('.bashrc')
    os.mkfifo(bashrcpath)
    with pytest.raises(FilesystemConflictError):
        apply_settings(settings)