aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jon Bernard <jbernard@tuxion.com> 2016-01-20 11:23:39 -0500
committerGravatar Jon Bernard <jbernard@tuxion.com> 2016-01-20 11:23:39 -0500
commiteb5902c00a8b41e2bb6b0710e33004c2340c9319 (patch)
treed09831a97d2372204782c4b2bf04d41633a23d4b
parent874058788bdc2b599fa00b59dea7989775180584 (diff)
downloaddotfiles-eb5902c00a8b41e2bb6b0710e33004c2340c9319.tar.gz
dotfiles-eb5902c00a8b41e2bb6b0710e33004c2340c9319.tar.bz2
dotfiles-eb5902c00a8b41e2bb6b0710e33004c2340c9319.zip
Finish basic repository unit tests
-rw-r--r--tests/test_repository.py93
1 files changed, 62 insertions, 31 deletions
diff --git a/tests/test_repository.py b/tests/test_repository.py
index 24420fa..4cf694f 100644
--- a/tests/test_repository.py
+++ b/tests/test_repository.py
@@ -1,15 +1,15 @@
+import py
import pytest
from dotfiles.repository import Repository
+from dotfiles.exceptions import NotRootedInHome, InRepository, TargetIgnored, \
+ IsDirectory
-def test_init(repo, home):
+def test_repo_create(repo, home):
repo.remove()
assert repo.check(exists=0)
-
- r = Repository(repo, home)
- assert r.repodir == repo
- assert r.homedir == home
+ Repository(repo, home)
assert repo.check(exists=1, dir=1)
@@ -20,41 +20,67 @@ def test_str(repo, home):
r = Repository(repo, home)
- assert str(r) == ('%s\n%s\n%s' % (home.join('.a'),
- home.join('.b'),
- home.join('.c')))
+ assert str(r) == (
+ '%s\n%s\n%s' % (home.join('.a'),
+ home.join('.b'),
+ home.join('.c')))
-def test_repr(repo):
- actual = '%r' % Repository(repo, None)
- expected = '<Repository local(\'%s\')>' % repo
- assert actual == expected
+@pytest.mark.parametrize('path', ['.foo', '.foo/bar/baz'])
+def test_target_to_name(repo, home, path):
+ r = Repository(repo, home, dot=True)
+ assert r._target_to_name(repo.join(path)) == home.join(path)
+ r = Repository(repo, home, dot=False)
+ assert r._target_to_name(repo.join(path)) == home.join('.%s' % path)
-def test_target_to_name(repo, home):
- actual = Repository(repo, home)._target_to_name(repo.join('.foo'))
- expected = home.join('.foo')
- assert actual == expected
+@pytest.mark.parametrize('path', ['.foo', '.foo/bar/baz'])
+def test_name_to_target(repo, home, path):
+ r = Repository(repo, home, dot=True)
+ assert r._name_to_target(home.join(path)) == repo.join(path)
-def test_name_to_target(repo, home):
- actual = Repository(repo, home)._name_to_target(home.join('.foo'))
- expected = repo.join('.foo')
- assert actual == expected
+ r = Repository(repo, home, dot=False)
+ assert r._name_to_target(home.join(path)) == repo.join(path[1:])
-@pytest.mark.xfail(reason='TODO')
-def test_dotfile():
- assert False
+def test_dotfile(repo, home):
+ with pytest.raises(NotRootedInHome):
+ Repository(repo, home)._dotfile(py.path.local('/tmp/foo'))
+ with pytest.raises(TargetIgnored):
+ Repository(repo, home, ignore=['.foo'])._dotfile(home.join('.foo'))
+ with pytest.raises(TargetIgnored):
+ Repository(repo, home, ignore=['foo'])._dotfile(home.join('.bar/foo'))
+ with pytest.raises(IsDirectory):
+ Repository(repo, home)._dotfile(home.ensure_dir('.config'))
+ # The home fixture is parametrized, we can only expect InRepository
+ # exception when the repository is contained in the home directory.
+ if repo.dirname == home.basename:
+ with pytest.raises(InRepository):
+ Repository(repo, home)._dotfile(repo.join('.foo/bar'))
-def test_contents(repo, home):
+ Repository(repo, home)._dotfile(home.join('.foo'))
+
+
+def test_dotfiles(repo, home):
+ file = home.join('.baz')
+ dir = home.ensure_dir('.dir')
+ dir.ensure('foo/bat')
+ dir.ensure('foo/buz')
+ dir.ensure('bar')
+ dir.ensure('boo')
+
+ dotfiles = Repository(repo, home).dotfiles([str(file), str(dir)])
+ assert len(dotfiles) == 5
+
+def test_contents(repo, home):
assert Repository(repo, home).contents() == []
target_a = repo.ensure('a')
- target_b = repo.ensure('b')
- target_c = repo.ensure('c')
+ target_b = repo.ensure('b/b')
+ target_c = repo.ensure('c/c/c')
contents = Repository(repo, home).contents()
assert contents[0].target == target_a
@@ -62,9 +88,14 @@ def test_contents(repo, home):
assert contents[2].target == target_c
-def test_nested_name_to_target(repo, home):
- r = Repository(repo, home)
+# TODO: Need tests for whatever-dot option
+
+
+def test_prune(repo, home):
+ repo.ensure_dir('.a/a')
+ repo.ensure_dir('.b/b/b/b')
+ repo.ensure_dir('.c/c/c/c/c/c/c/c')
+
+ Repository(repo, home).prune()
- actual = r._name_to_target(home.join('.vim/.mrconfig'))
- expected = repo.join('.vim/.mrconfig')
- assert actual == expected
+ assert len(repo.listdir()) == 0