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/func/test_repo.py b/tests/func/test_repo.py index 2bf2340b0c..bb278d2737 100644 --- a/tests/func/test_repo.py +++ b/tests/func/test_repo.py @@ -1,71 +1,73 @@ -from dvc.ignore import DvcIgnore -from dvc.main import main +import os + +from dvc.scm.git.tree import GitTree +from dvc.cache import Cache 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"]] +from dvc.system import System +from dvc.utils.compat import fspath + + +def test_destroy(tmp_dir, dvc): + dvc.config.set("cache", "type", "symlink") + dvc.cache = Cache(dvc) + + 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): + def collect_outs(*args, **kwargs): + return set( + str(out.path_info) + for stage in dvc.collect(*args, **kwargs) + for out in stage.outs ) - result = self._check("new_branch", "buzz", False, [["buzz"]]) - self.assertEqual([str(i) for i in result[0].deps], ["bar"]) + 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") + + assert collect_outs("bar.dvc", with_deps=True) == {"foo", "bar"} + + dvc.tree = GitTree(scm.repo, "new-branch") + + assert collect_outs("buzz.dvc", with_deps=True) == {"foo", "bar", "buzz"} + assert collect_outs("buzz.dvc", with_deps=False) == {"buzz"} -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) +def test_stages(tmp_dir, dvc): + def stages(): + return set(stage.relpath for stage in Repo(fspath(tmp_dir)).stages) - stages = self.dvc.stages - self.assertEqual(4, len(stages)) + tmp_dir.dvc_gen({"file": "a", "dir/file": "b", "dir/subdir/file": "c"}) - self.create(DvcIgnore.DVCIGNORE_FILE, self.DATA_DIR) + assert stages() == { + "file.dvc", + os.path.join("dir", "file.dvc"), + os.path.join("dir", "subdir", "file.dvc"), + } - self.dvc = Repo(self.dvc.root_dir) - stages = self.dvc.stages - self.assertEqual(2, len(stages)) + tmp_dir.gen(".dvcignore", "dir") - 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) + assert stages() == {"file.dvc"} diff --git a/tests/unit/test_repo.py b/tests/unit/test_repo.py index ad7426154a..0d7577bd4c 100644 --- a/tests/unit/test_repo.py +++ b/tests/unit/test_repo.py @@ -1,13 +1,6 @@ import os -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(dvc): + assert dvc.is_dvc_internal(os.path.join("path", "to", ".dvc", "file")) + assert not dvc.is_dvc_internal(os.path.join("path", "to-non-.dvc", "file"))