diff options
-rw-r--r-- | dotfiles.py | 3 | ||||
-rw-r--r-- | test_dotfiles.py | 71 |
2 files changed, 59 insertions, 15 deletions
diff --git a/dotfiles.py b/dotfiles.py index 233d37e..f868d5b 100644 --- a/dotfiles.py +++ b/dotfiles.py @@ -17,7 +17,7 @@ class Repository(object): """ def __init__(self, repodir, homedir): - self.repodir = repodir + self.repodir = repodir.ensure(dir=1) self.homedir = homedir def __str__(self): @@ -69,7 +69,6 @@ class Repository(object): def contents(self): """Return a list of all dotfiles in the repository path.""" contents = [] - self.repodir.ensure(dir=1) for target in self.repodir.listdir(): target = py.path.local(target) contents.append(Dotfile(self._target_to_name(target), target)) diff --git a/test_dotfiles.py b/test_dotfiles.py index 1bb9a07..adefdb2 100644 --- a/test_dotfiles.py +++ b/test_dotfiles.py @@ -1,4 +1,3 @@ -import py import pytest from dotfiles import Repository, Dotfile, cli @@ -6,6 +5,14 @@ from dotfiles import Repository, Dotfile, cli class TestCli(object): + @pytest.mark.xfail(reason='TODO') + def test_add(self): + assert False + + @pytest.mark.xfail(reason='TODO') + def test_remove(self): + assert False + def test_status(self, runner, repo, home): result = runner.invoke(cli, ['--home-directory', str(home), '--repository', str(repo), @@ -13,19 +20,59 @@ class TestCli(object): assert not result.exception assert result.output == '' + # TODO: can do better than this + + @pytest.mark.xfail(reason='TODO') + def test_link(self): + assert False + + @pytest.mark.xfail(reason='TODO') + def test_unlink(self): + assert False + class TestRepository(object): - def test_repodir_create(self, repo, home): + def test_init(self, repo, home): repo.remove() assert repo.check(exists=0) - Repository(repo, home).contents() + + r = Repository(repo, home) + assert r.repodir == repo + assert r.homedir == home assert repo.check(exists=1, dir=1) - def test_contents_empty(self, repo, home): + def test_str(self, repo, home): + repo.ensure('a') + repo.ensure('b') + repo.ensure('c') + assert str(Repository(repo, home)) == ('.a\n' + '.b\n' + '.c') + + def test_repr(self, repo): + actual = '%r' % Repository(repo, None) + expected = '<Repository local(\'%s\')>' % repo + assert actual == expected + + def test_target_to_name(self, repo, home): + actual = Repository(repo, home)._target_to_name(repo.join('foo')) + expected = home.join('.foo') + assert actual == expected + + def test_name_to_target(self, repo, home): + actual = Repository(repo, home)._name_to_target(home.join('.foo')) + expected = repo.join('foo') + assert actual == expected + + @pytest.mark.xfail(reason='TODO') + def test_dotifle(self): + assert False + + def test_contents(self, repo, home): + assert Repository(repo, home).contents() == [] - def test_contents_nonempty(self, repo, home): target_a = repo.ensure('a') target_b = repo.ensure('b') target_c = repo.ensure('c') @@ -35,11 +82,6 @@ class TestRepository(object): assert contents[1].target == target_b assert contents[2].target == target_c - def test_expected_name(self, repo, home): - actual = Repository(repo, home).expected_name(repo.join('foo')) - expected = home.join('.foo') - assert actual == expected - class TestDotfile(object): @@ -79,6 +121,7 @@ class TestDotfile(object): for x in range(2, times): with pytest.raises(OSError): + # TODO: verify exception type once those exists Dotfile(name, target).add() assert target.check(file=1, link=0) assert name.check(file=1, link=1) @@ -96,7 +139,8 @@ class TestDotfile(object): assert name.check(file=1, link=0) for x in range(2, times): - with pytest.raises(OSError): + with pytest.raises(Exception): + # TODO: verify exception type once those exists Dotfile(name, target).remove() assert not target.check() assert name.check(file=1, link=0) @@ -113,12 +157,13 @@ class TestDotfile(object): assert name.samefile(target) for x in range(2, times): - with pytest.raises(py.error.EEXIST): + with pytest.raises(Exception): + # TODO: verify exception type once those exists Dotfile(name, target).link() assert target.check(file=1, link=0) assert name.check(file=1, link=1) assert name.samefile(target) - @pytest.mark.xfail(reason='not implemented yet') + @pytest.mark.xfail(reason='TODO') def test_unlink(self): assert False |