tests: introduce dvc.testing

This is a very early version of test utils for dvc plugins. This module
consists of existing tests with minimal changes and is going to evolve
a lot as our plugins are getting filled in and pytest-test-utils matures.
This commit is contained in:
Ruslan Kuprieiev
2021-12-02 09:08:40 +02:00
parent 004e15c2c0
commit 09f48a5aaa
36 changed files with 1338 additions and 1009 deletions
+2 -2
View File
@@ -219,7 +219,7 @@ def test_auto_push_during_iterations(
):
# set up remote repo
remote = git_upstream.url if use_url else git_upstream.remote
git_upstream.scm.fetch_refspecs(str(tmp_dir), ["master:master"])
git_upstream.tmp_dir.scm.fetch_refspecs(str(tmp_dir), ["master:master"])
monkeypatch.setenv(DVC_EXP_GIT_REMOTE, remote)
auto_push_spy = mocker.spy(BaseExecutor, "_auto_push")
@@ -233,7 +233,7 @@ def test_auto_push_during_iterations(
assert (tmp_dir / "foo").read_text() == "4"
exp = first(results)
ref_info = first(exp_refs_by_rev(scm, exp))
assert git_upstream.scm.get_ref(str(ref_info)) == exp
assert git_upstream.tmp_dir.scm.get_ref(str(ref_info)) == exp
assert auto_push_spy.call_count == 2
assert auto_push_spy.call_args[0][2] == remote
+31 -31
View File
@@ -20,30 +20,30 @@ def test_push(tmp_dir, scm, dvc, git_upstream, exp_stage, use_url):
ref_info = first(exp_refs_by_rev(scm, exp))
dvc.experiments.push(remote, ref_info.name)
assert git_upstream.scm.get_ref(str(ref_info)) == exp
assert git_upstream.tmp_dir.scm.get_ref(str(ref_info)) == exp
git_upstream.scm.remove_ref(str(ref_info))
git_upstream.tmp_dir.scm.remove_ref(str(ref_info))
dvc.experiments.push(remote, str(ref_info))
assert git_upstream.scm.get_ref(str(ref_info)) == exp
assert git_upstream.tmp_dir.scm.get_ref(str(ref_info)) == exp
def test_push_diverged(tmp_dir, scm, dvc, git_upstream, exp_stage):
git_upstream.scm_gen("foo", "foo", commit="init")
remote_rev = git_upstream.scm.get_rev()
git_upstream.tmp_dir.scm_gen("foo", "foo", commit="init")
remote_rev = git_upstream.tmp_dir.scm.get_rev()
results = dvc.experiments.run(exp_stage.addressing, params=["foo=2"])
exp = first(results)
ref_info = first(exp_refs_by_rev(scm, exp))
git_upstream.scm.set_ref(str(ref_info), remote_rev)
git_upstream.tmp_dir.scm.set_ref(str(ref_info), remote_rev)
with pytest.raises(DvcException):
dvc.experiments.push(git_upstream.remote, ref_info.name)
assert git_upstream.scm.get_ref(str(ref_info)) == remote_rev
assert git_upstream.tmp_dir.scm.get_ref(str(ref_info)) == remote_rev
dvc.experiments.push(git_upstream.remote, ref_info.name, force=True)
assert git_upstream.scm.get_ref(str(ref_info)) == exp
assert git_upstream.tmp_dir.scm.get_ref(str(ref_info)) == exp
def test_push_checkpoint(tmp_dir, scm, dvc, git_upstream, checkpoint_stage):
@@ -54,7 +54,7 @@ def test_push_checkpoint(tmp_dir, scm, dvc, git_upstream, checkpoint_stage):
ref_info_a = first(exp_refs_by_rev(scm, exp_a))
dvc.experiments.push(git_upstream.remote, ref_info_a.name, force=True)
assert git_upstream.scm.get_ref(str(ref_info_a)) == exp_a
assert git_upstream.tmp_dir.scm.get_ref(str(ref_info_a)) == exp_a
results = dvc.experiments.run(
checkpoint_stage.addressing, checkpoint_resume=exp_a
@@ -65,7 +65,7 @@ def test_push_checkpoint(tmp_dir, scm, dvc, git_upstream, checkpoint_stage):
tmp_dir.scm_gen("new", "new", commit="new")
dvc.experiments.push(git_upstream.remote, ref_info_b.name, force=True)
assert git_upstream.scm.get_ref(str(ref_info_b)) == exp_b
assert git_upstream.tmp_dir.scm.get_ref(str(ref_info_b)) == exp_b
def test_push_ambiguous_name(tmp_dir, scm, dvc, git_upstream, exp_stage):
@@ -87,7 +87,7 @@ def test_push_ambiguous_name(tmp_dir, scm, dvc, git_upstream, exp_stage):
ref_info_b = first(exp_refs_by_rev(scm, exp_b))
dvc.experiments.push(remote, "foo")
assert git_upstream.scm.get_ref(str(ref_info_b)) == exp_b
assert git_upstream.tmp_dir.scm.get_ref(str(ref_info_b)) == exp_b
tmp_dir.scm_gen("new", "new 2", commit="new 2")
@@ -95,7 +95,7 @@ def test_push_ambiguous_name(tmp_dir, scm, dvc, git_upstream, exp_stage):
dvc.experiments.push(remote, "foo")
dvc.experiments.push(remote, str(ref_info_a))
assert git_upstream.scm.get_ref(str(ref_info_a)) == exp_a
assert git_upstream.tmp_dir.scm.get_ref(str(ref_info_a)) == exp_a
@pytest.mark.parametrize("use_url", [True, False])
@@ -117,8 +117,8 @@ def test_list_remote(tmp_dir, scm, dvc, git_downstream, exp_stage, use_url):
remote = git_downstream.url if use_url else git_downstream.remote
assert git_downstream.scm.get_ref("HEAD") != scm.get_ref("HEAD")
downstream_exp = git_downstream.dvc.experiments
assert git_downstream.tmp_dir.scm.get_ref("HEAD") != scm.get_ref("HEAD")
downstream_exp = git_downstream.tmp_dir.dvc.experiments
assert downstream_exp.ls(git_remote=remote) == {}
exp_list = downstream_exp.ls(rev=baseline_a, git_remote=remote)
@@ -138,7 +138,7 @@ def test_pull(tmp_dir, scm, dvc, git_downstream, exp_stage, use_url):
from dvc.exceptions import InvalidArgumentError
remote = git_downstream.url if use_url else git_downstream.remote
downstream_exp = git_downstream.dvc.experiments
downstream_exp = git_downstream.tmp_dir.dvc.experiments
with pytest.raises(InvalidArgumentError):
downstream_exp.pull(remote, "foo")
@@ -147,31 +147,31 @@ def test_pull(tmp_dir, scm, dvc, git_downstream, exp_stage, use_url):
ref_info = first(exp_refs_by_rev(scm, exp))
downstream_exp.pull(remote, ref_info.name)
assert git_downstream.scm.get_ref(str(ref_info)) == exp
assert git_downstream.tmp_dir.scm.get_ref(str(ref_info)) == exp
git_downstream.scm.remove_ref(str(ref_info))
git_downstream.tmp_dir.scm.remove_ref(str(ref_info))
downstream_exp.pull(remote, str(ref_info))
assert git_downstream.scm.get_ref(str(ref_info)) == exp
assert git_downstream.tmp_dir.scm.get_ref(str(ref_info)) == exp
def test_pull_diverged(tmp_dir, scm, dvc, git_downstream, exp_stage):
git_downstream.scm_gen("foo", "foo", commit="init")
remote_rev = git_downstream.scm.get_rev()
git_downstream.tmp_dir.scm_gen("foo", "foo", commit="init")
remote_rev = git_downstream.tmp_dir.scm.get_rev()
results = dvc.experiments.run(exp_stage.addressing, params=["foo=2"])
exp = first(results)
ref_info = first(exp_refs_by_rev(scm, exp))
git_downstream.scm.set_ref(str(ref_info), remote_rev)
git_downstream.tmp_dir.scm.set_ref(str(ref_info), remote_rev)
downstream_exp = git_downstream.dvc.experiments
downstream_exp = git_downstream.tmp_dir.dvc.experiments
with pytest.raises(DvcException):
downstream_exp.pull(git_downstream.remote, ref_info.name)
assert git_downstream.scm.get_ref(str(ref_info)) == remote_rev
assert git_downstream.tmp_dir.scm.get_ref(str(ref_info)) == remote_rev
downstream_exp.pull(git_downstream.remote, ref_info.name, force=True)
assert git_downstream.scm.get_ref(str(ref_info)) == exp
assert git_downstream.tmp_dir.scm.get_ref(str(ref_info)) == exp
def test_pull_checkpoint(tmp_dir, scm, dvc, git_downstream, checkpoint_stage):
@@ -181,9 +181,9 @@ def test_pull_checkpoint(tmp_dir, scm, dvc, git_downstream, checkpoint_stage):
exp_a = first(results)
ref_info_a = first(exp_refs_by_rev(scm, exp_a))
downstream_exp = git_downstream.dvc.experiments
downstream_exp = git_downstream.tmp_dir.dvc.experiments
downstream_exp.pull(git_downstream.remote, ref_info_a.name, force=True)
assert git_downstream.scm.get_ref(str(ref_info_a)) == exp_a
assert git_downstream.tmp_dir.scm.get_ref(str(ref_info_a)) == exp_a
results = dvc.experiments.run(
checkpoint_stage.addressing, checkpoint_resume=exp_a
@@ -192,7 +192,7 @@ def test_pull_checkpoint(tmp_dir, scm, dvc, git_downstream, checkpoint_stage):
ref_info_b = first(exp_refs_by_rev(scm, exp_b))
downstream_exp.pull(git_downstream.remote, ref_info_b.name, force=True)
assert git_downstream.scm.get_ref(str(ref_info_b)) == exp_b
assert git_downstream.tmp_dir.scm.get_ref(str(ref_info_b)) == exp_b
def test_pull_ambiguous_name(tmp_dir, scm, dvc, git_downstream, exp_stage):
@@ -212,16 +212,16 @@ def test_pull_ambiguous_name(tmp_dir, scm, dvc, git_downstream, exp_stage):
ref_info_b = first(exp_refs_by_rev(scm, exp_b))
remote = git_downstream.remote
downstream_exp = git_downstream.dvc.experiments
downstream_exp = git_downstream.tmp_dir.dvc.experiments
with pytest.raises(InvalidArgumentError):
downstream_exp.pull(remote, "foo")
downstream_exp.pull(remote, str(ref_info_b))
assert git_downstream.scm.get_ref(str(ref_info_b)) == exp_b
assert git_downstream.tmp_dir.scm.get_ref(str(ref_info_b)) == exp_b
with git_downstream.scm.detach_head(ref_info_a.baseline_sha):
with git_downstream.tmp_dir.scm.detach_head(ref_info_a.baseline_sha):
downstream_exp.pull(remote, "foo")
assert git_downstream.scm.get_ref(str(ref_info_a)) == exp_a
assert git_downstream.tmp_dir.scm.get_ref(str(ref_info_a)) == exp_a
def test_push_pull_cache(
+6 -4
View File
@@ -107,12 +107,14 @@ def test_remove_remote(tmp_dir, scm, dvc, exp_stage, git_upstream, use_url):
ref_info = first(exp_refs_by_rev(scm, exp))
ref_info_list.append(ref_info)
dvc.experiments.push(remote, ref_info.name)
assert git_upstream.scm.get_ref(str(ref_info)) == exp
assert git_upstream.tmp_dir.scm.get_ref(str(ref_info)) == exp
dvc.experiments.remove(
remote=remote, exp_names=[str(ref_info_list[0]), ref_info_list[1].name]
)
assert git_upstream.scm.get_ref(str(ref_info_list[0])) is None
assert git_upstream.scm.get_ref(str(ref_info_list[1])) is None
assert git_upstream.scm.get_ref(str(ref_info_list[2])) == exp_list[2]
assert git_upstream.tmp_dir.scm.get_ref(str(ref_info_list[0])) is None
assert git_upstream.tmp_dir.scm.get_ref(str(ref_info_list[1])) is None
assert (
git_upstream.tmp_dir.scm.get_ref(str(ref_info_list[2])) == exp_list[2]
)
+70 -96
View File
@@ -34,6 +34,7 @@ from dvc.stage.exceptions import (
StagePathNotFoundError,
)
from dvc.system import System
from dvc.testing.test_workspace import TestAdd
from dvc.utils import LARGE_DIR_SIZE, file_md5, relpath
from dvc.utils.fs import path_isin
from dvc.utils.serialize import YAMLFileCorruptedError, load_yaml
@@ -291,59 +292,72 @@ def test_add_filtered_files_in_dir(
assert stage.outs[0].def_path in expected_def_paths
@pytest.mark.parametrize(
"workspace, hash_name, hash_value",
[
(
pytest.lazy_fixture("local_cloud"),
"md5",
"8c7dd922ad47494fc02c388e12c00eac",
),
pytest.param(
pytest.lazy_fixture("ssh"),
"md5",
"8c7dd922ad47494fc02c388e12c00eac",
marks=pytest.mark.skipif(
os.name == "nt", reason="disabled on windows"
class TestAddExternal(TestAdd):
@pytest.mark.parametrize(
"workspace, hash_name, hash_value",
[
(
"local",
"md5",
"8c7dd922ad47494fc02c388e12c00eac",
),
),
(
pytest.lazy_fixture("s3"),
"etag",
"8c7dd922ad47494fc02c388e12c00eac",
),
(
pytest.lazy_fixture("hdfs"),
"checksum",
"000002000000000000000000a86fe4d846edc1bf4c355cb6112f141e",
),
(
pytest.lazy_fixture("webhdfs"),
"checksum",
"000002000000000000000000a86fe4d846edc1bf4c355cb6112f141e00000000",
),
],
indirect=["workspace"],
)
def test_add_external_file(tmp_dir, dvc, workspace, hash_name, hash_value):
workspace.gen("file", "file")
with pytest.raises(StageExternalOutputsError):
dvc.add(workspace.url)
dvc.add("remote://workspace/file")
assert (tmp_dir / "file.dvc").read_text() == (
"outs:\n"
f"- {hash_name}: {hash_value}\n"
" size: 4\n"
" path: remote://workspace/file\n"
pytest.param(
"ssh",
"md5",
"8c7dd922ad47494fc02c388e12c00eac",
marks=pytest.mark.skipif(
os.name == "nt", reason="disabled on windows"
),
),
(
"s3",
"etag",
"8c7dd922ad47494fc02c388e12c00eac",
),
(
"hdfs",
"checksum",
"000002000000000000000000a86fe4d846edc1bf4c355cb6112f141e",
),
(
"webhdfs",
"checksum",
"000002000000000000000000a86fe4d846edc1bf4c355cb6112f141e00000000", # noqa: E501
),
],
indirect=["workspace"],
)
assert (workspace / "file").read_text() == "file"
assert (
workspace / "cache" / hash_value[:2] / hash_value[2:]
).read_text() == "file"
def test_add(self, tmp_dir, dvc, workspace, hash_name, hash_value):
super().test_add(tmp_dir, dvc, workspace, hash_name, hash_value)
assert dvc.status() == {}
@pytest.mark.parametrize(
"workspace, hash_name, dir_hash_value",
[
(
"local",
"md5",
"b6dcab6ccd17ca0a8bf4a215a37d14cc.dir",
),
pytest.param(
"ssh",
"md5",
"b6dcab6ccd17ca0a8bf4a215a37d14cc.dir",
marks=pytest.mark.skipif(
os.name == "nt", reason="disabled on windows"
),
),
(
"s3",
"etag",
"ec602a6ba97b2dd07bd6d2cd89674a60.dir",
),
],
indirect=["workspace"],
)
def test_add_dir(self, tmp_dir, dvc, workspace, hash_name, dir_hash_value):
super().test_add_dir(
tmp_dir, dvc, workspace, hash_name, dir_hash_value
)
def test_add_external_relpath(tmp_dir, dvc, local_cloud):
@@ -364,44 +378,6 @@ def test_add_external_relpath(tmp_dir, dvc, local_cloud):
assert dvc.status() == {}
@pytest.mark.parametrize(
"workspace, hash_name, hash_value",
[
(
pytest.lazy_fixture("local_cloud"),
"md5",
"b6dcab6ccd17ca0a8bf4a215a37d14cc.dir",
),
pytest.param(
pytest.lazy_fixture("ssh"),
"md5",
"b6dcab6ccd17ca0a8bf4a215a37d14cc.dir",
marks=pytest.mark.skipif(
os.name == "nt", reason="disabled on windows"
),
),
(
pytest.lazy_fixture("s3"),
"etag",
"ec602a6ba97b2dd07bd6d2cd89674a60.dir",
),
],
indirect=["workspace"],
)
def test_add_external_dir(tmp_dir, dvc, workspace, hash_name, hash_value):
workspace.gen({"dir": {"file": "file", "subdir": {"subfile": "subfile"}}})
dvc.add("remote://workspace/dir")
assert (tmp_dir / "dir.dvc").read_text() == (
"outs:\n"
f"- {hash_name}: {hash_value}\n"
" size: 11\n"
" nfiles: 2\n"
" path: remote://workspace/dir\n"
)
assert (workspace / "cache" / hash_value[:2] / hash_value[2:]).is_file()
class TestAddLocalRemoteFile(TestDvc):
def test(self):
"""
@@ -1159,19 +1135,17 @@ def test_add_to_cache_invalid_combinations(dvc, invalid_opt, kwargs):
@pytest.mark.parametrize(
"workspace",
[
pytest.lazy_fixture("local_cloud"),
pytest.lazy_fixture("s3"),
"local",
"s3",
pytest.param("gs", marks=pytest.mark.needs_internet),
"hdfs",
pytest.param(
pytest.lazy_fixture("gs"), marks=pytest.mark.needs_internet
),
pytest.lazy_fixture("hdfs"),
pytest.param(
pytest.lazy_fixture("ssh"),
"ssh",
marks=pytest.mark.skipif(
os.name == "nt", reason="disabled on windows"
),
),
pytest.lazy_fixture("http"),
"http",
],
indirect=True,
)
+26 -47
View File
@@ -5,10 +5,11 @@ from funcy import first, get_in
from dvc import api
from dvc.exceptions import FileMissingError, OutputNotFoundError
from dvc.testing.test_api import TestAPI as _TestAPI
from dvc.utils.fs import remove
from tests.unit.fs.test_repo import make_subrepo
cloud_names = [
clouds = [
"s3",
"gs",
"azure",
@@ -20,23 +21,19 @@ cloud_names = [
"webdav",
"webhdfs",
]
clouds = [pytest.lazy_fixture(cloud) for cloud in cloud_names]
all_clouds = [pytest.lazy_fixture("local_cloud")] + clouds
all_clouds = ["local"] + clouds
# `lazy_fixture` is confusing pylint, pylint: disable=unused-argument
@pytest.mark.needs_internet
@pytest.mark.parametrize("remote", clouds, indirect=True)
def test_get_url(tmp_dir, dvc, remote):
tmp_dir.dvc_gen("foo", "foo")
expected_url = (remote / "ac/bd18db4cc2f85cedef654fccc4a4d8").url
assert api.get_url("foo") == expected_url
class TestAPI(_TestAPI):
pass
@pytest.mark.needs_internet
@pytest.mark.parametrize("cloud", clouds)
@pytest.mark.parametrize("cloud", clouds, indirect=True)
def test_get_url_external(tmp_dir, erepo_dir, cloud):
erepo_dir.add_remote(config=cloud.config)
with erepo_dir.chdir():
@@ -58,36 +55,21 @@ def test_get_url_requires_dvc(tmp_dir, scm):
api.get_url("foo", repo=f"file://{tmp_dir}")
@pytest.mark.needs_internet
@pytest.mark.parametrize("remote", all_clouds, indirect=True)
def test_open(tmp_dir, dvc, remote):
tmp_dir.dvc_gen("foo", "foo-text")
dvc.push()
# Remove cache to force download
remove(dvc.odb.local.cache_dir)
with api.open("foo") as fd:
assert fd.read() == "foo-text"
@pytest.mark.needs_internet
@pytest.mark.parametrize(
"cloud",
[
pytest.lazy_fixture(cloud)
for cloud in [
"s3",
"gs",
"azure",
"gdrive",
"oss",
"http",
"hdfs",
"ssh",
"webdav",
]
"s3",
"gs",
"azure",
"gdrive",
"oss",
"http",
"hdfs",
"ssh",
"webdav",
],
indirect=True,
)
def test_open_external(tmp_dir, erepo_dir, cloud):
erepo_dir.add_remote(config=cloud.config)
@@ -129,18 +111,15 @@ def test_open_granular(tmp_dir, dvc, remote):
@pytest.mark.parametrize(
"remote",
[
pytest.lazy_fixture(cloud)
for cloud in [
"s3",
"gs",
"azure",
"gdrive",
"oss",
"ssh",
"http",
"hdfs",
"webdav",
]
"s3",
"gs",
"azure",
"gdrive",
"oss",
"ssh",
"http",
"hdfs",
"webdav",
],
indirect=True,
)
@@ -195,7 +174,7 @@ def test_open_rev(tmp_dir, scm, dvc):
@pytest.mark.parametrize("as_external", [True, False])
@pytest.mark.parametrize("remote", [pytest.lazy_fixture("ssh")], indirect=True)
@pytest.mark.parametrize("remote", ["ssh"], indirect=True)
@pytest.mark.parametrize(
"files, to_read",
[
+16 -105
View File
@@ -9,120 +9,31 @@ import dvc as dvc_module
from dvc.external_repo import clean_repos
from dvc.main import main
from dvc.stage.exceptions import StageNotFound
from dvc.utils.fs import move, remove
from dvc.testing.test_remote import TestRemote as _TestRemote
from dvc.utils.fs import remove
all_clouds = [
pytest.lazy_fixture(cloud)
for cloud in [
"s3",
"gs",
"azure",
"ssh",
"http",
"hdfs",
"webdav",
"webhdfs",
"oss",
"gdrive",
]
"s3",
"gs",
"azure",
"ssh",
"http",
"hdfs",
"webdav",
"webhdfs",
"oss",
"gdrive",
]
# Clouds that implement the general methods that can be tested
# for functional tests that require extensive apis (e.g traversing
# via walk_files())
full_clouds = [
pytest.lazy_fixture(cloud)
for cloud in ["s3", "gs", "azure", "ssh", "hdfs"]
]
full_clouds = ["s3", "gs", "azure", "ssh", "hdfs"]
@pytest.mark.needs_internet
@pytest.mark.parametrize("remote", all_clouds, indirect=True)
def test_cloud(tmp_dir, dvc, remote): # pylint:disable=unused-argument
(stage,) = tmp_dir.dvc_gen("foo", "foo")
out = stage.outs[0]
cache = out.cache_path
foo_hash = out.hash_info
foo_hashes = out.get_used_objs().get(None, set())
(stage_dir,) = tmp_dir.dvc_gen(
{
"data_dir": {
"data_sub_dir": {"data_sub": "data_sub"},
"data": "data",
"empty": "",
}
}
)
out_dir = stage_dir.outs[0]
cache_dir = out_dir.cache_path
dir_hash = out_dir.hash_info
dir_hashes = {dir_hash} | {oid for _, _, oid in out_dir.obj}
def _check_status(status, **kwargs):
for key in ("ok", "missing", "new", "deleted"):
expected = kwargs.get(key, set())
assert expected == set(getattr(status, key))
# Check status
status = dvc.cloud.status(foo_hashes)
_check_status(status, new={foo_hash})
status_dir = dvc.cloud.status(dir_hashes)
_check_status(status_dir, new=dir_hashes)
# Move cache and check status
# See issue https://github.com/iterative/dvc/issues/4383 for details
backup_dir = dvc.odb.local.cache_dir + ".backup"
move(dvc.odb.local.cache_dir, backup_dir)
status = dvc.cloud.status(foo_hashes)
_check_status(status, missing={foo_hash})
status_dir = dvc.cloud.status(dir_hashes)
_check_status(status_dir, missing=dir_hashes)
# Restore original cache:
remove(dvc.odb.local.cache_dir)
move(backup_dir, dvc.odb.local.cache_dir)
# Push and check status
dvc.cloud.push(foo_hashes)
assert os.path.exists(cache)
assert os.path.isfile(cache)
dvc.cloud.push(dir_hashes)
assert os.path.isfile(cache_dir)
status = dvc.cloud.status(foo_hashes)
_check_status(status, ok={foo_hash})
status_dir = dvc.cloud.status(dir_hashes)
_check_status(status_dir, ok=dir_hashes)
# Remove and check status
remove(dvc.odb.local.cache_dir)
status = dvc.cloud.status(foo_hashes)
_check_status(status, deleted={foo_hash})
status_dir = dvc.cloud.status(dir_hashes)
_check_status(status_dir, deleted=dir_hashes)
# Pull and check status
dvc.cloud.pull(foo_hashes)
assert os.path.exists(cache)
assert os.path.isfile(cache)
with open(cache, encoding="utf-8") as fd:
assert fd.read() == "foo"
dvc.cloud.pull(dir_hashes)
assert os.path.isfile(cache_dir)
status = dvc.cloud.status(foo_hashes)
_check_status(status, ok={foo_hash})
status_dir = dvc.cloud.status(dir_hashes)
_check_status(status_dir, ok=dir_hashes)
class TestRemote(_TestRemote):
pass
@pytest.mark.needs_internet
@@ -448,7 +359,7 @@ def test_pipeline_file_target_ops(tmp_dir, dvc, run_copy, local_remote):
assert set(dvc.pull()["added"]) == set(outs)
# clean everything in remote and push
from tests.dir_helpers import TmpDir
from dvc.testing.tmp_dir import TmpDir
clean(TmpDir(path).iterdir())
dvc.push(["dvc.yaml:copy-ipsum-baz"])
+5 -5
View File
@@ -346,12 +346,12 @@ def test_gc_not_collect_pipeline_tracked_files(tmp_dir, dvc, run_copy):
@pytest.mark.parametrize(
"workspace",
[
pytest.lazy_fixture("local_cloud"),
pytest.lazy_fixture("s3"),
pytest.lazy_fixture("hdfs"),
pytest.lazy_fixture("webhdfs"),
"local",
"s3",
"hdfs",
"webhdfs",
pytest.param(
pytest.lazy_fixture("ssh"),
"ssh",
marks=pytest.mark.skipif(
os.name == "nt", reason="disabled on windows"
),
+1 -1
View File
@@ -9,9 +9,9 @@ from dvc.ignore import DvcIgnore, DvcIgnorePatterns
from dvc.output import OutputIsIgnoredError
from dvc.pathspec_math import PatternInfo, merge_patterns
from dvc.repo import Repo
from dvc.testing.tmp_dir import TmpDir
from dvc.types import List
from dvc.utils.fs import get_mtime_and_size
from tests.dir_helpers import TmpDir
def _to_pattern_info_list(str_list: List):
+110 -142
View File
@@ -8,8 +8,8 @@ import pytest
from dvc.dependency.base import DependencyDoesNotExistError
from dvc.exceptions import InvalidArgumentError
from dvc.main import main
from dvc.objects.db import ODBManager
from dvc.stage import Stage
from dvc.testing.test_workspace import TestImport as _TestImport
from dvc.utils.fs import makedirs
from tests.basic_env import TestDvc
@@ -118,102 +118,108 @@ def test_import_url_with_no_exec(tmp_dir, dvc, erepo_dir):
assert not dst.exists()
@pytest.mark.parametrize(
"workspace",
[
pytest.lazy_fixture("local_cloud"),
pytest.lazy_fixture("s3"),
pytest.lazy_fixture("azure"),
pytest.param(
pytest.lazy_fixture("gs"), marks=pytest.mark.needs_internet
),
pytest.lazy_fixture("hdfs"),
pytest.lazy_fixture("webhdfs"),
pytest.param(
pytest.lazy_fixture("ssh"),
marks=pytest.mark.skipif(
os.name == "nt", reason="disabled on windows"
class TestImport(_TestImport):
@pytest.mark.parametrize(
"workspace",
[
"local",
"s3",
"azure",
pytest.param("gs", marks=pytest.mark.needs_internet),
"hdfs",
"webhdfs",
pytest.param(
"ssh",
marks=pytest.mark.skipif(
os.name == "nt", reason="disabled on windows"
),
),
),
pytest.lazy_fixture("http"),
],
indirect=True,
)
def test_import_url(tmp_dir, dvc, workspace):
workspace.gen("file", "file")
assert not (tmp_dir / "file").exists() # sanity check
dvc.imp_url("remote://workspace/file")
assert (tmp_dir / "file").read_text() == "file"
"http",
],
indirect=True,
)
def test_import(self, tmp_dir, dvc, workspace):
super().test_import(tmp_dir, dvc, workspace)
assert dvc.status() == {}
@pytest.mark.parametrize(
"workspace, stage_md5, dir_md5",
[
(
pytest.lazy_fixture("local_cloud"),
"dc24e1271084ee317ac3c2656fb8812b",
"b6dcab6ccd17ca0a8bf4a215a37d14cc.dir",
),
(
pytest.lazy_fixture("s3"),
"2aa17f8daa26996b3f7a4cf8888ac9ac",
"ec602a6ba97b2dd07bd6d2cd89674a60.dir",
),
(
pytest.lazy_fixture("azure"),
None, # ETags for azure are not consistent with the actual
None, # content of the object, so they will change every time
# we create new objects. We'll skip stage content check for Azure.
),
(
pytest.lazy_fixture("hdfs"),
"ec0943f83357f702033c98e70b853c8c",
"e6dcd267966dc628d732874f94ef4280.dir",
),
pytest.param(
pytest.lazy_fixture("ssh"),
"dc24e1271084ee317ac3c2656fb8812b",
"b6dcab6ccd17ca0a8bf4a215a37d14cc.dir",
marks=pytest.mark.skipif(
os.name == "nt", reason="disabled on windows"
@pytest.mark.parametrize(
"workspace, stage_md5, dir_md5",
[
(
"local",
"dc24e1271084ee317ac3c2656fb8812b",
"b6dcab6ccd17ca0a8bf4a215a37d14cc.dir",
),
),
],
indirect=["workspace"],
)
def test_import_url_dir(tmp_dir, dvc, workspace, stage_md5, dir_md5):
workspace.gen({"dir": {"file": "file", "subdir": {"subfile": "subfile"}}})
(
"s3",
"2aa17f8daa26996b3f7a4cf8888ac9ac",
"ec602a6ba97b2dd07bd6d2cd89674a60.dir",
),
(
"azure",
None, # ETags for azure are not consistent with the actual
None, # content of the object, so they will change every time
# we create new objects. We'll skip stage content
# check for Azure.
),
(
"hdfs",
"ec0943f83357f702033c98e70b853c8c",
"e6dcd267966dc628d732874f94ef4280.dir",
),
pytest.param(
"ssh",
"dc24e1271084ee317ac3c2656fb8812b",
"b6dcab6ccd17ca0a8bf4a215a37d14cc.dir",
marks=pytest.mark.skipif(
os.name == "nt", reason="disabled on windows"
),
),
],
indirect=["workspace"],
)
def test_import_dir(self, tmp_dir, dvc, workspace, stage_md5, dir_md5):
super().test_import_dir(tmp_dir, dvc, workspace, stage_md5, dir_md5)
# remove external cache to make sure that we don't need it to import dirs
with dvc.config.edit() as conf:
del conf["cache"]
dvc.odb = ODBManager(dvc)
assert not (tmp_dir / "dir").exists() # sanity check
dvc.imp_url("remote://workspace/dir")
assert set(os.listdir(tmp_dir / "dir")) == {"file", "subdir"}
assert (tmp_dir / "dir" / "file").read_text() == "file"
assert list(os.listdir(tmp_dir / "dir" / "subdir")) == ["subfile"]
assert (tmp_dir / "dir" / "subdir" / "subfile").read_text() == "subfile"
assert dvc.status() == {}
if stage_md5 is not None and dir_md5 is not None:
assert (tmp_dir / "dir.dvc").read_text() == (
f"md5: {stage_md5}\n"
"frozen: true\n"
"deps:\n"
f"- md5: {dir_md5}\n"
" size: 11\n"
" nfiles: 2\n"
" path: remote://workspace/dir\n"
"outs:\n"
"- md5: b6dcab6ccd17ca0a8bf4a215a37d14cc.dir\n"
" size: 11\n"
" nfiles: 2\n"
" path: dir\n"
@pytest.mark.parametrize(
"workspace, is_object_storage",
[
("hdfs", False),
pytest.param(
"s3",
True,
marks=pytest.mark.xfail(
reason="https://github.com/iterative/dvc/issues/5521",
),
),
pytest.param(
"gs",
True,
marks=pytest.mark.xfail(
reason="https://github.com/iterative/dvc/issues/5521",
),
),
pytest.param(
"azure",
True,
marks=pytest.mark.xfail(
reason="https://github.com/iterative/dvc/issues/5521",
),
),
pytest.param(
"ssh",
False,
marks=pytest.mark.skipif(
os.name == "nt", reason="disabled on windows"
),
),
],
indirect=["workspace"],
)
def test_import_empty_dir(
self, tmp_dir, dvc, workspace, is_object_storage
):
super().test_import_empty_dir(
tmp_dir, dvc, workspace, is_object_storage
)
@@ -257,19 +263,17 @@ def test_import_url_preserve_meta(tmp_dir, dvc):
@pytest.mark.parametrize(
"workspace",
[
pytest.lazy_fixture("local_cloud"),
pytest.lazy_fixture("s3"),
"local",
"s3",
pytest.param("gs", marks=pytest.mark.needs_internet),
"hdfs",
pytest.param(
pytest.lazy_fixture("gs"), marks=pytest.mark.needs_internet
),
pytest.lazy_fixture("hdfs"),
pytest.param(
pytest.lazy_fixture("ssh"),
"ssh",
marks=pytest.mark.skipif(
os.name == "nt", reason="disabled on windows"
),
),
pytest.lazy_fixture("http"),
"http",
],
indirect=True,
)
@@ -300,14 +304,12 @@ def test_import_url_to_remote_single_file(
@pytest.mark.parametrize(
"workspace",
[
pytest.lazy_fixture("local_cloud"),
pytest.lazy_fixture("s3"),
"local",
"s3",
pytest.param("gs", marks=pytest.mark.needs_internet),
"hdfs",
pytest.param(
pytest.lazy_fixture("gs"), marks=pytest.mark.needs_internet
),
pytest.lazy_fixture("hdfs"),
pytest.param(
pytest.lazy_fixture("ssh"),
"ssh",
marks=pytest.mark.skipif(
os.name == "nt", reason="disabled on windows"
),
@@ -381,40 +383,6 @@ empty_xfail = pytest.mark.xfail(
)
@pytest.mark.parametrize(
"workspace",
[
pytest.lazy_fixture("hdfs"),
pytest.param(pytest.lazy_fixture("s3"), marks=empty_xfail),
pytest.param(pytest.lazy_fixture("gs"), marks=empty_xfail),
pytest.param(pytest.lazy_fixture("azure"), marks=empty_xfail),
pytest.param(
pytest.lazy_fixture("ssh"),
marks=pytest.mark.skipif(
os.name == "nt", reason="disabled on windows"
),
),
],
indirect=True,
)
def test_import_url_empty_directory(tmp_dir, dvc, workspace):
# prefix based storage services (e.g s3) doesn't have the real concept
# of directories. So instead we create an empty file that ends with a
# trailing slash in order to actually support this operation
if workspace.IS_OBJECT_STORAGE:
contents = ""
else:
contents = {}
workspace.gen({"empty_dir/": contents})
dvc.imp_url("remote://workspace/empty_dir/")
empty_dir = tmp_dir / "empty_dir"
assert empty_dir.is_dir()
assert tuple(empty_dir.iterdir()) == ()
def test_import_url_to_remote_status(tmp_dir, dvc, local_cloud, local_remote):
local_cloud.gen("foo", "foo")
+1 -3
View File
@@ -114,9 +114,7 @@ def test_merge_conflict(tmp_dir, dvc, ancestor, our, their, error, caplog):
assert error in caplog.text
@pytest.mark.parametrize(
"workspace", [pytest.lazy_fixture("ssh")], indirect=True
)
@pytest.mark.parametrize("workspace", ["ssh"], indirect=True)
def test_merge_different_output_types(tmp_dir, dvc, caplog, workspace):
(tmp_dir / "ancestor").touch()
+4 -4
View File
@@ -354,13 +354,13 @@ def test_run_overwrite_preserves_meta_and_comment(tmp_dir, dvc, run_copy):
"workspace, hash_name, foo_hash, bar_hash",
[
(
pytest.lazy_fixture("local_cloud"),
"local",
"md5",
"acbd18db4cc2f85cedef654fccc4a4d8",
"37b51d194a7513e45b56f6524f2d51f2",
),
pytest.param(
pytest.lazy_fixture("ssh"),
"ssh",
"md5",
"acbd18db4cc2f85cedef654fccc4a4d8",
"37b51d194a7513e45b56f6524f2d51f2",
@@ -369,13 +369,13 @@ def test_run_overwrite_preserves_meta_and_comment(tmp_dir, dvc, run_copy):
),
),
(
pytest.lazy_fixture("s3"),
"s3",
"etag",
"acbd18db4cc2f85cedef654fccc4a4d8",
"37b51d194a7513e45b56f6524f2d51f2",
),
(
pytest.lazy_fixture("hdfs"),
"hdfs",
"checksum",
"0000020000000000000000003dba826b9be9c6a8e2f8310a770555c4",
"00000200000000000000000075433c81259d3c38e364b348af52e84d",
+14 -20
View File
@@ -159,15 +159,13 @@ def test_update_before_and_after_dvc_init(tmp_dir, dvc, git_dir):
@pytest.mark.parametrize(
"workspace",
[
pytest.lazy_fixture("local_cloud"),
pytest.lazy_fixture("s3"),
"local",
"s3",
pytest.param("gs", marks=pytest.mark.needs_internet),
"hdfs",
"webhdfs",
pytest.param(
pytest.lazy_fixture("gs"), marks=pytest.mark.needs_internet
),
pytest.lazy_fixture("hdfs"),
pytest.lazy_fixture("webhdfs"),
pytest.param(
pytest.lazy_fixture("ssh"),
"ssh",
marks=pytest.mark.skipif(
os.name == "nt", reason="disabled on windows"
),
@@ -326,12 +324,10 @@ def test_update_import_to_remote(tmp_dir, dvc, erepo_dir, local_remote):
@pytest.mark.parametrize(
"workspace",
[
pytest.lazy_fixture("local_cloud"),
pytest.lazy_fixture("s3"),
pytest.param(
pytest.lazy_fixture("gs"), marks=pytest.mark.needs_internet
),
pytest.lazy_fixture("hdfs"),
"local",
"s3",
pytest.param("gs", marks=pytest.mark.needs_internet),
"hdfs",
],
indirect=True,
)
@@ -349,11 +345,9 @@ def test_update_import_url_to_remote(tmp_dir, dvc, workspace, local_remote):
@pytest.mark.parametrize(
"workspace",
[
pytest.lazy_fixture("s3"),
pytest.param(
pytest.lazy_fixture("gs"), marks=pytest.mark.needs_internet
),
pytest.lazy_fixture("hdfs"),
"s3",
pytest.param("gs", marks=pytest.mark.needs_internet),
"hdfs",
],
indirect=True,
)
@@ -378,7 +372,7 @@ def test_update_import_url_to_remote_directory(
)
download_file_mock = mocker.spy(
type(dvc.cloud.get_remote_odb("cache").fs), "download_file"
type(dvc.cloud.get_remote_odb("workspace-cache").fs), "download_file"
)
stage = dvc.update(stage.path, to_remote=True)