From 92c20d3f7520c6b94308ebb156202fdfd1dcd482 Mon Sep 17 00:00:00 2001 From: cojenco Date: Thu, 7 Dec 2023 14:09:20 -0800 Subject: [PATCH] fix: clarify error message and docstrings in Blob class method (#1196) * fix: clarify error message and docstrings * run docs --- 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 74cdc76e1..47564b6da 100644 --- a/google/cloud/storage/blob.py +++ b/google/cloud/storage/blob.py @@ -394,7 +394,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: @@ -408,7 +409,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 5cd37cae3..563111ef0 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 592920d0e..9650de976 100644 --- a/tests/unit/test_client.py +++ b/tests/unit/test_client.py @@ -1750,7 +1750,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):