aboutsummaryrefslogtreecommitdiffstats
path: root/test_dotfiles.py
diff options
context:
space:
mode:
authorGravatar Jon Bernard <jbernard@tuxion.com> 2016-01-03 17:36:22 -0500
committerGravatar Jon Bernard <jbernard@tuxion.com> 2016-01-03 22:39:43 -0500
commitad3e6a6d4456ffdf4c26deac7e06aa35d487f92e (patch)
tree7a02bda439088399d84794eba9d960e24b026e29 /test_dotfiles.py
parentfce79366e1f1d48fd962dcb9d65a8ed4dc551643 (diff)
downloaddotfiles-ad3e6a6d4456ffdf4c26deac7e06aa35d487f92e.tar.gz
dotfiles-ad3e6a6d4456ffdf4c26deac7e06aa35d487f92e.tar.bz2
dotfiles-ad3e6a6d4456ffdf4c26deac7e06aa35d487f92e.zip
Use test fixtures and some cleanup
Diffstat (limited to 'test_dotfiles.py')
-rw-r--r--test_dotfiles.py237
1 files changed, 71 insertions, 166 deletions
diff --git a/test_dotfiles.py b/test_dotfiles.py
index e0ebc77..cea1446 100644
--- a/test_dotfiles.py
+++ b/test_dotfiles.py
@@ -1,182 +1,92 @@
import py
import pytest
-from click.testing import CliRunner
-from dotfiles import __version__
-from dotfiles import Repository
-from dotfiles import Dotfile, unique_suffix
-from dotfiles import version
+from dotfiles import cli, unique_suffix
+from dotfiles import Repository, Dotfile
-class TestCLI(object):
+def test_unique_suffix_overlap():
+ (name, target) = unique_suffix(py.path.local('/foo/baz'),
+ py.path.local('/foo/bar/bat'))
+ assert name == 'baz'
+ assert target == 'bar/bat'
- def test_version(self):
- runner = CliRunner()
- result = runner.invoke(version)
- assert ('dotfiles version %s\n' % __version__) == result.output
- """
- @pytest.mark.xfail()
- def test_empty_status(tmpdir):
- repo = Repository(tmpdir.join("repo"))
- assert '[no dotfiles found]' == repo.status()
+@pytest.mark.xfail(reason='this is a bug')
+def test_unique_suffix_no_overlap():
+ (name, target) = unique_suffix(py.path.local('/a/b/c'),
+ py.path.local('/d/e/f'))
+ assert name == '/a/b/c'
+ assert target == '/d/e/f'
- @pytest.mark.xfail()
- def test_status_manual(tmpdir, monkeypatch):
- repodir = tmpdir.join("Dotfiles", dir=1)
- target = repodir.ensure("vimrc")
- name = tmpdir.ensure(".vimrc")
+class TestCli(object):
- dotfile = Dotfile(name, target)
-
- repo = Repository(repodir, tmpdir)
- monkeypatch.setattr(Repository, "_load",
- lambda self: [dotfile, dotfile, dotfile])
-
- dotfile_state = 'conflict'
- expected_status = ("{0:<18} {1}\n"
- "{0:<18} {1}\n"
- "{0:<18} {1}".format(name.basename, dotfile_state))
-
- assert expected_status == repo.status()
-
- @pytest.mark.xfail()
- def test_status_discover(tmpdir):
-
- repodir = tmpdir.ensure("Dotfiles", dir=1)
-
- tmpdir.join('.bashrc').mksymlinkto(repodir.ensure('bashrc'))
- tmpdir.join('.inputrc').mksymlinkto(repodir.ensure('inputrc'))
- tmpdir.join('.vimrc').mksymlinkto(repodir.ensure('vimrc'))
-
- repo = Repository(repodir, tmpdir)
-
- expected_status = ("{1:<18} {0}\n"
- "{2:<18} {0}\n"
- "{3:<18} {0}".format('ok',
- '.bashrc',
- '.inputrc',
- '.vimrc'))
-
- assert expected_status == repo.status()
-
- @pytest.mark.xfail()
- def test_check(tmpdir, monkeypatch):
-
- repodir = tmpdir.join('repo')
-
- dotfile_a = Dotfile(tmpdir.join('.aaa'), repodir.join('aaa'))
- dotfile_b = Dotfile(tmpdir.join('.bbb'), repodir.join('bbb'))
- dotfile_c = Dotfile(tmpdir.join('.ccc'), repodir.join('ccc'))
-
- dotfile_b.state = 'ok'
-
- repo = Repository(tmpdir)
- monkeypatch.setattr(Repository, "_load",
- lambda self: [dotfile_a, dotfile_b, dotfile_c])
-
- expected_status = ("{1:<18} {0}\n"
- "{2:<18} {0}".format('error',
- dotfile_a.name.basename,
- dotfile_c.name.basename))
-
- assert expected_status == repo.check()
- """
+ def test_list_empty(self, runner, repo, home):
+ result = runner.invoke(cli, ['--home-directory', str(home),
+ '--repository', str(repo),
+ 'list'])
+ assert not result.exception
+ assert result.output == '[no dotfiles found]\n'
class TestRepository(object):
- def test_repodir_create(self, tmpdir):
- repodir = tmpdir.join('test_create_repo')
- repo = Repository(repodir, tmpdir)
+ def test_repodir_create(self, repo, home):
+ repo.remove()
+ assert repo.check(exists=0)
+ Repository(repo, home).contents()
+ assert repo.check(exists=1, dir=1)
- assert True == repodir.check(exists=0)
- repo.contents()
- assert True == repodir.check(exists=1, dir=1)
+ def test_contents_empty(self, repo, home):
+ assert Repository(repo, home).contents() == []
- def test_contents_empty(self, tmpdir):
- assert [] == Repository(tmpdir.join('Dotfiles'), tmpdir).contents()
+ def test_contents_nonempty(self, repo, home):
+ target_a = repo.ensure('a')
+ target_b = repo.ensure('b')
+ target_c = repo.ensure('c')
+ contents = Repository(repo, home).contents()
- def test_contents_nonempty(self, tmpdir):
- repodir = tmpdir.ensure('test_create_repo', dir=1)
- target_a = repodir.ensure('a')
- target_b = repodir.ensure('b')
- target_c = repodir.ensure('c')
-
- contents = Repository(repodir, tmpdir).contents()
-
- assert target_a == contents[0].target
- assert target_b == contents[1].target
- assert target_c == contents[2].target
+ assert contents[0].target == target_a
+ assert contents[1].target == target_b
+ assert contents[2].target == target_c
@pytest.mark.xfail(reason='not implemented yet')
def test_expected_name(self):
- assert 0
+ assert False
class TestDotfile(object):
- def test_unique_suffix_overlap(self):
- (name, target) = unique_suffix(py.path.local('/foo/baz'),
- py.path.local('/foo/bar/bat'))
- assert 'baz' == name
- assert 'bar/bat' == target
-
- @pytest.mark.xfail(reason='this is a bug')
- def test_unique_suffix_no_overlap(self):
- (name, target) = unique_suffix(py.path.local('/a/b/c'),
- py.path.local('/d/e/f'))
- assert '/a/b/c' == name
- assert '/d/e/f' == target
+ def test_state_error(self, repo, home):
+ dotfile = Dotfile(home.join('.vimrc'), repo.join('vimrc'))
+ assert dotfile.state == 'error'
- def test_state_error(self, tmpdir):
- repo = tmpdir.ensure("Dotfiles", dir=1)
- name = tmpdir.join(".vimrc")
- target = repo.join("vimrc")
-
- dotfile = Dotfile(name, target)
-
- assert 'error' == dotfile.state
-
- def test_state_missing(self, tmpdir):
- repo = tmpdir.ensure("Dotfiles", dir=1)
- name = tmpdir.join(".vimrc")
- target = repo.ensure("vimrc")
-
- dotfile = Dotfile(name, target)
+ def test_state_missing(self, repo, home):
+ dotfile = Dotfile(home.join('.vimrc'), repo.ensure('vimrc'))
+ assert dotfile.state == 'missing'
- assert 'missing' == dotfile.state
+ def test_state_conflict(self, repo, home):
+ dotfile = Dotfile(home.ensure('.vimrc'), repo.ensure('vimrc'))
+ assert dotfile.state == 'conflict'
- def test_state_conflict(self, tmpdir):
- repo = tmpdir.ensure("Dotfiles", dir=1)
- name = tmpdir.ensure(".vimrc")
- target = repo.ensure("vimrc")
+ def test_state_ok(self, repo, home):
+ name = home.join('.vimrc')
+ target = repo.ensure('vimrc')
dotfile = Dotfile(name, target)
-
- assert 'conflict' == dotfile.state
-
- def test_state_ok(self, tmpdir):
- repo = tmpdir.join("Dotfiles", dir=1)
- name = tmpdir.join(".vimrc")
- target = repo.ensure("vimrc")
- dotfile = Dotfile(name, target)
-
name.mksymlinkto(target)
- assert 'ok' == dotfile.state
+ assert dotfile.state == 'ok'
name.remove()
- assert 'missing' == dotfile.state
+ assert dotfile.state == 'missing'
- @pytest.mark.parametrize("times", range(1, 4))
- def test_add(self, tmpdir, times):
- repo = tmpdir.ensure("Dotfiles", dir=1)
- name = tmpdir.ensure(".vimrc")
- target = repo.join("vimrc")
+ @pytest.mark.parametrize('times', range(1, 4))
+ def test_add(self, repo, home, times):
+ name = home.ensure('.vimrc')
+ target = repo.join('vimrc')
- dotfile = Dotfile(name, target)
- dotfile.add()
+ Dotfile(name, target).add()
assert target.check(file=1, link=0)
assert name.check(file=1, link=1)
@@ -184,39 +94,34 @@ class TestDotfile(object):
for x in range(2, times):
with pytest.raises(OSError):
- dotfile.add()
+ Dotfile(name, target).add()
assert target.check(file=1, link=0)
assert name.check(file=1, link=1)
assert name.samefile(target)
- @pytest.mark.parametrize("times", range(1, 4))
- def test_remove(self, tmpdir, times):
- repo = tmpdir.ensure("Dotfiles", dir=1)
- name = tmpdir.join(".vimrc")
- target = repo.ensure("vimrc")
+ @pytest.mark.parametrize('times', range(1, 4))
+ def test_remove(self, repo, home, times):
+ name = home.join('.vimrc')
+ target = repo.ensure('vimrc')
name.mksymlinkto(target)
+ Dotfile(name, target).remove()
- dotfile = Dotfile(name, target)
- dotfile.remove()
-
- assert False == target.check()
+ assert not target.check()
assert name.check(file=1, link=0)
for x in range(2, times):
with pytest.raises(OSError):
- dotfile.remove()
- assert False == target.check()
+ Dotfile(name, target).remove()
+ assert not target.check()
assert name.check(file=1, link=0)
- @pytest.mark.parametrize("times", range(1, 4))
- def test_sync(self, tmpdir, times):
- repo = tmpdir.ensure("Dotfiles", dir=1)
- name = tmpdir.join(".vimrc")
- target = repo.ensure("vimrc")
+ @pytest.mark.parametrize('times', range(1, 4))
+ def test_sync(self, repo, home, times):
+ name = home.join('.vimrc')
+ target = repo.ensure('vimrc')
- dotfile = Dotfile(name, target)
- dotfile.sync()
+ Dotfile(name, target).sync()
assert target.check(file=1, link=0)
assert name.check(file=1, link=1)
@@ -224,11 +129,11 @@ class TestDotfile(object):
for x in range(2, times):
with pytest.raises(py.error.EEXIST):
- dotfile.sync()
+ Dotfile(name, target).sync()
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')
def test_unsync(self):
- assert 0
+ assert False