From 08b335d2b5da45e259dd80f1e708671326e9d72e Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Mon, 16 Dec 2019 08:04:28 -0600 Subject: [PATCH] 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 000000000..68d38b102 --- /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 5bc5ed6b8..f21c5a0f0 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"]