Files
dvc/tests/unit/remote/test_gs.py
T
Peter Rowlands (변기호) a0c229cf9b remote: continue remote/cache/tree refactoring (#4041)
* remote: move constants into trees

* remote: replace Remote() Cache() helper functions

* output: update for remote changes

* cache/data_cloud: update for remote changes

* dependency: update for remote changes

* stage: update for remote changes

* remote: move remaining non-index methods into tree

* tests: update remote unit tests

* remote: LocalCache needs to lock remote index, not cache index

* fix bugs from moved PARAM_CHECKSUM/PARAM_RELPATH

* tests: repo tree open needs state context

* remote: make Remote.gc a class method

* operates on obj.tree, so that GC can be done with both remote and
  cache instances

* bug fixes

* tests: update test_data_cloud

* bug fixes

* tests: update func tests
2020-06-15 16:22:55 +03:00

55 lines
1.3 KiB
Python

import mock
import pytest
import requests
from dvc.remote.gs import GSRemoteTree, 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):
tree = GSRemoteTree(dvc, CONFIG)
assert tree.path_info == URL
assert tree.projectname == PROJECT
assert tree.credentialpath == CREDENTIALPATH
@mock.patch("google.cloud.storage.Client.from_service_account_json")
def test_gs(mock_client, dvc):
tree = GSRemoteTree(dvc, CONFIG)
assert tree.credentialpath
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"]
tree = GSRemoteTree(dvc, config)
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]