Skip to content

Commit

Permalink
address @efiop's suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry committed Dec 1, 2019
1 parent f4f836e commit 22c0a64
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 46 deletions.
2 changes: 1 addition & 1 deletion dvc/remote/gs.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def exists(self, path_info):
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)
Expand Down
6 changes: 5 additions & 1 deletion tests/func/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
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
Expand Down
51 changes: 9 additions & 42 deletions tests/remotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,27 +242,16 @@ def remote(cls):
yield remote

@classmethod
@contextmanager
def put_objects(cls, remote, objects):
s3 = cls.get_client(remote)
s3.create_bucket(Bucket="dvc-test")
s3 = remote.s3
bucket = remote.path_info.bucket
s3.create_bucket(Bucket=bucket)
for key, body in objects.items():
cls.put_object(remote, key, body)
s3.put_object(
Bucket=bucket, Key=(remote.path_info / key).path, Body=body
)
yield

@staticmethod
def get_client(remote):
return remote.s3

@classmethod
def put_object(cls, remote, key, body):
s3 = cls.get_client(remote)
bucket = remote.path_info.bucket

s3.put_object(
Bucket=bucket, Key=remote.path_info.path + "/" + key, Body=body
)


class GCP:
should_test = staticmethod(_should_test_gcp)
Expand All @@ -275,30 +264,12 @@ def remote(cls):
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:
Expand All @@ -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
4 changes: 2 additions & 2 deletions tests/unit/remote/test_remote_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 22c0a64

Please sign in to comment.