mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-07 15:28:28 +01:00
Fixes #1654 Fixes #1655 Signed-off-by: Ruslan Kuprieiev <[email protected]>
69 lines
2.2 KiB
Python
69 lines
2.2 KiB
Python
import mock
|
|
from unittest import TestCase
|
|
|
|
from dvc.remote.base import RemoteBase, RemoteCmdError, RemoteMissingDepsError
|
|
|
|
|
|
class TestRemoteBase(object):
|
|
REMOTE_CLS = RemoteBase
|
|
|
|
|
|
class TestMissingDeps(TestCase, TestRemoteBase):
|
|
def test(self):
|
|
REQUIRES = {"foo": None, "bar": None, "mock": mock}
|
|
with mock.patch.object(self.REMOTE_CLS, "REQUIRES", REQUIRES):
|
|
with self.assertRaises(RemoteMissingDepsError):
|
|
self.REMOTE_CLS(None, {})
|
|
|
|
|
|
class TestCmdError(TestCase, TestRemoteBase):
|
|
def test(self):
|
|
repo = None
|
|
config = {}
|
|
|
|
cmd = "sed 'hello'"
|
|
ret = "1"
|
|
err = "sed: expression #1, char 2: extra characters after command"
|
|
|
|
with mock.patch.object(
|
|
self.REMOTE_CLS,
|
|
"remove",
|
|
side_effect=RemoteCmdError("base", cmd, ret, err),
|
|
):
|
|
with self.assertRaises(RemoteCmdError):
|
|
self.REMOTE_CLS(repo, config).remove("file")
|
|
|
|
|
|
class TestCacheExists(TestCase):
|
|
def test(self):
|
|
config = {
|
|
"url": "base://example/prefix",
|
|
"connection_string": "1234567",
|
|
}
|
|
remote = RemoteBase(None, config)
|
|
|
|
remote.PARAM_CHECKSUM = "checksum"
|
|
remote.path_info = {}
|
|
remote.url = ""
|
|
remote.prefix = ""
|
|
path_info = {"scheme": None, "path": "example"}
|
|
checksum_info = {remote.PARAM_CHECKSUM: "1234567890"}
|
|
|
|
with mock.patch.object(remote, "_checkout") as mock_checkout:
|
|
with mock.patch.object(remote, "_save") as mock_save:
|
|
with mock.patch.object(
|
|
remote, "changed_cache", return_value=True
|
|
):
|
|
remote.save(path_info, checksum_info)
|
|
mock_save.assert_called_once()
|
|
mock_checkout.assert_not_called()
|
|
|
|
with mock.patch.object(remote, "_checkout") as mock_checkout:
|
|
with mock.patch.object(remote, "_save") as mock_save:
|
|
with mock.patch.object(
|
|
remote, "changed_cache", return_value=False
|
|
):
|
|
remote.save(path_info, checksum_info)
|
|
mock_save.assert_not_called()
|
|
mock_checkout.assert_called_once()
|