address @efiop's suggestions

This commit is contained in:
Saugat Pachhai
2019-12-01 16:08:53 +05:45
parent f4f836e17c
commit 22c0a644e5
4 changed files with 18 additions and 47 deletions
+1 -1
View File
@@ -176,7 +176,7 @@ class RemoteGS(RemoteBASE):
eg: if `data/file.txt` exists, check for `data` should return True
"""
return True if self.isfile(path_info) else self.isdir(path_info / "")
return self.isfile(path_info) or self.isdir(path_info / "")
def _upload(self, from_file, to_info, name=None, no_progress_bar=True):
bucket = self.gs.bucket(to_info.bucket)
+5 -1
View File
@@ -8,7 +8,11 @@ from dvc.exceptions import FileMissingError
from dvc.main import main
from dvc.path_info import URLInfo
from dvc.remote.config import RemoteConfig
from tests.remotes import remote_params, all_remote_params
from tests.remotes import Azure, GCP, HDFS, Local, OSS, S3, SSH
remote_params = [S3, GCP, Azure, OSS, SSH, HDFS]
all_remote_params = [Local] + remote_params
@pytest.fixture
+10 -43
View File
@@ -242,26 +242,15 @@ class S3Mocked:
yield remote
@classmethod
@contextmanager
def put_objects(cls, remote, objects):
s3 = cls.get_client(remote)
s3.create_bucket(Bucket="dvc-test")
for key, body in objects.items():
cls.put_object(remote, key, body)
yield
@staticmethod
def get_client(remote):
return remote.s3
@classmethod
def put_object(cls, remote, key, body):
s3 = cls.get_client(remote)
s3 = remote.s3
bucket = remote.path_info.bucket
s3.put_object(
Bucket=bucket, Key=remote.path_info.path + "/" + key, Body=body
)
s3.create_bucket(Bucket=bucket)
for key, body in objects.items():
s3.put_object(
Bucket=bucket, Key=(remote.path_info / key).path, Body=body
)
yield
class GCP:
@@ -275,30 +264,12 @@ class GCP:
yield remote
@classmethod
@contextmanager
def put_objects(cls, remote, objects):
client = remote.gs
bucket = client.get_bucket(remote.path_info.bucket)
for key, body in objects.items():
cls.put_object(remote, key, body)
bucket.blob((remote.path_info / key).path).upload_from_string(body)
yield
cls.remove(remote, objects.keys())
@classmethod
def put_object(cls, remote, key, body):
client = cls.get_client(remote)
bucket = remote.path_info.bucket
bucket = client.get_bucket(bucket)
blob = bucket.blob(remote.path_info.path + "/" + key)
blob.upload_from_string(body)
@staticmethod
def get_client(remote):
return remote.gs
@staticmethod
def remove(remote, files):
for fname in files:
remote.remove(remote.path_info / fname)
class Azure:
@@ -319,7 +290,3 @@ class SSH:
class HDFS:
should_test = staticmethod(_should_test_hdfs)
get_url = staticmethod(get_hdfs_url)
remote_params = [S3, GCP, Azure, OSS, SSH, HDFS]
all_remote_params = [Local] + remote_params
+2 -2
View File
@@ -26,8 +26,8 @@ def remote(request):
if not request.param.should_test():
raise pytest.skip()
with request.param.remote() as remote:
with request.param.put_objects(remote, FILE_WITH_CONTENTS):
yield remote
request.param.put_objects(remote, FILE_WITH_CONTENTS)
yield remote
@pytest.mark.parametrize("remote", remotes, indirect=True)