Merge pull request #2740 from algomaster99/test-arg-types-symlink

Ensure `contains_symlink_up_to` accept both str and Path-like objects
This commit is contained in:
Ruslan Kuprieiev
2019-11-05 22:42:06 +02:00
committed by GitHub
2 changed files with 12 additions and 0 deletions
+4
View File
@@ -9,6 +9,7 @@ import nanotime
from dvc.exceptions import DvcException
from dvc.system import System
from dvc.utils import dict_md5
from dvc.utils import fspath
from dvc.utils import fspath_py35
from dvc.utils import walk_files
from dvc.utils.compat import str
@@ -61,6 +62,9 @@ class BasePathNotInCheckedPathException(DvcException):
def contains_symlink_up_to(path, base_path):
base_path = fspath(base_path)
path = fspath(path)
if base_path not in path:
raise BasePathNotInCheckedPathException(path, base_path)
+8
View File
@@ -94,6 +94,14 @@ class TestContainsLink(TestCase):
):
self.assertFalse(contains_symlink_up_to(target_path, base_path))
def test_path_object_and_str_are_valid_arg_types(self):
base_path = "foo"
target_path = os.path.join(base_path, "bar")
self.assertFalse(contains_symlink_up_to(target_path, base_path))
self.assertFalse(
contains_symlink_up_to(PathInfo(target_path), PathInfo(base_path))
)
@pytest.mark.parametrize(
"path1, path2",