aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jon Bernard <jbernard@tuxion.com> 2015-12-31 11:23:42 -0500
committerGravatar Jon Bernard <jbernard@tuxion.com> 2015-12-31 11:25:04 -0500
commitc91c4c58ea7a85986feaae2528f84ea53995c45d (patch)
tree24885ccbcb35d1b1060b0cb9c97952cb5a47703b
parent9dbf216aee8de31af987231a10d2b4b17a67cdfa (diff)
downloaddotfiles-c91c4c58ea7a85986feaae2528f84ea53995c45d.tar.gz
dotfiles-c91c4c58ea7a85986feaae2528f84ea53995c45d.tar.bz2
dotfiles-c91c4c58ea7a85986feaae2528f84ea53995c45d.zip
Add tests for new repository implementation
-rw-r--r--tests/test_repository.py143
1 files changed, 123 insertions, 20 deletions
diff --git a/tests/test_repository.py b/tests/test_repository.py
index 098704b..8e6b48b 100644
--- a/tests/test_repository.py
+++ b/tests/test_repository.py
@@ -1,38 +1,141 @@
+import os
+import pytest
+
from dotfiles.dotfile import Dotfile
from dotfiles.repository import Repository
-def test_list(tmpdir):
+def test_getters():
+
+ repo = Repository('foo', 'bar')
+
+ assert isinstance(repo.homedir, str)
+ assert isinstance(repo.repodir, str)
+
+
+def test_setters():
+
+ repodir = '/foo/bar'
+ homedir = '/fizz/buzz'
+
+ repo = Repository('foo', 'bar')
+
+ repo.repodir = repodir
+ repo.homedir = homedir
+
+ assert repodir == repo.repodir
+ assert homedir == repo.homedir
+
+
+def test_custom_paths():
+
+ homedir = '/foo/bar'
+ repodir = '/fizz/buzz'
+
+ repo = Repository(repodir, homedir)
+
+ assert homedir == repo.homedir
+ assert repodir == repo.repodir
+
+
+def test_path_expansion():
+
+ repo = Repository('~/foo', '~/bar')
+
+ assert os.path.expanduser('~/foo') == repo.repodir
+ assert os.path.expanduser('~/bar') == repo.homedir
+
+
+def test_create_repo(tmpdir):
+
+ repodir = tmpdir.join("test_create_repo")
+
+ repodir.check(exists=0)
+ Repository(repodir)
+ repodir.check(exists=1, dir=1)
+
- repo = tmpdir.ensure("Dotfiles", dir=1)
+def test_empty_status(tmpdir):
+
+ repo = Repository(tmpdir.join("repo"))
+
+ assert '[no dotfiles found]' == repo.status()
+
+
+def test_status_manual(tmpdir, monkeypatch):
+
+ repodir = tmpdir.join("Dotfiles", dir=1)
name = tmpdir.join(".vimrc")
- target = repo.ensure("vimrc")
+ target = repodir.ensure("vimrc")
dotfile = Dotfile(name, target)
- repository = Repository(repo, tmpdir)
- # manual discovery
- repository.dotfiles = [dotfile, dotfile, dotfile]
+ repo = Repository(repodir, tmpdir)
+ monkeypatch.setattr(Repository, "_load",
+ lambda self: [dotfile, dotfile, dotfile])
+
+ expected_status = (".vimrc -> Dotfiles/vimrc (unknown)\n"
+ ".vimrc -> Dotfiles/vimrc (unknown)\n"
+ ".vimrc -> Dotfiles/vimrc (unknown)")
+
+ assert expected_status == repo.status()
+
+
+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 = (".bashrc -> Dotfiles/bashrc (unknown)\n"
+ ".inputrc -> Dotfiles/inputrc (unknown)\n"
+ ".vimrc -> Dotfiles/vimrc (unknown)")
+
+ assert expected_status == repo.status()
+
+
+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])
+
+ assert ('.aaa -> repo/aaa (unknown)\n'
+ '.ccc -> repo/ccc (unknown)') == repo.check()
+
- expected_list = (".vimrc -> Dotfiles/vimrc (unknown)\n"
- ".vimrc -> Dotfiles/vimrc (unknown)\n"
- ".vimrc -> Dotfiles/vimrc (unknown)")
+def test_sync():
+ with pytest.raises(NotImplementedError):
+ Repository('todo').sync()
- assert expected_list == str(repository)
+def test_unsync():
+ with pytest.raises(NotImplementedError):
+ Repository('todo').unsync()
-def test_discovery(tmpdir):
- repo = tmpdir.ensure("Dotfiles", dir=1)
+def test_add():
+ with pytest.raises(NotImplementedError):
+ Repository('todo').add()
- tmpdir.join('.bashrc').mksymlinkto(repo.ensure('bashrc'))
- tmpdir.join('.inputrc').mksymlinkto(repo.ensure('inputrc'))
- tmpdir.join('.vimrc').mksymlinkto(repo.ensure('vimrc'))
- repository = Repository(repo, tmpdir)
+def test_remove():
+ with pytest.raises(NotImplementedError):
+ Repository('todo').remove()
- expected_list = (".bashrc -> Dotfiles/bashrc (unknown)\n"
- ".inputrc -> Dotfiles/inputrc (unknown)\n"
- ".vimrc -> Dotfiles/vimrc (unknown)")
- assert expected_list == str(repository)
+def test_move():
+ with pytest.raises(NotImplementedError):
+ Repository('todo').move()