From 767433d7a42e95f91d4e3fcf8ec0a239fb2a9fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Redzy=C5=84ski?= Date: Fri, 13 Mar 2020 16:19:35 +0100 Subject: [PATCH] tests: add .gitignore files upon dvc_add (#3455) --- tests/dir_helpers.py | 13 ++++++++++++- tests/func/test_ls.py | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/dir_helpers.py b/tests/dir_helpers.py index 0604099bb..ad374a2dc 100644 --- a/tests/dir_helpers.py +++ b/tests/dir_helpers.py @@ -156,7 +156,18 @@ class TmpDir(pathlib.Path): stages = self.dvc.add(filenames) if commit: stage_paths = [s.path for s in stages] - self.scm_add(stage_paths, commit=commit) + + def to_gitignore(stage_path): + from dvc.scm import Git + + return os.path.join(os.path.dirname(stage_path), Git.GITIGNORE) + + gitignores = [ + to_gitignore(s) + for s in stage_paths + if os.path.exists(to_gitignore(s)) + ] + self.scm_add(stage_paths + gitignores, commit=commit) return stages diff --git a/tests/func/test_ls.py b/tests/func/test_ls.py index 4b61f6398..29cf969ed 100644 --- a/tests/func/test_ls.py +++ b/tests/func/test_ls.py @@ -112,8 +112,11 @@ def test_ls_repo_recursive(tmp_dir, dvc, scm): (("data", "subcontent", "data.xml.dvc"), False), (("data", "subcontent", "statistics", "data.csv.dvc"), False), (("data", "subcontent", "statistics", "data.csv"), True), + (("data", "subcontent", "statistics", ".gitignore"), False), (("data", "subcontent", "data.xml"), True), + (("data", "subcontent", ".gitignore"), False), (("model", "people.csv"), True), + (("model", ".gitignore"), False), (("structure.xml",), True), ), ) @@ -147,6 +150,7 @@ def test_ls_repo_with_target_dir(tmp_dir, dvc, scm): (("train.py",), False), (("people.csv",), True), (("people.csv.dvc",), False), + ((".gitignore",), False), ), ) @@ -172,6 +176,7 @@ def test_ls_repo_with_target_subdir(tmp_dir, dvc, scm): (("data.xml",), True), (("data.xml.dvc",), False), (("statistics",), False), + ((".gitignore",), False), ), ) @@ -249,6 +254,7 @@ def test_ls_repo_with_removed_dvc_dir(tmp_dir, dvc, scm): (("out.dvc",), False), (("dep",), True), (("out",), False), + ((".gitignore",), False), ), ) @@ -265,6 +271,7 @@ def test_ls_repo_with_removed_dvc_dir_recursive(tmp_dir, dvc, scm): (("out.dvc",), False), (("dep",), True), (("out", "file"), True), + ((".gitignore",), False), ), ) @@ -324,8 +331,11 @@ def test_ls_remote_repo_recursive(erepo_dir): (("data", "subcontent", "data.xml.dvc"), False), (("data", "subcontent", "statistics", "data.csv.dvc"), False), (("data", "subcontent", "statistics", "data.csv"), True), + (("data", "subcontent", "statistics", ".gitignore"), False), (("data", "subcontent", "data.xml"), True), + (("data", "subcontent", ".gitignore"), False), (("model", "people.csv"), True), + (("model", ".gitignore"), False), (("structure.xml",), True), ), ) @@ -363,6 +373,7 @@ def test_ls_remote_repo_with_target_dir(erepo_dir): (("train.py",), False), (("people.csv",), True), (("people.csv.dvc",), False), + ((".gitignore",), False), ), ) @@ -401,9 +412,13 @@ def test_ls_remote_repo_with_rev_recursive(erepo_dir): (("data", "subcontent", "data.xml.dvc"), False), (("data", "subcontent", "statistics", "data.csv.dvc"), False), (("data", "subcontent", "statistics", "data.csv"), True), + (("data", "subcontent", "statistics", ".gitignore"), False), (("data", "subcontent", "data.xml"), True), + (("data", "subcontent", ".gitignore"), False), (("model", "people.csv"), True), + (("model", ".gitignore"), False), (("structure.xml",), True), + ((".gitignore",), False), ), )