data cloud: refactor verify checksums test

This commit is contained in:
Paweł Redzyński
2020-01-22 10:54:07 +01:00
parent e36cc8c9d2
commit 482dfaf998
3 changed files with 37 additions and 34 deletions
+1 -2
View File
@@ -89,8 +89,7 @@ class DataCloud(object):
if self.repo.cache.local.exists(cache_file):
# We can safely save here, as existing corrupted files will be
# removed upon status, while files corrupted during download
# will not be copied from tmp_file (see download
# implementation in `remote/base`)
# will not be moved from tmp_file (see `RemoteBASE.download()`)
self.repo.state.save(cache_file, checksum)
def status(self, cache, jobs=None, remote=None, show_checksums=False):
+36 -1
View File
@@ -9,10 +9,11 @@ import pytest
from mock import patch
from dvc.cache import NamedCache
from dvc.compat import fspath
from dvc.config import Config
from dvc.data_cloud import DataCloud
from dvc.main import main
from dvc.remote import RemoteAZURE
from dvc.remote import RemoteAZURE, RemoteConfig
from dvc.remote import RemoteGDrive
from dvc.remote import RemoteGS
from dvc.remote import RemoteHDFS
@@ -653,3 +654,37 @@ class TestShouldWarnOnNoChecksumInLocalAndRemoteCache(TestDvc):
assert self.message_header in self._caplog.text
assert self.message_foo_part in self._caplog.text
assert self.message_bar_part in self._caplog.text
def test_verify_checksums(tmp_dir, scm, dvc, mocker, tmp_path_factory):
tmp_dir.dvc_gen({"file": "file1 content"}, commit="add file")
tmp_dir.dvc_gen({"dir": {"subfile": "file2 content"}}, commit="add dir")
RemoteConfig(dvc.config).add(
"local_remote",
fspath(tmp_path_factory.mktemp("local_remote")),
default=True,
)
dvc.push()
# remove artifacts and cache to trigger fetching
os.remove("file")
shutil.rmtree("dir")
shutil.rmtree(dvc.cache.local.cache_dir)
checksum_spy = mocker.spy(dvc.cache.local, "get_file_checksum")
dvc.pull()
assert checksum_spy.call_count == 0
# Removing cache will invalidate existing state entries
shutil.rmtree(dvc.cache.local.cache_dir)
dvc.config.set(
Config.SECTION_REMOTE_FMT.format("local_remote"),
Config.SECTION_REMOTE_VERIFY,
"True",
)
dvc.pull()
assert checksum_spy.call_count == 3
-31
View File
@@ -13,7 +13,6 @@ from dvc.path_info import PathInfo
from dvc.remote import RemoteLOCAL, RemoteConfig
from dvc.remote.base import RemoteBASE
from dvc.compat import fspath
from dvc.scm import Git
from tests.basic_env import TestDvc
from tests.remotes import Local
@@ -258,33 +257,3 @@ def test_modify_missing_remote(dvc):
with pytest.raises(ConfigError, match=r"unable to find remote section"):
remote_config.modify("myremote", "gdrive_client_id", "xxx")
def test_verify_checksums(tmp_dir, erepo_dir, mocker):
with erepo_dir.chdir():
erepo_dir.dvc_gen({"file": "file1 content"}, commit="add file")
erepo_dir.dvc_gen(
{"dir": {"subfile": "file2 content"}}, commit="add " "dir"
)
Git.clone(fspath(erepo_dir), fspath(tmp_dir))
from dvc.repo import Repo
dvc = Repo(fspath(tmp_dir))
file_md5_spy = mocker.spy(dvc.cache.local, "get_file_checksum")
dvc.pull()
assert file_md5_spy.call_count == 0
# Removing cache will invalidate existing state entries
shutil.rmtree(dvc.cache.local.cache_dir)
dvc.config.set(
Config.SECTION_REMOTE_FMT.format("upstream"),
Config.SECTION_REMOTE_VERIFY,
"True",
)
dvc.pull()
assert file_md5_spy.call_count == 3