From c178e77ab720cdc9687e14a0187bef8578f4091a Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Fri, 13 Dec 2019 17:39:01 -0600 Subject: [PATCH 1/9] tests/repo: use pytest --- tests/unit/test_repo.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/tests/unit/test_repo.py b/tests/unit/test_repo.py index ad7426154a..f21c5a0f0d 100644 --- a/tests/unit/test_repo.py +++ b/tests/unit/test_repo.py @@ -1,13 +1,6 @@ -import os +from dvc.utils.compat import fspath -from tests.basic_env import TestDvc - -class TestIsDvcInternal(TestDvc): - def test_return_false_on_non_dvc_file(self): - path = os.path.join("path", "to-non-.dvc", "file") - self.assertFalse(self.dvc.is_dvc_internal(path)) - - def test_return_true_on_dvc_internal_file(self): - path = os.path.join("path", "to", ".dvc", "file") - self.assertTrue(path) +def test_is_dvc_internal(tmp_dir, dvc): + assert dvc.is_dvc_internal(fspath(tmp_dir / ".dvc" / "file")) + assert not dvc.is_dvc_internal("file") From 655b79bf0cd23c5099668fb1c25b65ca7f33b01f Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Fri, 13 Dec 2019 17:39:23 -0600 Subject: [PATCH 2/9] tests/repo: move .destroy to unit test --- tests/func/test_destroy.py | 28 ---------------------------- tests/unit/test_repo.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 28 deletions(-) delete mode 100644 tests/func/test_destroy.py diff --git a/tests/func/test_destroy.py b/tests/func/test_destroy.py deleted file mode 100644 index 3535c9d7ac..0000000000 --- a/tests/func/test_destroy.py +++ /dev/null @@ -1,28 +0,0 @@ -import os - -from dvc.system import System - - -def test_destroy(repo_dir, dvc_repo): - # NOTE: using symlink to ensure that data was unprotected after `destroy` - dvc_repo.config.set("cache", "type", "symlink") - - foo_stage, = dvc_repo.add(repo_dir.FOO) - data_dir_stage, = dvc_repo.add(repo_dir.DATA_DIR) - - dvc_repo.destroy() - - assert not os.path.exists(dvc_repo.dvc_dir) - assert not os.path.exists(foo_stage.path) - assert not os.path.exists(data_dir_stage.path) - - assert os.path.isfile(repo_dir.FOO) - assert os.path.isdir(repo_dir.DATA_DIR) - assert os.path.isfile(repo_dir.DATA) - assert os.path.isdir(repo_dir.DATA_SUB_DIR) - assert os.path.isfile(repo_dir.DATA_SUB) - - assert not System.is_symlink(repo_dir.FOO) - assert not System.is_symlink(repo_dir.DATA_DIR) - assert not System.is_symlink(repo_dir.DATA) - assert not System.is_symlink(repo_dir.DATA_SUB) diff --git a/tests/unit/test_repo.py b/tests/unit/test_repo.py index f21c5a0f0d..6f286e94d2 100644 --- a/tests/unit/test_repo.py +++ b/tests/unit/test_repo.py @@ -1,6 +1,34 @@ +from dvc.system import System from dvc.utils.compat import fspath def test_is_dvc_internal(tmp_dir, dvc): assert dvc.is_dvc_internal(fspath(tmp_dir / ".dvc" / "file")) assert not dvc.is_dvc_internal("file") + + +def test_destroy(tmp_dir, dvc): + dvc.config.set("cache", "type", "symlink") + + tmp_dir.dvc_gen('file', 'text') + tmp_dir.dvc_gen({'dir': {'file': 'lorem', 'subdir/file': 'ipsum'}}) + + dvc.destroy() + + # Remove all the files related to DVC + assert not (tmp_dir / ".dvc").exists() + assert not (tmp_dir / "file.dvc").exists() + assert not (tmp_dir / "dir.dvc").exists() + + # Leave the rest of the files + assert (tmp_dir / "file").is_file() + assert (tmp_dir / "dir").is_dir() + assert (tmp_dir / "dir" / "file").is_file() + assert (tmp_dir / "dir" / "subdir" / "file").is_file() + + # Make sure that data was unprotected after `destroy` + assert not System.is_symlink(fspath(tmp_dir / "foo")) + assert not System.is_symlink(fspath(tmp_dir / "file")) + assert not System.is_symlink(fspath(tmp_dir / "dir")) + assert not System.is_symlink(fspath(tmp_dir / "dir" / "file")) + assert not System.is_symlink(fspath(tmp_dir / "dir" / "subdir" / "file")) From b3a52515a3d8f3dee55803417025d53838c43341 Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Fri, 13 Dec 2019 17:54:05 -0600 Subject: [PATCH 3/9] tests/repo: move .collect to unit --- tests/func/test_repo.py | 42 ----------------------------------------- tests/unit/test_repo.py | 28 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 42 deletions(-) diff --git a/tests/func/test_repo.py b/tests/func/test_repo.py index 2bf2340b0c..cbf454e991 100644 --- a/tests/func/test_repo.py +++ b/tests/func/test_repo.py @@ -1,52 +1,10 @@ from dvc.ignore import DvcIgnore from dvc.main import main from dvc.repo import Repo -from dvc.scm.git import GitTree -from dvc.scm.tree import WorkingTree from dvc.stage import Stage from tests.basic_env import TestDvcGit -class TestCollect(TestDvcGit): - def setUp(self): - super(TestCollect, self).setUp() - self.dvc.add(self.FOO) - self.dvc.run( - deps=[self.FOO], - outs=[self.BAR], - cmd="python code.py {} {}".format(self.FOO, self.BAR), - ) - self.dvc.scm.add([".gitignore", self.FOO + ".dvc", self.BAR + ".dvc"]) - self.dvc.scm.commit("foo.dvc and bar.dvc") - self.dvc.scm.checkout("new_branch", True) - self.dvc.run( - deps=[self.BAR], - outs=["buzz"], - cmd="python code.py {} {}".format(self.BAR, "buzz"), - ) - self.dvc.scm.add([".gitignore", "buzz.dvc"]) - self.dvc.scm.commit("add buzz") - self.dvc.scm.checkout("master") - - def _check(self, branch, target, with_deps, expected): - if branch: - self.dvc.tree = GitTree(self.dvc.scm.repo, branch) - else: - self.dvc.tree = WorkingTree() - result = self.dvc.collect(target + ".dvc", with_deps=with_deps) - self.assertEqual([[str(j) for j in i.outs] for i in result], expected) - return result - - def test(self): - self._check("", self.BAR, True, [[self.FOO], [self.BAR]]) - self._check("master", self.BAR, True, [[self.FOO], [self.BAR]]) - self._check( - "new_branch", "buzz", True, [[self.FOO], [self.BAR], ["buzz"]] - ) - result = self._check("new_branch", "buzz", False, [["buzz"]]) - self.assertEqual([str(i) for i in result[0].deps], ["bar"]) - - class TestIgnore(TestDvcGit): def _stage_name(self, file): return file + Stage.STAGE_FILE_SUFFIX diff --git a/tests/unit/test_repo.py b/tests/unit/test_repo.py index 6f286e94d2..3e79a0776c 100644 --- a/tests/unit/test_repo.py +++ b/tests/unit/test_repo.py @@ -1,3 +1,4 @@ +from dvc.scm.git import GitTree from dvc.system import System from dvc.utils.compat import fspath @@ -32,3 +33,30 @@ def test_destroy(tmp_dir, dvc): assert not System.is_symlink(fspath(tmp_dir / "dir")) assert not System.is_symlink(fspath(tmp_dir / "dir" / "file")) assert not System.is_symlink(fspath(tmp_dir / "dir" / "subdir" / "file")) + + +def test_collect(tmp_dir, scm, dvc, run_copy): + tmp_dir.dvc_gen("foo", "foo") + run_copy("foo", "bar") + scm.add([".gitignore", "foo.dvc", "bar.dvc"]) + scm.commit("Add foo and bar") + + scm.checkout("new-branch", create_new=True) + + run_copy("bar", "buzz") + scm.add([".gitignore", "buzz.dvc"]) + scm.commit("Add buzz") + + def collect_outs(*args, **kwargs): + return [ + str(out.path_info) + for stage in dvc.collect(*args, **kwargs) + for out in stage.outs + ] + + assert ["foo", "bar"] == collect_outs("bar.dvc", with_deps=True) + + dvc.tree = GitTree(scm.repo, "new-branch") + + assert ["foo", "bar", "buzz"] == collect_outs("buzz.dvc", with_deps=True) + assert ["buzz"] == collect_outs("buzz.dvc", with_deps=False) From 37a2844a74150183fc312bdd6e98282b3a883720 Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Fri, 13 Dec 2019 18:01:11 -0600 Subject: [PATCH 4/9] tests/repo: move .stages to unit --- tests/func/test_repo.py | 29 ----------------------------- tests/unit/test_repo.py | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 29 deletions(-) delete mode 100644 tests/func/test_repo.py diff --git a/tests/func/test_repo.py b/tests/func/test_repo.py deleted file mode 100644 index cbf454e991..0000000000 --- a/tests/func/test_repo.py +++ /dev/null @@ -1,29 +0,0 @@ -from dvc.ignore import DvcIgnore -from dvc.main import main -from dvc.repo import Repo -from dvc.stage import Stage -from tests.basic_env import TestDvcGit - - -class TestIgnore(TestDvcGit): - def _stage_name(self, file): - return file + Stage.STAGE_FILE_SUFFIX - - def test_should_not_gather_stage_files_from_ignored_dir(self): - ret = main(["add", self.FOO, self.BAR, self.DATA, self.DATA_SUB]) - self.assertEqual(0, ret) - - stages = self.dvc.stages - self.assertEqual(4, len(stages)) - - self.create(DvcIgnore.DVCIGNORE_FILE, self.DATA_DIR) - - self.dvc = Repo(self.dvc.root_dir) - stages = self.dvc.stages - self.assertEqual(2, len(stages)) - - stagenames = [s.relpath for s in stages] - self.assertIn(self._stage_name(self.FOO), stagenames) - self.assertIn(self._stage_name(self.BAR), stagenames) - self.assertNotIn(self._stage_name(self.DATA), stagenames) - self.assertNotIn(self._stage_name(self.DATA_SUB), stagenames) diff --git a/tests/unit/test_repo.py b/tests/unit/test_repo.py index 3e79a0776c..aafec4de01 100644 --- a/tests/unit/test_repo.py +++ b/tests/unit/test_repo.py @@ -1,3 +1,4 @@ +from dvc.repo import Repo from dvc.scm.git import GitTree from dvc.system import System from dvc.utils.compat import fspath @@ -60,3 +61,16 @@ def collect_outs(*args, **kwargs): assert ["foo", "bar", "buzz"] == collect_outs("buzz.dvc", with_deps=True) assert ["buzz"] == collect_outs("buzz.dvc", with_deps=False) + + +def test_stages(tmp_dir, dvc): + tmp_dir.dvc_gen({"file": "a", "dir/file": "b", "dir/subdir/file": "c"}) + + def stages(): + return [stage.relpath for stage in Repo(tmp_dir).stages] + + assert stages() == ["file.dvc", "dir/file.dvc", "dir/subdir/file.dvc"] + + tmp_dir.gen(".dvcignore", "dir") + + assert stages() == ["file.dvc"] From 299fb9022f94e8bd241e8324d975ad0c38373f1a Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Fri, 13 Dec 2019 18:04:15 -0600 Subject: [PATCH 5/9] :nail_care: black --- dvc/api.py | 2 +- dvc/repo/__init__.py | 6 +++--- dvc/repo/get_url.py | 4 ++-- setup.py | 2 +- tests/func/test_add.py | 8 ++++---- tests/func/test_api.py | 2 +- tests/func/test_commit.py | 6 +++--- tests/func/test_gc.py | 2 +- tests/func/test_stage.py | 4 ++-- tests/unit/test_repo.py | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/dvc/api.py b/dvc/api.py index bf976dcf01..8da4cf6ba6 100644 --- a/dvc/api.py +++ b/dvc/api.py @@ -15,7 +15,7 @@ def get_url(path, repo=None, rev=None, remote=None): """Returns an url of a resource specified by path in repo""" with _make_repo(repo, rev=rev) as _repo: abspath = os.path.join(_repo.root_dir, path) - out, = _repo.find_outs_by_path(abspath) + (out,) = _repo.find_outs_by_path(abspath) remote_obj = _repo.cloud.get_remote(remote) return str(remote_obj.checksum_to_path_info(out.checksum)) diff --git a/dvc/repo/__init__.py b/dvc/repo/__init__.py index 8a0afc2d3c..94f792880a 100644 --- a/dvc/repo/__init__.py +++ b/dvc/repo/__init__.py @@ -263,7 +263,7 @@ def used_cache( for stage in stages: if stage.is_repo_import: - dep, = stage.deps + (dep,) = stage.deps cache.external[dep.repo_pair].add(dep.def_path) continue @@ -445,7 +445,7 @@ def func(out): def find_out_by_relpath(self, relpath): path = os.path.join(self.root_dir, relpath) - out, = self.find_outs_by_path(path) + (out,) = self.find_outs_by_path(path) return out def is_dvc_internal(self, path): @@ -457,7 +457,7 @@ def open(self, path, remote=None, mode="r", encoding=None): """Opens a specified resource as a file descriptor""" cause = None try: - out, = self.find_outs_by_path(path) + (out,) = self.find_outs_by_path(path) except OutputNotFoundError as e: out = None cause = e diff --git a/dvc/repo/get_url.py b/dvc/repo/get_url.py index fbc173b640..5718b20ecd 100644 --- a/dvc/repo/get_url.py +++ b/dvc/repo/get_url.py @@ -14,6 +14,6 @@ def get_url(url, out=None): out = os.path.abspath(out) - dep, = dependency.loads_from(None, [url]) - out, = output.loads_from(None, [out], use_cache=False) + (dep,) = dependency.loads_from(None, [url]) + (out,) = output.loads_from(None, [out], use_cache=False) dep.download(out) diff --git a/setup.py b/setup.py index 29a4a09363..81dadf1cba 100644 --- a/setup.py +++ b/setup.py @@ -141,7 +141,7 @@ def run(self): ] if (sys.version_info) >= (3, 6): - tests_requirements.append("black==19.3b0") + tests_requirements.append("black==19.10b0") setup( name="dvc", diff --git a/tests/func/test_add.py b/tests/func/test_add.py index 8a76263da2..bbb4fc4bf0 100644 --- a/tests/func/test_add.py +++ b/tests/func/test_add.py @@ -32,7 +32,7 @@ def test_add(tmp_dir, dvc): - stage, = tmp_dir.dvc_gen({"foo": "foo"}) + (stage,) = tmp_dir.dvc_gen({"foo": "foo"}) md5, _ = file_md5("foo") assert stage is not None @@ -50,7 +50,7 @@ def test_add_unicode(tmp_dir, dvc): with open("\xe1", "wb") as fd: fd.write("something".encode("utf-8")) - stage, = dvc.add("\xe1") + (stage,) = dvc.add("\xe1") assert os.path.isfile(stage.path) @@ -61,7 +61,7 @@ def test_add_unsupported_file(dvc): def test_add_directory(tmp_dir, dvc): - stage, = tmp_dir.dvc_gen({"dir": {"file": "file"}}) + (stage,) = tmp_dir.dvc_gen({"dir": {"file": "file"}}) assert stage is not None assert len(stage.deps) == 0 @@ -162,7 +162,7 @@ def test_add_file_in_dir(tmp_dir, dvc): tmp_dir.gen({"dir": {"subdir": {"subdata": "subdata content"}}}) subdir_path = os.path.join("dir", "subdir", "subdata") - stage, = dvc.add(subdir_path) + (stage,) = dvc.add(subdir_path) assert stage is not None assert len(stage.deps) == 0 diff --git a/tests/func/test_api.py b/tests/func/test_api.py index 54623c080d..b6ddc9dd5a 100644 --- a/tests/func/test_api.py +++ b/tests/func/test_api.py @@ -101,7 +101,7 @@ def _set_remote_url_and_commit(repo, remote_url): # FIXME: this test doesn't use scm ;D def test_open_scm_controlled(dvc_repo, repo_dir): - stage, = dvc_repo.add(repo_dir.FOO) + (stage,) = dvc_repo.add(repo_dir.FOO) stage_content = open(stage.path, "r").read() with api.open(stage.path) as fd: diff --git a/tests/func/test_commit.py b/tests/func/test_commit.py index 8d6a8e57d6..85c3623b59 100644 --- a/tests/func/test_commit.py +++ b/tests/func/test_commit.py @@ -20,7 +20,7 @@ def test_commit_recursive(tmp_dir, dvc): def test_commit_force(tmp_dir, dvc): tmp_dir.gen({"dir": {"file": "text1", "file2": "text2"}}) - stage, = dvc.add("dir", no_commit=True) + (stage,) = dvc.add("dir", no_commit=True) with dvc.state: assert stage.outs[0].changed_cache() @@ -42,7 +42,7 @@ def test_commit_force(tmp_dir, dvc): def test_commit_with_deps(tmp_dir, dvc, run_copy): tmp_dir.gen("foo", "foo") - foo_stage, = dvc.add("foo", no_commit=True) + (foo_stage,) = dvc.add("foo", no_commit=True) assert foo_stage is not None assert len(foo_stage.outs) == 1 @@ -62,7 +62,7 @@ def test_commit_with_deps(tmp_dir, dvc, run_copy): def test_commit_changed_md5(tmp_dir, dvc): tmp_dir.gen({"file": "file content"}) - stage, = dvc.add("file", no_commit=True) + (stage,) = dvc.add("file", no_commit=True) stage_file_content = load_stage_file(stage.path) stage_file_content["md5"] = "1111111111" diff --git a/tests/func/test_gc.py b/tests/func/test_gc.py index 7d06cb9a38..2fb46eb0ca 100644 --- a/tests/func/test_gc.py +++ b/tests/func/test_gc.py @@ -192,7 +192,7 @@ def test_all_commits(tmp_dir, scm, dvc): def test_gc_no_dir_cache(tmp_dir, dvc, repo_template): dvc.add(["foo", "bar"]) - dir_stage, = dvc.add("dir") + (dir_stage,) = dvc.add("dir") os.unlink(dir_stage.outs[0].cache_path) diff --git a/tests/func/test_stage.py b/tests/func/test_stage.py index b87a32d76f..d4e9e8b979 100644 --- a/tests/func/test_stage.py +++ b/tests/func/test_stage.py @@ -155,7 +155,7 @@ def test_remote_dependency(self): def test_md5_ignores_comments(repo_dir, dvc_repo): - stage, = dvc_repo.add("foo") + (stage,) = dvc_repo.add("foo") with open(stage.path, "a") as f: f.write("# End comment\n") @@ -165,7 +165,7 @@ def test_md5_ignores_comments(repo_dir, dvc_repo): def test_meta_is_preserved(dvc_repo): - stage, = dvc_repo.add("foo") + (stage,) = dvc_repo.add("foo") # Add meta to DVC-file data = load_stage_file(stage.path) diff --git a/tests/unit/test_repo.py b/tests/unit/test_repo.py index aafec4de01..2e0720a452 100644 --- a/tests/unit/test_repo.py +++ b/tests/unit/test_repo.py @@ -12,8 +12,8 @@ def test_is_dvc_internal(tmp_dir, dvc): def test_destroy(tmp_dir, dvc): dvc.config.set("cache", "type", "symlink") - tmp_dir.dvc_gen('file', 'text') - tmp_dir.dvc_gen({'dir': {'file': 'lorem', 'subdir/file': 'ipsum'}}) + tmp_dir.dvc_gen("file", "text") + tmp_dir.dvc_gen({"dir": {"file": "lorem", "subdir/file": "ipsum"}}) dvc.destroy() From df9f3de2317ab5f2b92755a9c4a5676c7159cc56 Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Fri, 13 Dec 2019 19:15:25 -0600 Subject: [PATCH 6/9] tests/repo: stringify stage.relpath --- tests/unit/test_repo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_repo.py b/tests/unit/test_repo.py index 2e0720a452..5bc5ed6b85 100644 --- a/tests/unit/test_repo.py +++ b/tests/unit/test_repo.py @@ -67,7 +67,7 @@ def test_stages(tmp_dir, dvc): tmp_dir.dvc_gen({"file": "a", "dir/file": "b", "dir/subdir/file": "c"}) def stages(): - return [stage.relpath for stage in Repo(tmp_dir).stages] + return [str(stage.relpath) for stage in Repo(tmp_dir).stages] assert stages() == ["file.dvc", "dir/file.dvc", "dir/subdir/file.dvc"] From 08b335d2b5da45e259dd80f1e708671326e9d72e Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Mon, 16 Dec 2019 08:04:28 -0600 Subject: [PATCH 7/9] tests/repo: move unit tests to func tests --- tests/func/test_repo.py | 64 +++++++++++++++++++++++++++++++++++++ tests/unit/test_repo.py | 70 ----------------------------------------- 2 files changed, 64 insertions(+), 70 deletions(-) create mode 100644 tests/func/test_repo.py diff --git a/tests/func/test_repo.py b/tests/func/test_repo.py new file mode 100644 index 0000000000..68d38b1025 --- /dev/null +++ b/tests/func/test_repo.py @@ -0,0 +1,64 @@ +from dvc.repo import Repo +from dvc.scm.git import GitTree +from dvc.system import System +from dvc.utils.compat import fspath + +def test_destroy(tmp_dir, dvc): + dvc.config.set("cache", "type", "symlink") + + tmp_dir.dvc_gen("file", "text") + tmp_dir.dvc_gen({"dir": {"file": "lorem", "subdir/file": "ipsum"}}) + + dvc.destroy() + + # Remove all the files related to DVC + for path in [".dvc", "file.dvc", "dir.dvc"]: + assert not (tmp_dir / path).exists() + + # Leave the rest of the files + for path in ["file", "dir/file", "dir/subdir/file"]: + assert (tmp_dir / path).is_file() + + # Make sure that data was unprotected after `destroy` + for path in ["file", "dir", "dir/file", "dir/subdir", "dir/subdir/file"]: + assert not System.is_symlink(fspath(tmp_dir / path)) + + +def test_collect(tmp_dir, scm, dvc, run_copy): + tmp_dir.dvc_gen("foo", "foo") + run_copy("foo", "bar") + scm.add([".gitignore", "foo.dvc", "bar.dvc"]) + scm.commit("Add foo and bar") + + scm.checkout("new-branch", create_new=True) + + run_copy("bar", "buzz") + scm.add([".gitignore", "buzz.dvc"]) + scm.commit("Add buzz") + + def collect_outs(*args, **kwargs): + return [ + str(out.path_info) + for stage in dvc.collect(*args, **kwargs) + for out in stage.outs + ] + + assert ["foo", "bar"] == collect_outs("bar.dvc", with_deps=True) + + dvc.tree = GitTree(scm.repo, "new-branch") + + assert ["foo", "bar", "buzz"] == collect_outs("buzz.dvc", with_deps=True) + assert ["buzz"] == collect_outs("buzz.dvc", with_deps=False) + + +def test_stages(tmp_dir, dvc): + tmp_dir.dvc_gen({"file": "a", "dir/file": "b", "dir/subdir/file": "c"}) + + def stages(): + return set(stage.relpath for stage in Repo(str(tmp_dir)).stages) + + assert stages() == {"file.dvc", "dir/file.dvc", "dir/subdir/file.dvc"} + + tmp_dir.gen(".dvcignore", "dir") + + assert stages() == {"file.dvc"} diff --git a/tests/unit/test_repo.py b/tests/unit/test_repo.py index 5bc5ed6b85..f21c5a0f0d 100644 --- a/tests/unit/test_repo.py +++ b/tests/unit/test_repo.py @@ -1,76 +1,6 @@ -from dvc.repo import Repo -from dvc.scm.git import GitTree -from dvc.system import System from dvc.utils.compat import fspath def test_is_dvc_internal(tmp_dir, dvc): assert dvc.is_dvc_internal(fspath(tmp_dir / ".dvc" / "file")) assert not dvc.is_dvc_internal("file") - - -def test_destroy(tmp_dir, dvc): - dvc.config.set("cache", "type", "symlink") - - tmp_dir.dvc_gen("file", "text") - tmp_dir.dvc_gen({"dir": {"file": "lorem", "subdir/file": "ipsum"}}) - - dvc.destroy() - - # Remove all the files related to DVC - assert not (tmp_dir / ".dvc").exists() - assert not (tmp_dir / "file.dvc").exists() - assert not (tmp_dir / "dir.dvc").exists() - - # Leave the rest of the files - assert (tmp_dir / "file").is_file() - assert (tmp_dir / "dir").is_dir() - assert (tmp_dir / "dir" / "file").is_file() - assert (tmp_dir / "dir" / "subdir" / "file").is_file() - - # Make sure that data was unprotected after `destroy` - assert not System.is_symlink(fspath(tmp_dir / "foo")) - assert not System.is_symlink(fspath(tmp_dir / "file")) - assert not System.is_symlink(fspath(tmp_dir / "dir")) - assert not System.is_symlink(fspath(tmp_dir / "dir" / "file")) - assert not System.is_symlink(fspath(tmp_dir / "dir" / "subdir" / "file")) - - -def test_collect(tmp_dir, scm, dvc, run_copy): - tmp_dir.dvc_gen("foo", "foo") - run_copy("foo", "bar") - scm.add([".gitignore", "foo.dvc", "bar.dvc"]) - scm.commit("Add foo and bar") - - scm.checkout("new-branch", create_new=True) - - run_copy("bar", "buzz") - scm.add([".gitignore", "buzz.dvc"]) - scm.commit("Add buzz") - - def collect_outs(*args, **kwargs): - return [ - str(out.path_info) - for stage in dvc.collect(*args, **kwargs) - for out in stage.outs - ] - - assert ["foo", "bar"] == collect_outs("bar.dvc", with_deps=True) - - dvc.tree = GitTree(scm.repo, "new-branch") - - assert ["foo", "bar", "buzz"] == collect_outs("buzz.dvc", with_deps=True) - assert ["buzz"] == collect_outs("buzz.dvc", with_deps=False) - - -def test_stages(tmp_dir, dvc): - tmp_dir.dvc_gen({"file": "a", "dir/file": "b", "dir/subdir/file": "c"}) - - def stages(): - return [str(stage.relpath) for stage in Repo(tmp_dir).stages] - - assert stages() == ["file.dvc", "dir/file.dvc", "dir/subdir/file.dvc"] - - tmp_dir.gen(".dvcignore", "dir") - - assert stages() == ["file.dvc"] From 6ed61efc051a04abf3b6ca7e5725ffef7cbfc23b Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Mon, 16 Dec 2019 08:08:23 -0600 Subject: [PATCH 8/9] tests/repo: refactor some tests --- tests/func/test_repo.py | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/tests/func/test_repo.py b/tests/func/test_repo.py index 68d38b1025..60984c987d 100644 --- a/tests/func/test_repo.py +++ b/tests/func/test_repo.py @@ -25,40 +25,28 @@ def test_destroy(tmp_dir, dvc): def test_collect(tmp_dir, scm, dvc, run_copy): - tmp_dir.dvc_gen("foo", "foo") - run_copy("foo", "bar") - scm.add([".gitignore", "foo.dvc", "bar.dvc"]) - scm.commit("Add foo and bar") - - scm.checkout("new-branch", create_new=True) - - run_copy("bar", "buzz") - scm.add([".gitignore", "buzz.dvc"]) - scm.commit("Add buzz") - def collect_outs(*args, **kwargs): - return [ + return set( str(out.path_info) for stage in dvc.collect(*args, **kwargs) for out in stage.outs - ] - - assert ["foo", "bar"] == collect_outs("bar.dvc", with_deps=True) + ) - dvc.tree = GitTree(scm.repo, "new-branch") + tmp_dir.dvc_gen("foo", "foo") + run_copy("foo", "bar") + assert collect_outs("bar.dvc", with_deps=True) == {"foo", "bar"} - assert ["foo", "bar", "buzz"] == collect_outs("buzz.dvc", with_deps=True) - assert ["buzz"] == collect_outs("buzz.dvc", with_deps=False) + run_copy("bar", "buzz") + assert collect_outs("buzz.dvc", with_deps=True) == {"foo", "bar", "buzz"} + assert collect_outs("buzz.dvc", with_deps=False) == {"buzz"} def test_stages(tmp_dir, dvc): - tmp_dir.dvc_gen({"file": "a", "dir/file": "b", "dir/subdir/file": "c"}) - def stages(): return set(stage.relpath for stage in Repo(str(tmp_dir)).stages) + tmp_dir.dvc_gen({"file": "a", "dir/file": "b", "dir/subdir/file": "c"}) assert stages() == {"file.dvc", "dir/file.dvc", "dir/subdir/file.dvc"} tmp_dir.gen(".dvcignore", "dir") - assert stages() == {"file.dvc"} From efb3a6205fae086450cc2f65922538143ad43d35 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 16 Dec 2019 14:07:05 +0000 Subject: [PATCH 9/9] Restyled by black --- tests/func/test_repo.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/func/test_repo.py b/tests/func/test_repo.py index 60984c987d..2bd799668f 100644 --- a/tests/func/test_repo.py +++ b/tests/func/test_repo.py @@ -3,6 +3,7 @@ from dvc.system import System from dvc.utils.compat import fspath + def test_destroy(tmp_dir, dvc): dvc.config.set("cache", "type", "symlink")