Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clarify error message and docstrings in Blob class method #1196

Merged
merged 3 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions google/cloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down