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_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_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_repo.py b/tests/func/test_repo.py index 2bf2340b0c..2bd799668f 100644 --- a/tests/func/test_repo.py +++ b/tests/func/test_repo.py @@ -1,71 +1,53 @@ -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 +from dvc.system import System +from dvc.utils.compat import fspath -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 test_destroy(tmp_dir, dvc): + dvc.config.set("cache", "type", "symlink") - 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 + tmp_dir.dvc_gen("file", "text") + tmp_dir.dvc_gen({"dir": {"file": "lorem", "subdir/file": "ipsum"}}) - 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"]) + 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 + ) -class TestIgnore(TestDvcGit): - def _stage_name(self, file): - return file + Stage.STAGE_FILE_SUFFIX + tmp_dir.dvc_gen("foo", "foo") + run_copy("foo", "bar") + assert collect_outs("bar.dvc", with_deps=True) == {"foo", "bar"} - 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) + run_copy("bar", "buzz") + assert collect_outs("buzz.dvc", with_deps=True) == {"foo", "bar", "buzz"} + assert collect_outs("buzz.dvc", with_deps=False) == {"buzz"} - stages = self.dvc.stages - self.assertEqual(4, len(stages)) - self.create(DvcIgnore.DVCIGNORE_FILE, self.DATA_DIR) +def test_stages(tmp_dir, dvc): + def stages(): + return set(stage.relpath for stage in Repo(str(tmp_dir)).stages) - self.dvc = Repo(self.dvc.root_dir) - stages = self.dvc.stages - self.assertEqual(2, len(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"} - 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) + tmp_dir.gen(".dvcignore", "dir") + assert stages() == {"file.dvc"} 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 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")