diff options
author | Jon Bernard <jbernard@jbernard.io> | 2019-01-20 11:18:56 -0500 |
---|---|---|
committer | Jon Bernard <jbernard@jbernard.io> | 2019-03-05 10:16:06 -0500 |
commit | a0fb28975309f2ea4c355e1bdb013152be97042b (patch) | |
tree | 9d8d4d1121c4eba8eba1074c1d8c36f15132daee /tests/test_dotfile.py | |
parent | 174f42ea32529d25a7790ae956e891c6ac15a99a (diff) | |
download | dotfiles-a0fb28975309f2ea4c355e1bdb013152be97042b.tar.gz dotfiles-a0fb28975309f2ea4c355e1bdb013152be97042b.tar.bz2 dotfiles-a0fb28975309f2ea4c355e1bdb013152be97042b.zip |
Finish migration from py.path to pathlib
Diffstat (limited to 'tests/test_dotfile.py')
-rw-r--r-- | tests/test_dotfile.py | 108 |
1 files changed, 58 insertions, 50 deletions
diff --git a/tests/test_dotfile.py b/tests/test_dotfile.py index 5672c53..d992bdb 100644 --- a/tests/test_dotfile.py +++ b/tests/test_dotfile.py @@ -2,26 +2,27 @@ import pytest from pathlib import Path from dotfiles.dotfile import Dotfile -from dotfiles.exceptions import IsSymlink, NotASymlink, TargetExists, \ - TargetMissing, Exists +from dotfiles.pathutils import is_file, is_link, touch, mkdir +from dotfiles.exceptions import TargetExists, IsSymlink, \ + TargetMissing, NotASymlink, Exists def _make_dotfile(repo, name, target=None): - return Dotfile(repo.homedir.join(name), - repo.path.join(target if target is not None else name)) + return Dotfile(repo.homedir.joinpath(name), + repo.path.joinpath(target if target else name)) @pytest.mark.parametrize('name', ['.a']) def test_str(repo, name): dotfile = _make_dotfile(repo, name, '.b') - assert str(dotfile) == repo.homedir.join(name) + assert dotfile.name == repo.homedir / name @pytest.mark.parametrize('name', ['.foo']) def test_short_name(repo, name): dotfile = _make_dotfile(repo, name) - assert dotfile.name == repo.homedir.join(name) - assert dotfile.short_name(repo.homedir) == name + assert dotfile.name == repo.homedir / name + assert dotfile.short_name(repo.homedir) == Path(name) def test_is_present(repo): @@ -30,77 +31,81 @@ def test_is_present(repo): # TODO: more -# {{{1 state def test_state(repo): dotfile = _make_dotfile(repo, '.vimrc', 'vimrc') assert dotfile.state == 'error' - dotfile.target.ensure() - dotfile.name.mksymlinkto(dotfile.target) + dotfile.target.touch() + dotfile.name.symlink_to(dotfile.target) assert dotfile.state == 'ok' - dotfile.name.remove() + dotfile.name.unlink() assert dotfile.state == 'missing' - dotfile.name.ensure() + dotfile.name.touch() assert dotfile.state == 'ok' - dotfile.name.write('test content') + dotfile.name.write_text('test content') assert dotfile.state == 'conflict' - dotfile.target.write('test content') + dotfile.target.write_text('test content') assert dotfile.state == 'ok' -# {{{1 add @pytest.mark.parametrize('path', ['.foo', '.foo/bar/baz']) def test_add(repo, path): dotfile = _make_dotfile(repo, path) - dotfile.target.ensure() - dotfile.name.ensure() + + touch(dotfile.name) + touch(dotfile.target) with pytest.raises(TargetExists): dotfile.add() + dotfile.target.unlink() - dotfile.target.remove() dotfile.add() - - assert dotfile.target.check(file=1, link=0) - assert dotfile.name.check(file=1, link=1) + assert is_link(dotfile.name) + assert is_file(dotfile.target) assert dotfile.name.samefile(dotfile.target) with pytest.raises(IsSymlink): dotfile.add() - - assert dotfile.target.check(file=1, link=0) - assert dotfile.name.check(file=1, link=1) + assert is_file(dotfile.target) assert dotfile.name.samefile(dotfile.target) -# {{{1 remove @pytest.mark.parametrize('path', ['.foo', '.foo/bar/baz']) def test_remove(repo, path): dotfile = _make_dotfile(repo, path) - py.path.local(dotfile.name.dirname).ensure_dir() - dotfile.name.mksymlinkto(dotfile.target) + + # py.path.local(dotfile.name.dirname).ensure_dir() + # dotfile.name.mksymlinkto(dotfile.target) + # dotfile.name.parent.mkdir(parents=True) + mkdir(dotfile.name.parent) + dotfile.name.symlink_to(dotfile.target) with pytest.raises(TargetMissing): dotfile.remove() - dotfile.target.ensure() + # dotfile.target.ensure() + # dotfile.target.touch() + touch(dotfile.target) dotfile.remove() - assert dotfile.target.check(exists=0) - assert dotfile.name.check(file=1, link=0) + # assert dotfile.target.check(exists=0) + # assert dotfile.name.check(file=1, link=0) + assert not dotfile.target.exists() + assert is_file(dotfile.name) with pytest.raises(NotASymlink): dotfile.remove() - assert dotfile.target.check(exists=0) - assert dotfile.name.check(file=1, link=0) + # assert dotfile.target.check(exists=0) + # assert dotfile.name.check(file=1, link=0) + assert not dotfile.target.exists() + assert is_file(dotfile.name) -# {{{1 link @pytest.mark.parametrize('path', ['.foo', '.foo/bar/baz']) def test_link(repo, path): dotfile = _make_dotfile(repo, path) @@ -108,22 +113,21 @@ def test_link(repo, path): with pytest.raises(TargetMissing): dotfile.link() - dotfile.target.ensure() + touch(dotfile.target) dotfile.link() - assert dotfile.target.check(file=1, link=0) - assert dotfile.name.check(file=1, link=1) + assert is_file(dotfile.target) + assert is_link(dotfile.name) assert dotfile.name.samefile(dotfile.target) with pytest.raises(Exists): dotfile.link() - assert dotfile.target.check(file=1, link=0) - assert dotfile.name.check(file=1, link=1) + assert is_file(dotfile.target) + assert is_link(dotfile.name) assert dotfile.name.samefile(dotfile.target) -# {{{1 unlink @pytest.mark.parametrize('path', ['.foo', '.foo/bar/baz']) def test_unlink(repo, path): dotfile = _make_dotfile(repo, path) @@ -131,26 +135,30 @@ def test_unlink(repo, path): with pytest.raises(NotASymlink): dotfile.unlink() - py.path.local(dotfile.name.dirname).ensure_dir() - dotfile.name.mksymlinkto(dotfile.target) + # py.path.local(dotfile.name.dirname).ensure_dir() + # dotfile.name.mksymlinkto(dotfile.target) + mkdir(dotfile.name.parent) + dotfile.name.symlink_to(dotfile.target) with pytest.raises(TargetMissing): dotfile.unlink() - dotfile.target.ensure() + # dotfile.target.ensure() + touch(dotfile.target) dotfile.unlink() - assert dotfile.target.check(file=1, link=0) - assert dotfile.name.check(exists=0) + assert is_file(dotfile.target) + assert not dotfile.name.exists() with pytest.raises(NotASymlink): dotfile.unlink() - assert dotfile.target.check(file=1, link=0) - assert dotfile.name.check(exists=0) + assert is_file(dotfile.target) + assert not dotfile.name.exists() -# {{{1 copy -# @pytest.mark.parametrize('path', ['.foo', '.foo/bar/baz']) -# def test_unlink(repo, path): -# dotfile = _make_dotfile(repo, path) +@pytest.mark.parametrize('path', ['.foo', '.foo/bar/baz']) +def test_copy(repo, path): + pass + # dotfile = _make_dotfile(repo, path) + # TODO |