Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit a804173

Browse files
authored
Merge branch 'main' into renovate/all
2 parents 5b3822a + dc05b4b commit a804173

File tree

5 files changed

+54
-3
lines changed

5 files changed

+54
-3
lines changed

.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ omit =
2222
google/cloud/__init__.py
2323

2424
[report]
25-
fail_under = 99
25+
fail_under = 98
2626
show_missing = True
2727
exclude_lines =
2828
# Re-enable the standard pragma

.github/workflows/unittest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ jobs:
5858
run: |
5959
find .coverage-results -type f -name '*.zip' -exec unzip {} \;
6060
coverage combine .coverage-results/**/.coverage*
61-
coverage report --show-missing --fail-under=99
61+
coverage report --show-missing --fail-under=98

google/cloud/documentai_toolbox/utilities/gcs_utilities.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ def get_blob(
142142
if not re.match(constants.FILE_CHECK_REGEX, gcs_uri):
143143
raise ValueError("gcs_uri must link to a single file.")
144144

145+
# google-cloud-storage >= 3.0.0
146+
if hasattr(storage.Blob, "from_uri"):
147+
return storage.Blob.from_uri(gcs_uri, _get_storage_client(module=module))
148+
145149
return storage.Blob.from_string(gcs_uri, _get_storage_client(module=module))
146150

147151

owlbot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
unit_test_python_versions=["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"],
3131
system_test_python_versions=["3.9", "3.14"],
3232
default_python_version="3.13",
33-
cov_level=99,
33+
cov_level=98,
3434
intersphinx_dependencies={
3535
"pandas": "https://pandas.pydata.org/pandas-docs/stable/"
3636
},

tests/unit/test_gcs_utilities.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,3 +579,50 @@ def test_get_blobs_with_no_input():
579579
match="You must provide either `gcs_uri` or both `gcs_bucket_name` and `gcs_prefix`.",
580580
):
581581
gcs_utilities.get_blobs()
582+
583+
584+
@mock.patch("google.cloud.documentai_toolbox.utilities.gcs_utilities.storage")
585+
def test_get_blobs_with_gcs_uri(mock_storage):
586+
client = mock_storage.Client.return_value
587+
gcs_uri = "gs://test-bucket/test-directory/1/"
588+
589+
gcs_utilities.get_blobs(gcs_uri=gcs_uri)
590+
591+
mock_storage.Client.assert_called_once()
592+
client.list_blobs.assert_called_once_with("test-bucket", prefix="test-directory/1/")
593+
594+
595+
def test_get_blobs_with_file_type_error():
596+
with pytest.raises(ValueError, match="gcs_prefix cannot contain file types"):
597+
gcs_utilities.get_blobs(gcs_bucket_name="test-bucket", gcs_prefix="test.json")
598+
599+
600+
def test_get_blob_invalid_uri():
601+
with pytest.raises(ValueError, match="gcs_uri must link to a single file."):
602+
gcs_utilities.get_blob("gs://test-bucket/prefix/")
603+
604+
605+
@mock.patch("google.cloud.documentai_toolbox.utilities.gcs_utilities.storage")
606+
def test_get_blob_from_uri(mock_storage):
607+
gcs_uri = "gs://test-bucket/test.json"
608+
609+
# Mock storage.Blob.from_uri to exist
610+
mock_storage.Blob.from_uri.return_value = mock.Mock(spec=storage.blob.Blob)
611+
612+
gcs_utilities.get_blob(gcs_uri=gcs_uri)
613+
614+
mock_storage.Blob.from_uri.assert_called_once()
615+
616+
617+
@mock.patch("google.cloud.documentai_toolbox.utilities.gcs_utilities.storage")
618+
def test_get_blob_from_string(mock_storage):
619+
gcs_uri = "gs://test-bucket/test.json"
620+
621+
# Mock storage.Blob to NOT have from_uri
622+
del mock_storage.Blob.from_uri
623+
624+
mock_storage.Blob.from_string.return_value = mock.Mock(spec=storage.blob.Blob)
625+
626+
gcs_utilities.get_blob(gcs_uri=gcs_uri)
627+
628+
mock_storage.Blob.from_string.assert_called_once()

0 commit comments

Comments
 (0)