aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jon Bernard <jbernard@jbernard.io> 2018-10-05 12:10:59 -0400
committerGravatar Jon Bernard <jbernard@jbernard.io> 2019-03-05 10:16:06 -0500
commit59d276bbfd84bf256dcaee6447f692ca4f5cfeab (patch)
treece3c38ca9fe73315af1274c93caa26f66f026a4e
parentac121c58aee4a606626bd387d782151eb58d6a67 (diff)
downloaddotfiles-59d276bbfd84bf256dcaee6447f692ca4f5cfeab.tar.gz
dotfiles-59d276bbfd84bf256dcaee6447f692ca4f5cfeab.tar.bz2
dotfiles-59d276bbfd84bf256dcaee6447f692ca4f5cfeab.zip
Begin conversion of repository._dotfile() to pathlib
-rw-r--r--dotfiles/repository.py6
-rw-r--r--tests/test_repository.py19
2 files changed, 14 insertions, 11 deletions
diff --git a/dotfiles/repository.py b/dotfiles/repository.py
index 474c9ba..a29c142 100644
--- a/dotfiles/repository.py
+++ b/dotfiles/repository.py
@@ -81,7 +81,11 @@ class Repository(object):
def _dotfile_target(self, path):
"""Return the expected repository target for the given symlink."""
- relpath = str(path.relative_to(self.homedir))
+ try:
+ relpath = str(path.relative_to(self.homedir))
+ except ValueError:
+ raise NotRootedInHome(path)
+
if self.remove_leading_dot:
return self.path / relpath[1:]
else:
diff --git a/tests/test_repository.py b/tests/test_repository.py
index ef78001..ed8543c 100644
--- a/tests/test_repository.py
+++ b/tests/test_repository.py
@@ -1,6 +1,7 @@
import pytest
from pathlib import Path
+from dotfiles.exceptions import NotRootedInHome
from dotfiles.repository import Repository, \
REMOVE_LEADING_DOT, IGNORE_PATTERNS
@@ -86,17 +87,15 @@ def test_dotfile_target(repo, path):
repo.path / path[1:])
-# from dotfiles.exceptions import NotRootedInHome, InRepository, TargetIgnored,
-# IsDirectory
+def test_dotfile(repo):
+ with pytest.raises(NotRootedInHome):
+ repo._dotfile(Path('/tmp/foo'))
+ # with pytest.raises(TargetIgnored):
+ # repo.ignore_patterns = ['.foo']
+ # repo.remove_leading_dot = False
+ # repo._dotfile(py.path.local(repo.homedir.join('.foo')))
+ # repo._dotfile(repo.homedir / '.foo')
-
-# def test_dotfile(repo):
-# with pytest.raises(NotRootedInHome):
-# repo._dotfile(py.path.local('/tmp/foo'))
-# with pytest.raises(TargetIgnored):
-# repo.ignore_patterns = ['.foo']
-# repo.remove_leading_dot = False
-# repo._dotfile(py.path.local(repo.homedir.join('.foo')))
# with pytest.raises(TargetIgnored):
# repo.ignore_patterns = ['foo']
# repo._dotfile(repo.homedir.join('.bar/foo'))