summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/test_core.py34
-rw-r--r--tests/utils.py55
2 files changed, 89 insertions, 0 deletions
diff --git a/tests/test_core.py b/tests/test_core.py
new file mode 100644
index 0000000..a425e24
--- /dev/null
+++ b/tests/test_core.py
@@ -0,0 +1,34 @@
+import os
+import pytest
+from utils import HomeDirectory
+from dotfiles.core import Dotfiles as Repository
+
+
+REPOSITORY = 'dotfiles'
+
+
+def test_sync(tmpdir):
+ """the quick, brown fox jumps over the lazy dog.
+
+ lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
+ tempor incididunt ut labore et dolore magna aliqua. ut enim ad minim veniam,
+ quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
+ consequat. duis aute irure dolor in reprehenderit in voluptate velit esse
+ cillum dolore eu fugiat nulla pariatur. excepteur sint occaecat cupidatat
+ non proident, sunt in culpa qui officia deserunt mollit anim id est
+ laborum"""
+
+ contents = {'.foo': True,
+ '.bar': True,
+ '.baz': False}
+
+ homedir = HomeDirectory(str(tmpdir), REPOSITORY, contents)
+
+ Repository(homedir=homedir.path,
+ repository=os.path.join(homedir.path, REPOSITORY),
+ prefix='', ignore=[], externals={}, packages=[],
+ dry_run = False).sync()
+
+ # .baz should now exist and link to the correct location
+ contents['.baz'] = True
+ homedir.verify(contents)
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)