diff --git a/dvc/remote/gs.py b/dvc/remote/gs.py index 190c52176..b71dab3d4 100644 --- a/dvc/remote/gs.py +++ b/dvc/remote/gs.py @@ -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) diff --git a/tests/func/test_api.py b/tests/func/test_api.py index de029960b..b0e0085e3 100644 --- a/tests/func/test_api.py +++ b/tests/func/test_api.py @@ -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 diff --git a/tests/remotes.py b/tests/remotes.py index b9f170d32..4c0d77660 100644 --- a/tests/remotes.py +++ b/tests/remotes.py @@ -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 diff --git a/tests/unit/remote/test_remote_dir.py b/tests/unit/remote/test_remote_dir.py index e0e48d1f7..bc58c5e71 100644 --- a/tests/unit/remote/test_remote_dir.py +++ b/tests/unit/remote/test_remote_dir.py @@ -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)