From e8c321e9a3d517f116dae755f88f7d7e837be09b Mon Sep 17 00:00:00 2001 From: Alexander Schepanovski Date: Tue, 24 Dec 2019 12:46:32 +0700 Subject: [PATCH 1/2] test: test ignore nuances - nested files are ignored - external dirs are not affected --- tests/func/test_ignore.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/func/test_ignore.py b/tests/func/test_ignore.py index 97fac4644b..382c07519a 100644 --- a/tests/func/test_ignore.py +++ b/tests/func/test_ignore.py @@ -7,10 +7,12 @@ from dvc.exceptions import DvcIgnoreInCollectedDirError from dvc.ignore import DvcIgnore, DvcIgnoreDirs, DvcIgnorePatterns from dvc.scm.tree import WorkingTree -from dvc.utils import walk_files +from dvc.utils import walk_files, relpath from dvc.utils.compat import fspath from dvc.utils.fs import get_mtime_and_size +from dvc.remote import RemoteLOCAL +from tests.dir_helpers import TmpDir from tests.utils import to_posixpath @@ -118,3 +120,28 @@ def test_ignore_on_branch(tmp_dir, scm, dvc): def _files_set(root, dvcignore): return {to_posixpath(f) for f in walk_files(root, dvcignore)} + + +def test_match_nested(tmp_dir, dvc): + tmp_dir.gen( + { + ".dvcignore": "*.backup\ntmp", + "foo": "foo", + "tmp": "...", + "dir": {"x.backup": "x backup", "tmp": "content"}, + } + ) + + remote = RemoteLOCAL(dvc, {}) + result = {fspath(f) for f in remote.walk_files(".")} + assert result == {".dvcignore", "foo"} + + +def test_ignore_external(tmp_dir, scm, dvc, tmp_path_factory): + tmp_dir.gen(".dvcignore", "*.backup\ntmp") + ext_dir = TmpDir(tmp_path_factory.mktemp("external_dir")) + ext_dir.gen({"y.backup": "y", "tmp": "ext tmp"}) + + remote = RemoteLOCAL(dvc, {}) + result = {relpath(f, ext_dir) for f in remote.walk_files(ext_dir)} + assert result == {"y.backup", "tmp"} From 5f3e416e6031bfe55b5a7a7a66bb5ef6081908af Mon Sep 17 00:00:00 2001 From: Alexander Schepanovski Date: Fri, 27 Dec 2019 15:51:07 +0700 Subject: [PATCH 2/2] test: fix test_ignore_external in Python 3.5 --- tests/func/test_ignore.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/func/test_ignore.py b/tests/func/test_ignore.py index 382c07519a..3bf878a4a1 100644 --- a/tests/func/test_ignore.py +++ b/tests/func/test_ignore.py @@ -8,7 +8,7 @@ from dvc.ignore import DvcIgnore, DvcIgnoreDirs, DvcIgnorePatterns from dvc.scm.tree import WorkingTree from dvc.utils import walk_files, relpath -from dvc.utils.compat import fspath +from dvc.utils.compat import fspath, fspath_py35 from dvc.utils.fs import get_mtime_and_size from dvc.remote import RemoteLOCAL @@ -139,7 +139,7 @@ def test_match_nested(tmp_dir, dvc): def test_ignore_external(tmp_dir, scm, dvc, tmp_path_factory): tmp_dir.gen(".dvcignore", "*.backup\ntmp") - ext_dir = TmpDir(tmp_path_factory.mktemp("external_dir")) + ext_dir = TmpDir(fspath_py35(tmp_path_factory.mktemp("external_dir"))) ext_dir.gen({"y.backup": "y", "tmp": "ext tmp"}) remote = RemoteLOCAL(dvc, {})