From 11369b8a20b72aa91f5128fd7ca96f2c2bbac9df Mon Sep 17 00:00:00 2001 From: Cathy Ouyang Date: Tue, 5 Dec 2023 11:47:14 -0800 Subject: [PATCH 1/2] fix: clarify error message and docstrings --- google/cloud/storage/blob.py | 5 +++-- tests/unit/test_blob.py | 2 +- tests/unit/test_client.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/google/cloud/storage/blob.py b/google/cloud/storage/blob.py index 33998f81a..6a84c1e92 100644 --- a/google/cloud/storage/blob.py +++ b/google/cloud/storage/blob.py @@ -393,7 +393,8 @@ def from_string(cls, uri, client=None): blob = Blob.from_string("gs://bucket/object", client=client) :type uri: str - :param uri: The blob uri pass to get blob object. + :param uri: The blob uri following a gs://bucket/object pattern. + Both a bucket and object name is required to construct a blob object. :type client: :class:`~google.cloud.storage.client.Client` :param client: @@ -407,7 +408,7 @@ def from_string(cls, uri, client=None): match = _GS_URL_REGEX_PATTERN.match(uri) if not match: - raise ValueError("URI scheme must be gs") + raise ValueError("URI pattern must be gs://bucket/object") bucket = Bucket(client, name=match.group("bucket_name")) return cls(match.group("object_name"), bucket) diff --git a/tests/unit/test_blob.py b/tests/unit/test_blob.py index dcaf3e028..2fde2fa8a 100644 --- a/tests/unit/test_blob.py +++ b/tests/unit/test_blob.py @@ -5840,7 +5840,7 @@ def test_from_string_w_invalid_uri(self): client = self._make_client() - with pytest.raises(ValueError, match="URI scheme must be gs"): + with pytest.raises(ValueError): Blob.from_string("http://bucket_name/b", client) def test_from_string_w_domain_name_bucket(self): diff --git a/tests/unit/test_client.py b/tests/unit/test_client.py index 4629ecf28..0df5542a9 100644 --- a/tests/unit/test_client.py +++ b/tests/unit/test_client.py @@ -1747,7 +1747,7 @@ def test_download_blob_to_file_with_invalid_uri(self): client = self._make_one(project=project, credentials=credentials) file_obj = io.BytesIO() - with pytest.raises(ValueError, match="URI scheme must be gs"): + with pytest.raises(ValueError): client.download_blob_to_file("http://bucket_name/path/to/object", file_obj) def test_download_blob_to_file_w_no_retry(self): From 08ba6e816b53c8168095e9637459f053fb79e7e9 Mon Sep 17 00:00:00 2001 From: Cathy Ouyang Date: Tue, 5 Dec 2023 12:02:37 -0800 Subject: [PATCH 2/2] run docs --- google/cloud/storage/blob.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/cloud/storage/blob.py b/google/cloud/storage/blob.py index 6a84c1e92..6416ce717 100644 --- a/google/cloud/storage/blob.py +++ b/google/cloud/storage/blob.py @@ -394,7 +394,7 @@ def from_string(cls, uri, client=None): :type uri: str :param uri: The blob uri following a gs://bucket/object pattern. - Both a bucket and object name is required to construct a blob object. + Both a bucket and object name is required to construct a blob object. :type client: :class:`~google.cloud.storage.client.Client` :param client: