aboutsummaryrefslogtreecommitdiffstats
path: root/tests/utils.py
diff options
context:
space:
mode:
authorGravatar Jon Bernard <jbernard@tuxion.com> 2014-07-17 17:37:30 -0400
committerGravatar Jon Bernard <jbernard@tuxion.com> 2014-07-17 17:37:30 -0400
commit936ad4fdd233f2be8e3b92ad2ee060e027fc6eac (patch)
treee7e982ea9bc17938bcd0ddb09f4944c1302a1fac /tests/utils.py
parent43b496d0e0a57115c86d57c1e5d1709f8de2be9f (diff)
downloaddotfiles-936ad4fdd233f2be8e3b92ad2ee060e027fc6eac.tar.gz
dotfiles-936ad4fdd233f2be8e3b92ad2ee060e027fc6eac.tar.bz2
dotfiles-936ad4fdd233f2be8e3b92ad2ee060e027fc6eac.zip
Experiments with using pytest for tests
Diffstat (limited to 'tests/utils.py')
-rw-r--r--tests/utils.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/utils.py b/tests/utils.py
new file mode 100644
index 0000000..ecdeb84
--- /dev/null
+++ b/tests/utils.py
@@ -0,0 +1,55 @@
+import os
+from dotfiles.utils import compare_path as samefile
+
+
+def _touch(fname, times=None):
+ with open(fname, 'a'):
+ os.utime(fname, times)
+
+
+class HomeDirectory(object):
+
+
+ def __init__(self, path, repo, contents):
+ self.path = path
+ self.repo = repo
+ 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)