mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
* remote: move upload()/download() into tree * remote: move path_info/path_cls into tree * remote.azure: finish moving methods into tree * remote.gs: finish moving methods into tree * remote.hdfs: finish moving methods to tree * remote.http: finish moving methods into tree * remote.oss: finish moving methods into tree * remote.s3: finish moving methods into tree * remote.ssh: finish moving methods into tree * remote.gdrive: finish moving methods into tree * tests: update remote unit tests * tests: update func tests * remote: use walk_files() for all remotes * list_cache_paths() now uses tree.walk_files() for all remotes except local/ssh * fix DS warnings * bugfixes
55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
import mock
|
|
import pytest
|
|
import requests
|
|
|
|
from dvc.remote.gs import GSRemote, dynamic_chunk_size
|
|
|
|
BUCKET = "bucket"
|
|
PREFIX = "prefix"
|
|
URL = f"gs://{BUCKET}/{PREFIX}"
|
|
CREDENTIALPATH = "/path/to/gcp_credentials.json"
|
|
PROJECT = "PROJECT"
|
|
CONFIG = {
|
|
"projectname": PROJECT,
|
|
"url": URL,
|
|
"credentialpath": CREDENTIALPATH,
|
|
}
|
|
|
|
|
|
def test_init(dvc):
|
|
remote = GSRemote(dvc, CONFIG)
|
|
assert remote.tree.path_info == URL
|
|
assert remote.tree.projectname == PROJECT
|
|
assert remote.tree.credentialpath == CREDENTIALPATH
|
|
|
|
|
|
@mock.patch("google.cloud.storage.Client.from_service_account_json")
|
|
def test_gs(mock_client, dvc):
|
|
remote = GSRemote(dvc, CONFIG)
|
|
assert remote.tree.credentialpath
|
|
remote.tree.gs()
|
|
mock_client.assert_called_once_with(CREDENTIALPATH)
|
|
|
|
|
|
@mock.patch("google.cloud.storage.Client")
|
|
def test_gs_no_credspath(mock_client, dvc):
|
|
config = CONFIG.copy()
|
|
del config["credentialpath"]
|
|
remote = GSRemote(dvc, config)
|
|
remote.tree.gs()
|
|
mock_client.assert_called_with(PROJECT)
|
|
|
|
|
|
def test_dynamic_chunk_size():
|
|
chunk_sizes = []
|
|
|
|
@dynamic_chunk_size
|
|
def upload(chunk_size=None):
|
|
chunk_sizes.append(chunk_size)
|
|
raise requests.exceptions.ConnectionError()
|
|
|
|
with pytest.raises(requests.exceptions.ConnectionError):
|
|
upload()
|
|
|
|
assert chunk_sizes == [10485760, 5242880, 2621440, 1310720, 524288, 262144]
|