diff options
author | Jon Bernard <jbernard@tuxion.com> | 2014-07-24 16:33:48 -0400 |
---|---|---|
committer | Jon Bernard <jbernard@tuxion.com> | 2014-07-24 16:33:48 -0400 |
commit | 4a215801542e28a6c7fdaa2d9e9679ebe911f9fe (patch) | |
tree | c853cc157e27a4e95767eda1d436e0057b833e61 /tests/conftest.py | |
parent | e3ac8c34392cd75256ca0fc1dcc30101c85f68df (diff) | |
download | dotfiles-4a215801542e28a6c7fdaa2d9e9679ebe911f9fe.tar.gz dotfiles-4a215801542e28a6c7fdaa2d9e9679ebe911f9fe.tar.bz2 dotfiles-4a215801542e28a6c7fdaa2d9e9679ebe911f9fe.zip |
A few more test tweaks
Diffstat (limited to 'tests/conftest.py')
-rw-r--r-- | tests/conftest.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..7fc2cc4 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,62 @@ +import os +import pytest +from dotfiles.utils import compare_path as samefile + + +def _touch(fname, times=None): + with open(fname, 'a'): + os.utime(fname, times) + + +class HomeDirectory(object): + + DEFAULT_REPOSITORY = 'dotfiles' + + def __init__(self, path, repo=None, contents=None): + self.path = path + if not repo: + self.repo = os.path.join(path, self.DEFAULT_REPOSITORY) + if contents: + self.setup(contents) + + def setup(self, contents): + repo = os.path.join(self.path, self.repo) + os.mkdir(repo) + + for link, link_should_exist in contents.items(): + + target = os.path.join('%s/%s' % (repo, link[1:])) + _touch(target) + + if link_should_exist: + os.symlink(target, os.path.join(self.path, link)) + + self.verify(contents) + + def verify(self, contents): + __tracebackhide__ = True + + for link, link_should_exist in contents.items(): + + target = os.path.join(self.path, '%s/%s' % (self.repo, link[1:])) + + if not os.path.exists(target): + pytest.fail("missing expected repo file \"%s\"" % target) + + link = os.path.join(self.path, link) + link_exists = os.path.exists(link) + + if link_should_exist: + if not link_exists: + pytest.fail("missing expected symlink \"%s\"" % link) + if not samefile(link, target): + pytest.fail("\"%s\" does not link to \"%s\"" % + (link, target)) + + elif link_exists: + pytest.fail("found unexpected symlink \"%s\"" % link) + + +@pytest.fixture +def homedir(tmpdir): + return HomeDirectory(str(tmpdir)) |