From ee8a42ee6707d514bc0a4989a018db0561b4e6e9 Mon Sep 17 00:00:00 2001 From: Jon Bernard Date: Tue, 29 Dec 2015 09:44:10 -0500 Subject: Add dotfile class rework This version of the dotfile class uses py.path.local and removes much of the cruft of using os.path and it's associated requirements. There are still a few things missing, namely dry_run mode where commands are printed instead of executed and force sync. They will be included as required. --- tests/test_dotfile.py | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 tests/test_dotfile.py (limited to 'tests/test_dotfile.py') diff --git a/tests/test_dotfile.py b/tests/test_dotfile.py new file mode 100644 index 0000000..b854859 --- /dev/null +++ b/tests/test_dotfile.py @@ -0,0 +1,112 @@ +import pytest +import py.error +from dotfiles.dotfile import Dotfile + + +class TestAdd: + + def test_add(self, tmpdir): + + repo = tmpdir.ensure("Dotfiles", dir=1) + name = tmpdir.ensure(".vimrc") + target = repo.join("vimrc") + + dotfile = Dotfile(name, target) + dotfile.add() + + assert target.check(file=1, link=0) + assert name.check(file=1, link=1) + assert name.samefile(target) + + def test_add_twice(self, tmpdir): + + repo = tmpdir.ensure("Dotfiles", dir=1) + name = tmpdir.ensure(".vimrc") + target = repo.join("vimrc") + + dotfile = Dotfile(name, target) + dotfile.add() + + assert target.check(file=1, link=0) + assert name.check(file=1, link=1) + assert name.samefile(target) + + with pytest.raises(OSError): + dotfile.add() + + assert target.check(file=1, link=0) + assert name.check(file=1, link=1) + assert name.samefile(target) + + +class TestRemove: + + def test_remove(self, tmpdir): + + repo = tmpdir.ensure("Dotfiles", dir=1) + name = tmpdir.join(".vimrc") + target = repo.ensure("vimrc") + + name.mksymlinkto(target) + + dotfile = Dotfile(name, target) + dotfile.remove() + + assert False == target.check() + assert name.check(file=1, link=0) + + def test_remove_twice(self, tmpdir): + + repo = tmpdir.ensure("Dotfiles", dir=1) + name = tmpdir.join(".vimrc") + target = repo.ensure("vimrc") + + name.mksymlinkto(target) + + dotfile = Dotfile(name, target) + dotfile.remove() + + assert False == target.check() + assert name.check(file=1, link=0) + + with pytest.raises(OSError): + dotfile.remove() + + assert False == target.check() + assert name.check(file=1, link=0) + + +class TestSync: + + def test_sync(self, tmpdir): + + repo = tmpdir.ensure("Dotfiles", dir=1) + name = tmpdir.join(".vimrc") + target = repo.ensure("vimrc") + + dotfile = Dotfile(name, target) + dotfile.sync() + + assert target.check(file=1, link=0) + assert name.check(file=1, link=1) + assert name.samefile(target) + + def test_sync_twice(self, tmpdir): + + repo = tmpdir.ensure("Dotfiles", dir=1) + name = tmpdir.join(".vimrc") + target = repo.ensure("vimrc") + + dotfile = Dotfile(name, target) + dotfile.sync() + + assert target.check(file=1, link=0) + assert name.check(file=1, link=1) + assert name.samefile(target) + + with pytest.raises(py.error.EEXIST): + dotfile.sync() + + assert target.check(file=1, link=0) + assert name.check(file=1, link=1) + assert name.samefile(target) -- cgit v1.2.3