Skip to content

Commit 1a855e0

Browse files
committed
Add unit test for init_aaow method in zb_hns_utils
1 parent cce7e99 commit 1a855e0

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

gcsfs/tests/test_zb_hns_utils.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
from gcsfs import zb_hns_utils
66

7+
mock_grpc_client = mock.Mock()
8+
bucket_name = "test-bucket"
9+
object_name = "test-object"
10+
generation = "12345"
11+
712

813
@pytest.mark.asyncio
914
async def test_download_range():
@@ -27,3 +32,29 @@ async def mock_download_ranges(ranges):
2732

2833
mock_mrd.download_ranges.assert_called_once_with([(offset, length, mock.ANY)])
2934
assert result == expected_data
35+
36+
37+
@pytest.mark.asyncio
38+
async def test_init_aaow():
39+
"""
40+
Tests that init_aaow calls the underlying AsyncAppendableObjectWriter.open
41+
method and returns its result.
42+
"""
43+
mock_writer_instance = mock.AsyncMock()
44+
with mock.patch(
45+
"gcsfs.zb_hns_utils.AsyncAppendableObjectWriter", # The class to patch
46+
new_callable=mock.Mock, # Use a regular Mock for the class
47+
return_value=mock_writer_instance,
48+
) as mock_writer_class:
49+
result = await zb_hns_utils.init_aaow(
50+
mock_grpc_client, bucket_name, object_name, generation
51+
)
52+
53+
mock_writer_class.assert_called_once_with(
54+
client=mock_grpc_client,
55+
bucket_name=bucket_name,
56+
object_name=object_name,
57+
generation=generation,
58+
)
59+
mock_writer_instance.open.assert_awaited_once()
60+
assert result is mock_writer_instance

0 commit comments

Comments
 (0)