From d0f3559d9669194084820a4df2e7b2ed3264d35b Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Thu, 12 Dec 2019 18:57:45 -0600 Subject: [PATCH 01/33] tests: updater, use dir helpers --- tests/func/test_updater.py | 52 -------------------------------- tests/unit/test_updater.py | 61 ++++++++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 74 deletions(-) diff --git a/tests/func/test_updater.py b/tests/func/test_updater.py index 4045c0ca6..e69de29bb 100644 --- a/tests/func/test_updater.py +++ b/tests/func/test_updater.py @@ -1,52 +0,0 @@ -import os - -import mock -import pytest - -from dvc.updater import Updater - - -@pytest.fixture -def updater(dvc_repo): - return Updater(dvc_repo.dvc_dir) - - -def test_updater(updater): - # NOTE: only test on travis CRON to avoid generating too much logs - travis = os.getenv("TRAVIS") == "true" - if not travis: - return - - cron = os.getenv("TRAVIS_EVENT_TYPE") == "cron" - if not cron: - return - - env = os.environ.copy() - if env.get("CI"): - del env["CI"] - - with mock.patch.dict(os.environ, env): - updater.check() - updater.check() - updater.check() - - -def test_check_version_newer(updater): - updater.latest = "0.20.8" - updater.current = "0.21.0" - - assert not updater._is_outdated() - - -def test_check_version_equal(updater): - updater.latest = "0.20.8" - updater.current = "0.20.8" - - assert not updater._is_outdated() - - -def test_check_version_outdated(updater): - updater.latest = "0.21.0" - updater.current = "0.20.8" - - assert updater._is_outdated() diff --git a/tests/unit/test_updater.py b/tests/unit/test_updater.py index c8a0ee2de..89ffc3236 100644 --- a/tests/unit/test_updater.py +++ b/tests/unit/test_updater.py @@ -1,40 +1,57 @@ import json import os +import mock +import pytest from dvc import __version__ from dvc.updater import Updater -class MockResponse(object): - def __init__(self, json_data, status_code): - self.json_data = json_data - self.status_code = status_code - - def json(self): - return self.json_data +@pytest.fixture +def updater(dvc): + return Updater(dvc.dvc_dir) -def mocked_requests_get(*args, **kwargs): - class MockResponse: - def __init__(self, json_data, status_code): - self.json_data = json_data - self.status_code = status_code +@mock.patch("requests.get") +def test_fetch(mock_get, updater): + mock_get.return_value.status_code = 200 + mock_get.return_value.json.return_value = {"version": __version__} - def json(self): - return self.json_data - - return MockResponse({"version": __version__}, 200) - - -def test_fetch(dvc_repo, mocker): - updater = Updater(dvc_repo.dvc_dir) assert not os.path.exists(updater.updater_file) - mock_get = mocker.patch("requests.get", side_effect=mocked_requests_get) updater.fetch(detach=False) - mock_get.assert_called_once_with(Updater.URL, timeout=Updater.TIMEOUT_GET) + mock_get.assert_called_once_with(Updater.URL, timeout=Updater.TIMEOUT_GET) assert os.path.isfile(updater.updater_file) + with open(updater.updater_file, "r") as fobj: info = json.load(fobj) + assert info["version"] == __version__ + + +@pytest.mark.parametrize( + "latest, current, result", + [ + ("0.20.8", "0.21.0", False), + ("0.20.8", "0.20.8", False), + ("0.20.8", "0.19.0", True), + ], +) +def test_is_outdated(latest, current, result, updater): + updater.latest = latest + updater.current = current + + assert updater._is_outdated() == result + + +def test_check(updater, monkeypatch): + # NOTE: only test on travis CRON to avoid generating too much logs + if not os.getenv("TRAVIS_EVENT_TYPE") == "cron": + return + + monkeypatch.delenv("CI") + + updater.check() + updater.check() + updater.check() From c09c3aec0cd3a22a3efe099ec69da51df04173e4 Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Thu, 12 Dec 2019 19:05:31 -0600 Subject: [PATCH 02/33] remove empty file --- tests/func/test_updater.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/func/test_updater.py diff --git a/tests/func/test_updater.py b/tests/func/test_updater.py deleted file mode 100644 index e69de29bb..000000000 From c178e77ab720cdc9687e14a0187bef8578f4091a Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Fri, 13 Dec 2019 17:39:01 -0600 Subject: [PATCH 03/33] 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 ad7426154..f21c5a0f0 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 +from dvc.utils.compat import fspath -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 04/33] 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 3535c9d7a..000000000 --- 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 f21c5a0f0..6f286e94d 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 05/33] 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 2bf2340b0..cbf454e99 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 6f286e94d..3e79a0776 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 06/33] 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 cbf454e99..000000000 --- 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 3e79a0776..aafec4de0 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 test_collect(tmp_dir, scm, dvc, run_copy): 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 07/33] :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 bf976dcf0..8da4cf6ba 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 8a0afc2d3..94f792880 100644 --- a/dvc/repo/__init__.py +++ b/dvc/repo/__init__.py @@ -263,7 +263,7 @@ class Repo(object): 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 @@ class Repo(object): 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 @@ class Repo(object): """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 fbc173b64..5718b20ec 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 29a4a0936..81dadf1cb 100644 --- a/setup.py +++ b/setup.py @@ -141,7 +141,7 @@ tests_requirements = [ ] 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 8a76263da..bbb4fc4bf 100644 --- a/tests/func/test_add.py +++ b/tests/func/test_add.py @@ -32,7 +32,7 @@ from tests.utils import spy 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 54623c080..b6ddc9dd5 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 8d6a8e57d..85c3623b5 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 7d06cb9a3..2fb46eb0c 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 b87a32d76..d4e9e8b97 100644 --- a/tests/func/test_stage.py +++ b/tests/func/test_stage.py @@ -155,7 +155,7 @@ class TestExternalRemoteResolution(TestDvc): 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 aafec4de0..2e0720a45 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 08/33] 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 2e0720a45..5bc5ed6b8 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 4b833f58e56e31d12d818316a2adce614d3a1c16 Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Sun, 15 Dec 2019 13:09:23 -0600 Subject: [PATCH 09/33] tests/updater: use skipif for .check --- tests/unit/test_updater.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/test_updater.py b/tests/unit/test_updater.py index 89ffc3236..d68e33d0a 100644 --- a/tests/unit/test_updater.py +++ b/tests/unit/test_updater.py @@ -45,11 +45,11 @@ def test_is_outdated(latest, current, result, updater): assert updater._is_outdated() == result +@pytest.mark.skipif( + os.getenv("TRAVIS_EVENT_TYPE") != "cron", + reason = "Only run on travis CRON to avoid generating too much logs" def test_check(updater, monkeypatch): - # NOTE: only test on travis CRON to avoid generating too much logs - if not os.getenv("TRAVIS_EVENT_TYPE") == "cron": - return - + monkeypatch.setenv("DVC_TEST", "true") monkeypatch.delenv("CI") updater.check() From 08b335d2b5da45e259dd80f1e708671326e9d72e Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Mon, 16 Dec 2019 08:04:28 -0600 Subject: [PATCH 10/33] 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"] From 6ed61efc051a04abf3b6ca7e5725ffef7cbfc23b Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Mon, 16 Dec 2019 08:08:23 -0600 Subject: [PATCH 11/33] 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 68d38b102..60984c987 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) + tmp_dir.dvc_gen("foo", "foo") + run_copy("foo", "bar") + assert collect_outs("bar.dvc", with_deps=True) == {"foo", "bar"} - 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) + 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 576290a3c52948a6fc2f93c441d77b358eb7cfc6 Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Mon, 16 Dec 2019 08:13:06 -0600 Subject: [PATCH 12/33] restyled: bump black to v19.10 --- .restyled.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.restyled.yaml b/.restyled.yaml index d5eeec715..245d33d2c 100644 --- a/.restyled.yaml +++ b/.restyled.yaml @@ -1,7 +1,7 @@ --- restylers: - name: black - image: restyled/restyler-black:v19.3b0 + image: restyled/restyler-black:v19.10b0 command: - black arguments: [] From a7525fca641b3b196fd0b80931180fc220543c6f Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Mon, 16 Dec 2019 08:13:54 -0600 Subject: [PATCH 13/33] :nail_care: black and flake --- tests/func/test_repo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/func/test_repo.py b/tests/func/test_repo.py index 60984c987..ebe4466a7 100644 --- a/tests/func/test_repo.py +++ b/tests/func/test_repo.py @@ -1,8 +1,8 @@ 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") From 59072f4d18adf4364e267759d0bb42ccf5f74a8b Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Mon, 16 Dec 2019 09:44:59 -0600 Subject: [PATCH 14/33] :nail_care: revert black upgrade --- .restyled.yaml | 2 +- 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 ++-- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.restyled.yaml b/.restyled.yaml index 245d33d2c..d5eeec715 100644 --- a/.restyled.yaml +++ b/.restyled.yaml @@ -1,7 +1,7 @@ --- restylers: - name: black - image: restyled/restyler-black:v19.10b0 + image: restyled/restyler-black:v19.3b0 command: - black arguments: [] diff --git a/dvc/api.py b/dvc/api.py index 8da4cf6ba..bf976dcf0 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 94f792880..8a0afc2d3 100644 --- a/dvc/repo/__init__.py +++ b/dvc/repo/__init__.py @@ -263,7 +263,7 @@ class Repo(object): 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 @@ class Repo(object): 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 @@ class Repo(object): """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 5718b20ec..fbc173b64 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 81dadf1cb..29a4a0936 100644 --- a/setup.py +++ b/setup.py @@ -141,7 +141,7 @@ tests_requirements = [ ] if (sys.version_info) >= (3, 6): - tests_requirements.append("black==19.10b0") + tests_requirements.append("black==19.3b0") setup( name="dvc", diff --git a/tests/func/test_add.py b/tests/func/test_add.py index bbb4fc4bf..8a76263da 100644 --- a/tests/func/test_add.py +++ b/tests/func/test_add.py @@ -32,7 +32,7 @@ from tests.utils import spy 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 b6ddc9dd5..54623c080 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 85c3623b5..8d6a8e57d 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 2fb46eb0c..7d06cb9a3 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 d4e9e8b97..b87a32d76 100644 --- a/tests/func/test_stage.py +++ b/tests/func/test_stage.py @@ -155,7 +155,7 @@ class TestExternalRemoteResolution(TestDvc): 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) From 519454300796475bdd908e6bf382b62f02e16c0f Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Mon, 16 Dec 2019 10:25:07 -0600 Subject: [PATCH 15/33] tests/repo: windows compat --- tests/func/test_repo.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/func/test_repo.py b/tests/func/test_repo.py index ebe4466a7..f01acffb8 100644 --- a/tests/func/test_repo.py +++ b/tests/func/test_repo.py @@ -1,3 +1,5 @@ +import os + from dvc.repo import Repo from dvc.system import System from dvc.utils.compat import fspath @@ -46,7 +48,13 @@ def test_stages(tmp_dir, dvc): 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"} + + assert stages() == { + os.path.join("file.dvc"), + os.path.join("dir", "file.dvc"), + os.path.join("dir", "subdir", "file.dvc"), + } tmp_dir.gen(".dvcignore", "dir") + assert stages() == {"file.dvc"} From 0de183de263701318eba5bd08226bff145cbb187 Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Tue, 17 Dec 2019 11:55:47 -0600 Subject: [PATCH 16/33] tests/repo: reload cache properly --- tests/func/test_repo.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/func/test_repo.py b/tests/func/test_repo.py index f01acffb8..c466514e7 100644 --- a/tests/func/test_repo.py +++ b/tests/func/test_repo.py @@ -1,5 +1,6 @@ import os +from dvc.cache import Cache from dvc.repo import Repo from dvc.system import System from dvc.utils.compat import fspath @@ -7,6 +8,7 @@ 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"}}) From a83e440b32fc1b827ae0f29cc587bda70eb9c31d Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Tue, 17 Dec 2019 11:56:48 -0600 Subject: [PATCH 17/33] tests/repo: remove unnecessary os.path.join --- tests/func/test_repo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/func/test_repo.py b/tests/func/test_repo.py index c466514e7..3cf4e246e 100644 --- a/tests/func/test_repo.py +++ b/tests/func/test_repo.py @@ -52,7 +52,7 @@ def test_stages(tmp_dir, dvc): tmp_dir.dvc_gen({"file": "a", "dir/file": "b", "dir/subdir/file": "c"}) assert stages() == { - os.path.join("file.dvc"), + "file.dvc", os.path.join("dir", "file.dvc"), os.path.join("dir", "subdir", "file.dvc"), } From 1bd66fa85905724ae7c0421b89d69478db529d51 Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Tue, 17 Dec 2019 12:03:35 -0600 Subject: [PATCH 18/33] tests/repo: old params in is_dvc_internal --- tests/unit/test_repo.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/test_repo.py b/tests/unit/test_repo.py index f21c5a0f0..0d7577bd4 100644 --- a/tests/unit/test_repo.py +++ b/tests/unit/test_repo.py @@ -1,6 +1,6 @@ -from dvc.utils.compat import fspath +import os -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_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")) From d2469f7a1f7c582d437b20ce6ffc2ffd5e912de6 Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Tue, 17 Dec 2019 12:04:37 -0600 Subject: [PATCH 19/33] tests/repo: str -> fspath --- tests/func/test_repo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/func/test_repo.py b/tests/func/test_repo.py index 3cf4e246e..92d70e305 100644 --- a/tests/func/test_repo.py +++ b/tests/func/test_repo.py @@ -47,7 +47,7 @@ def test_collect(tmp_dir, scm, dvc, run_copy): def test_stages(tmp_dir, dvc): def stages(): - return set(stage.relpath for stage in Repo(str(tmp_dir)).stages) + return set(stage.relpath for stage in Repo(fspath(tmp_dir)).stages) tmp_dir.dvc_gen({"file": "a", "dir/file": "b", "dir/subdir/file": "c"}) From 7dedd7f518a9487b67728f8333d50a2378ce87bc Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Tue, 17 Dec 2019 12:12:57 -0600 Subject: [PATCH 20/33] tests/repo: bring back the old branch logic --- tests/func/test_repo.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/func/test_repo.py b/tests/func/test_repo.py index 92d70e305..bb278d273 100644 --- a/tests/func/test_repo.py +++ b/tests/func/test_repo.py @@ -1,5 +1,6 @@ import os +from dvc.scm.git.tree import GitTree from dvc.cache import Cache from dvc.repo import Repo from dvc.system import System @@ -38,9 +39,19 @@ def test_collect(tmp_dir, scm, dvc, run_copy): tmp_dir.dvc_gen("foo", "foo") run_copy("foo", "bar") - assert collect_outs("bar.dvc", with_deps=True) == {"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"} From 8a14700c12132889eb1be1022f79088ff0dff51b Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Tue, 17 Dec 2019 12:18:43 -0600 Subject: [PATCH 21/33] tests/updater: fix problems with .check --- tests/unit/test_updater.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_updater.py b/tests/unit/test_updater.py index d68e33d0a..92dc3b037 100644 --- a/tests/unit/test_updater.py +++ b/tests/unit/test_updater.py @@ -48,10 +48,14 @@ def test_is_outdated(latest, current, result, updater): @pytest.mark.skipif( os.getenv("TRAVIS_EVENT_TYPE") != "cron", reason = "Only run on travis CRON to avoid generating too much logs" -def test_check(updater, monkeypatch): - monkeypatch.setenv("DVC_TEST", "true") - monkeypatch.delenv("CI") +) +@mock.patch("dvc.updater.Updater._check") +def test_check(mock_check, updater, monkeypatch): + monkeypatch.delenv("CI", None) + monkeypatch.setenv("DVC_TEST", False) updater.check() updater.check() updater.check() + + assert mock_check.call_count == 3 From e519464aca3bf40892f3f0c66faae4d790da057d Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Tue, 17 Dec 2019 12:21:50 -0600 Subject: [PATCH 22/33] :nail_care: black --- tests/unit/test_updater.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_updater.py b/tests/unit/test_updater.py index 92dc3b037..f0e350528 100644 --- a/tests/unit/test_updater.py +++ b/tests/unit/test_updater.py @@ -47,7 +47,7 @@ def test_is_outdated(latest, current, result, updater): @pytest.mark.skipif( os.getenv("TRAVIS_EVENT_TYPE") != "cron", - reason = "Only run on travis CRON to avoid generating too much logs" + reason="Only run on travis CRON to avoid generating too much logs", ) @mock.patch("dvc.updater.Updater._check") def test_check(mock_check, updater, monkeypatch): From a8b5387e124c6235f44eeed30522b7c757601b60 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Wed, 18 Dec 2019 08:33:22 +0200 Subject: [PATCH 23/33] build: mac: uninstall bundler Related to https://github.com/iterative/dvc/issues/2970 --- scripts/build_posix.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/build_posix.sh b/scripts/build_posix.sh index da89bd757..57159e391 100755 --- a/scripts/build_posix.sh +++ b/scripts/build_posix.sh @@ -87,6 +87,9 @@ install_dependencies() fi gem install --no-document fpm + + # https://github.com/iterative/dvc/issues/2970 + gem uninstall rubygems-bundler print_info "Upgrading pip..." pip install --upgrade pip From f4daf3bacc9a9494df7d641f572e92b662e2c08c Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Wed, 18 Dec 2019 09:16:49 +0200 Subject: [PATCH 24/33] travis: retry choco installs --- scripts/ci/before_install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ci/before_install.sh b/scripts/ci/before_install.sh index bf5c9fa78..2240f9cd0 100644 --- a/scripts/ci/before_install.sh +++ b/scripts/ci/before_install.sh @@ -45,10 +45,10 @@ fi if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then if [[ -n "$PY2" ]]; then - choco install python2 + $scriptdir/retry.sh choco install python2 echo 'PATH="/c/Python27:/c/Python27/Scripts:$PATH"' >> env.sh else - choco install python --version 3.7.5 + $scriptdir/retry.sh choco install python --version 3.7.5 echo 'PATH="/c/Python37:/c/Python37/Scripts:$PATH"' >> env.sh fi elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then From e0313660cfc07a10417543b8e4d08bea9f24a70a Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Wed, 18 Dec 2019 18:50:03 +0200 Subject: [PATCH 25/33] travis: mac: adjust bundler uninstall command --- scripts/build_posix.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build_posix.sh b/scripts/build_posix.sh index 57159e391..cfe1bf611 100755 --- a/scripts/build_posix.sh +++ b/scripts/build_posix.sh @@ -89,7 +89,7 @@ install_dependencies() gem install --no-document fpm # https://github.com/iterative/dvc/issues/2970 - gem uninstall rubygems-bundler + gem uninstall -i /Users/travis/.rvm/gems/ruby-2.4.3@global rubygems-bundler print_info "Upgrading pip..." pip install --upgrade pip From 385674a78bdd867808113fa891ce2fc12db2aad1 Mon Sep 17 00:00:00 2001 From: Jorge Orpinel Date: Tue, 22 Oct 2019 16:11:40 -0500 Subject: [PATCH 26/33] dvc: use ' for dynamic output and ` for DVC names (follow-up) continues https://github.com/iterative/dvc/pull/2644#discussion_r338417698 --- dvc/analytics.py | 2 +- dvc/command/diff.py | 2 +- dvc/command/imp_url.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dvc/analytics.py b/dvc/analytics.py index 1ae02f60a..55baf1225 100644 --- a/dvc/analytics.py +++ b/dvc/analytics.py @@ -164,4 +164,4 @@ def _find_or_create_user_id(): return user_id except LockError: - logger.debug("Failed to acquire {lockfile}".format(lockfile=lockfile)) + logger.debug("Failed to acquire '{lockfile}'".format(lockfile=lockfile)) diff --git a/dvc/command/diff.py b/dvc/command/diff.py index 180508896..4e82ea520 100644 --- a/dvc/command/diff.py +++ b/dvc/command/diff.py @@ -31,7 +31,7 @@ class CmdDiff(CmdBase): def _get_md5_string(sign, file_name, checksum): sample_msg = "" if file_name: - sample_msg = "{}{} with md5 {}\n" + sample_msg = "'{}{}' with md5 {}\n" sample_msg = sample_msg.format(sign, file_name, checksum) return sample_msg diff --git a/dvc/command/imp_url.py b/dvc/command/imp_url.py index e072bc1e3..9c325dbe3 100644 --- a/dvc/command/imp_url.py +++ b/dvc/command/imp_url.py @@ -19,7 +19,7 @@ class CmdImportUrl(CmdBase): ) except DvcException: logger.exception( - "failed to import {}. You could also try downloading " + "failed to import '{}'. You could also try downloading " "it manually, and adding it with `dvc add`.".format( self.args.url ) From e1f755bbddda5103d4846c0d59fb7329655706ab Mon Sep 17 00:00:00 2001 From: Jorge Orpinel Date: Fri, 20 Dec 2019 12:54:31 -0700 Subject: [PATCH 27/33] fix formatting of dvc/analytics.py based on https://github.com/iterative/dvc/pull/2987/files#diff-60f82c04687a06de3f632551d63de49e --- dvc/analytics.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dvc/analytics.py b/dvc/analytics.py index 55baf1225..a8969b2ef 100644 --- a/dvc/analytics.py +++ b/dvc/analytics.py @@ -164,4 +164,6 @@ def _find_or_create_user_id(): return user_id except LockError: - logger.debug("Failed to acquire '{lockfile}'".format(lockfile=lockfile)) + logger.debug( + "Failed to acquire '{lockfile}'".format(lockfile=lockfile) + ) From 3574b0c107181ed0b6a485dac5d5d9f25595234c Mon Sep 17 00:00:00 2001 From: Jorge Orpinel Date: Fri, 20 Dec 2019 17:48:09 -0700 Subject: [PATCH 28/33] dvc: use ' for dynamic output (up to lock) --- dvc/command/remove.py | 4 ++-- dvc/config.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dvc/command/remove.py b/dvc/command/remove.py index 179d373f6..b4b47f98f 100644 --- a/dvc/command/remove.py +++ b/dvc/command/remove.py @@ -20,7 +20,7 @@ class CmdRemove(CmdBase): if self.args.force: return False - msg = "Are you sure you want to remove {} with its outputs?".format( + msg = "Are you sure you want to remove '{}' with its outputs?".format( target ) @@ -38,7 +38,7 @@ class CmdRemove(CmdBase): outs_only = self._is_outs_only(target) self.repo.remove(target, outs_only=outs_only) except DvcException: - logger.exception("failed to remove {}".format(target)) + logger.exception("failed to remove '{}'".format(target)) return 1 return 0 diff --git a/dvc/config.py b/dvc/config.py index 0854ae930..5c71da3d0 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -81,7 +81,7 @@ def Choices(*choices): *choices: pass allowed values as arguments, or pass a list or tuple as a single argument """ - return Any(*choices, msg="expected one of {}".format(",".join(choices))) + return Any(*choices, msg="expected one of {}".format(", ".join(choices))) class Config(object): # pylint: disable=too-many-instance-attributes From 655fa956d4288beddb708bb23638926cb979c223 Mon Sep 17 00:00:00 2001 From: Jorge Orpinel Date: Fri, 20 Dec 2019 18:59:45 -0700 Subject: [PATCH 29/33] diff: revert ' in string --- dvc/command/diff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dvc/command/diff.py b/dvc/command/diff.py index 4e82ea520..180508896 100644 --- a/dvc/command/diff.py +++ b/dvc/command/diff.py @@ -31,7 +31,7 @@ class CmdDiff(CmdBase): def _get_md5_string(sign, file_name, checksum): sample_msg = "" if file_name: - sample_msg = "'{}{}' with md5 {}\n" + sample_msg = "{}{} with md5 {}\n" sample_msg = sample_msg.format(sign, file_name, checksum) return sample_msg From 06822a060e05623df257e754ba0cf218602db169 Mon Sep 17 00:00:00 2001 From: Jorge Orpinel Date: Fri, 20 Dec 2019 19:00:09 -0700 Subject: [PATCH 30/33] dvc: use ' for dynamic output (through dvc/util/) --- dvc/remote/base.py | 2 +- dvc/remote/oss.py | 6 +++--- dvc/repo/add.py | 2 +- dvc/repo/gc.py | 2 +- dvc/stage.py | 4 ++-- dvc/updater.py | 20 ++++++++++---------- dvc/utils/__init__.py | 4 +++- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/dvc/remote/base.py b/dvc/remote/base.py index 57a1846a6..0f66b27ab 100644 --- a/dvc/remote/base.py +++ b/dvc/remote/base.py @@ -58,7 +58,7 @@ class RemoteCmdError(DvcException): class RemoteActionNotImplemented(DvcException): def __init__(self, action, scheme): - m = "{} is not supported by {} remote".format(action, scheme) + m = "{} is not supported for {} remotes".format(action, scheme) super(RemoteActionNotImplemented, self).__init__(m) diff --git a/dvc/remote/oss.py b/dvc/remote/oss.py index 9445fd0b2..0abf1a92e 100644 --- a/dvc/remote/oss.py +++ b/dvc/remote/oss.py @@ -69,9 +69,9 @@ class RemoteOSS(RemoteBASE): def oss_service(self): import oss2 - logger.debug("URL {}".format(self.path_info)) - logger.debug("key id {}".format(self.key_id)) - logger.debug("key secret {}".format(self.key_secret)) + logger.debug("URL: {}".format(self.path_info)) + logger.debug("key id: {}".format(self.key_id)) + logger.debug("key secret: {}".format(self.key_secret)) auth = oss2.Auth(self.key_id, self.key_secret) bucket = oss2.Bucket(auth, self.endpoint, self.path_info.bucket) diff --git a/dvc/repo/add.py b/dvc/repo/add.py index 85486c1f7..8fe180d41 100644 --- a/dvc/repo/add.py +++ b/dvc/repo/add.py @@ -37,7 +37,7 @@ def add(repo, targets, recursive=False, no_commit=False, fname=None): "You are adding a large directory '{target}' recursively," " consider tracking it as a whole instead.\n" "{purple}HINT:{nc} Remove the generated DVC-file and then" - " run {cyan}dvc add {target}{nc}".format( + " run `{cyan}dvc add {target}{nc}`".format( purple=colorama.Fore.MAGENTA, cyan=colorama.Fore.CYAN, nc=colorama.Style.RESET_ALL, diff --git a/dvc/repo/gc.py b/dvc/repo/gc.py index 8313f8feb..7d8e0dd22 100644 --- a/dvc/repo/gc.py +++ b/dvc/repo/gc.py @@ -12,7 +12,7 @@ logger = logging.getLogger(__name__) def _do_gc(typ, func, clist): removed = func(clist) if not removed: - logger.info("No unused {} cache to remove.".format(typ)) + logger.info("No unused `{}` cache to remove.".format(typ)) @locked diff --git a/dvc/stage.py b/dvc/stage.py index 236a5f2d3..7aafa5d75 100644 --- a/dvc/stage.py +++ b/dvc/stage.py @@ -116,7 +116,7 @@ class MissingDep(DvcException): else: dep = "dependency" - msg = "missing {}: {}".format(dep, ", ".join(map(str, deps))) + msg = "missing '{}': {}".format(dep, ", ".join(map(str, deps))) super(MissingDep, self).__init__(msg) @@ -128,7 +128,7 @@ class MissingDataSource(DvcException): if len(missing_files) > 1: source += "s" - msg = "missing data {}: {}".format(source, ", ".join(missing_files)) + msg = "missing data '{}': {}".format(source, ", ".join(missing_files)) super(MissingDataSource, self).__init__(msg) diff --git a/dvc/updater.py b/dvc/updater.py index 661221926..4c83084a6 100644 --- a/dvc/updater.py +++ b/dvc/updater.py @@ -124,12 +124,13 @@ class Updater(object): # pragma: no cover def _get_update_instructions(self): instructions = { - "pip": "Run {yellow}pip{reset} install dvc {blue}--upgrade{reset}", - "rpm": "Run {yellow}yum{reset} update dvc", - "brew": "Run {yellow}brew{reset} upgrade dvc", + "pip": "Run `{yellow}pip{reset} install dvc " + "{blue}--upgrade{reset}`", + "rpm": "Run `{yellow}yum{reset} update dvc`", + "brew": "Run `{yellow}brew{reset} upgrade dvc`", "deb": ( - "Run {yellow}apt-get{reset} install" - " {blue}--only-upgrade{reset} dvc" + "Run `{yellow}apt-get{reset} install" + " {blue}--only-upgrade{reset} dvc`" ), "binary": ( "To upgrade follow these steps:\n" @@ -137,12 +138,11 @@ class Updater(object): # pragma: no cover "2. Go to {blue}https://dvc.org{reset}\n" "3. Download and install new binary" ), - "conda": "Run {yellow}conda{reset} update dvc", - "choco": "Run {yellow}choco{reset} upgrade dvc", + "conda": "Run `{yellow}conda{reset} update dvc`", + "choco": "Run `{yellow}choco{reset} upgrade dvc`", None: ( - "Find the latest release at\n{blue}" - "https://github.com/iterative/dvc/releases/latest" - "{reset}" + "Find the latest release at\n" + "{blue}https://github.com/iterative/dvc/releases/latest{reset}" ), } diff --git a/dvc/utils/__init__.py b/dvc/utils/__init__.py index a1d15aa0b..92fd34a8a 100644 --- a/dvc/utils/__init__.py +++ b/dvc/utils/__init__.py @@ -50,7 +50,9 @@ def file_md5(fname): no_progress_bar = True if size >= LARGE_FILE_SIZE: no_progress_bar = False - msg = "Computing md5 for a large file {}. This is only done once." + msg = ( + "Computing md5 for a large file '{}'. This is only done once." + ) logger.info(msg.format(relpath(fname))) name = relpath(fname) From 14ab7c93d39e49700a15e05fc2e16adced3494b9 Mon Sep 17 00:00:00 2001 From: Jorge Orpinel Date: Fri, 20 Dec 2019 19:09:22 -0700 Subject: [PATCH 31/33] import-url: revert ' around exception string --- dvc/command/imp_url.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dvc/command/imp_url.py b/dvc/command/imp_url.py index 9c325dbe3..e072bc1e3 100644 --- a/dvc/command/imp_url.py +++ b/dvc/command/imp_url.py @@ -19,7 +19,7 @@ class CmdImportUrl(CmdBase): ) except DvcException: logger.exception( - "failed to import '{}'. You could also try downloading " + "failed to import {}. You could also try downloading " "it manually, and adding it with `dvc add`.".format( self.args.url ) From 781314dc8991cdc98aa5e91f9077a7a6ec789677 Mon Sep 17 00:00:00 2001 From: Jorge Orpinel Date: Fri, 20 Dec 2019 19:15:27 -0700 Subject: [PATCH 32/33] dvc: fix ` to ' in dvc/repo/gc.py --- dvc/repo/gc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dvc/repo/gc.py b/dvc/repo/gc.py index 7d8e0dd22..85d681b08 100644 --- a/dvc/repo/gc.py +++ b/dvc/repo/gc.py @@ -12,7 +12,7 @@ logger = logging.getLogger(__name__) def _do_gc(typ, func, clist): removed = func(clist) if not removed: - logger.info("No unused `{}` cache to remove.".format(typ)) + logger.info("No unused '{}' cache to remove.".format(typ)) @locked From 654525cddef86c2df8b090aafff3a6daa5fdc412 Mon Sep 17 00:00:00 2001 From: Jorge Orpinel Date: Fri, 20 Dec 2019 19:29:29 -0700 Subject: [PATCH 33/33] add: fix test with ` around DVC command --- tests/func/test_add.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/func/test_add.py b/tests/func/test_add.py index 1d99ed4c1..3c3b21519 100644 --- a/tests/func/test_add.py +++ b/tests/func/test_add.py @@ -92,7 +92,7 @@ class TestAddCmdDirectoryRecursive(TestDvc): "You are adding a large directory 'large-dir' recursively," " consider tracking it as a whole instead.\n" "{purple}HINT:{nc} Remove the generated DVC-file and then" - " run {cyan}dvc add large-dir{nc}".format( + " run `{cyan}dvc add large-dir{nc}`".format( purple=colorama.Fore.MAGENTA, cyan=colorama.Fore.CYAN, nc=colorama.Style.RESET_ALL,