| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7c8412a commit c6461a4
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,7 @@ | |||
| 15 | 15 | import logging | |
| 16 | 16 | from typing import IO, Any, Dict, List | |
| 17 | 17 | ||
| 18 | - from google_crc32c import Checksum | ||
| 18 | + import google_crc32c | ||
| 19 | 19 | ||
| 20 | 20 | from google.cloud import _storage_v2 as storage_v2 | |
| 21 | 21 | from google.cloud.storage.asyncio.retry._helpers import ( | |
@@ -127,7 +127,7 @@ def update_state_from_response( | |||
| 127 | 127 | ||
| 128 | 128 | if checksummed_data.HasField("crc32c"): | |
| 129 | 129 | server_checksum = checksummed_data.crc32c | |
| 130 | - client_checksum = int.from_bytes(Checksum(data).digest(), "big") | ||
| 130 | + client_checksum = google_crc32c.value(data) | ||
| 131 | 131 | if server_checksum != client_checksum: | |
| 132 | 132 | raise DataCorruption( | |
| 133 | 133 | response, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -324,10 +324,10 @@ def test_init_raises_if_crc32c_c_extension_is_missing(self, mock_google_crc32c): | |||
| 324 | 324 | ) | |
| 325 | 325 | ||
| 326 | 326 | @pytest.mark.asyncio | |
| 327 | - @mock.patch("google.cloud.storage.asyncio.retry.reads_resumption_strategy.Checksum") | ||
| 328 | - async def test_download_ranges_raises_on_checksum_mismatch( | ||
| 329 | - self, mock_checksum_class | ||
| 330 | - ): | ||
| 327 | + @mock.patch( | ||
| 328 | + "google.cloud.storage.asyncio.retry.reads_resumption_strategy.google_crc32c.value" | ||
| 329 | + ) | ||
| 330 | + async def test_download_ranges_raises_on_checksum_mismatch(self, mock_crc32c_value): | ||
| 331 | 331 | from google.cloud.storage.asyncio._stream_multiplexer import _StreamMultiplexer | |
| 332 | 332 | from google.cloud.storage.asyncio.async_multi_range_downloader import ( | |
| 333 | 333 | AsyncMultiRangeDownloader, | |
@@ -340,8 +340,7 @@ async def test_download_ranges_raises_on_checksum_mismatch( | |||
| 340 | 340 | ||
| 341 | 341 | test_data = b"some-data" | |
| 342 | 342 | server_checksum = 12345 | |
| 343 | - mock_checksum_instance = mock_checksum_class.return_value | ||
| 344 | - mock_checksum_instance.digest.return_value = (54321).to_bytes(4, "big") | ||
| 343 | + mock_crc32c_value.return_value = 54321 | ||
| 345 | 344 | ||
| 346 | 345 | mock_response = _storage_v2.BidiReadObjectResponse( | |
| 347 | 346 | object_data_ranges=[ | |
@@ -372,7 +371,7 @@ async def test_download_ranges_raises_on_checksum_mismatch( | |||
| 372 | 371 | await mrd.download_ranges([(0, len(test_data), BytesIO())]) | |
| 373 | 372 | ||
| 374 | 373 | assert "Checksum mismatch" in str(exc_info.value) | |
| 375 | - mock_checksum_class.assert_called_once_with(test_data) | ||
| 374 | + mock_crc32c_value.assert_called_once_with(test_data) | ||
| 376 | 375 | ||
| 377 | 376 | @mock.patch( | |
| 378 | 377 | "google.cloud.storage.asyncio.async_multi_range_downloader.AsyncMultiRangeDownloader.open", | |
@@ -575,18 +574,11 @@ async def staged_recv(): | |||
| 575 | 574 | # Act | |
| 576 | 575 | buffer = BytesIO() | |
| 577 | 576 | ||
| 578 | - # Patch Checksum where it is likely used (reads_resumption_strategy or similar), | ||
| 579 | - # but actually if we use google_crc32c directly, we should patch that or provide valid CRC. | ||
| 580 | - # Since we can't reliably predict where Checksum is imported/used without more digging, | ||
| 581 | - # let's provide a valid CRC for b"data". | ||
| 582 | - # Checksum(b"data").digest() -> needs to match crc32c=123. | ||
| 583 | - # But we can't force b"data" to have crc=123. | ||
| 584 | - # So we MUST patch Checksum. | ||
| 585 | - # It is used in google.cloud.storage.asyncio.retry.reads_resumption_strategy | ||
| 577 | + # Patch google_crc32c.value where it is used in reads_resumption_strategy | ||
| 586 | 578 | with mock.patch( | |
| 587 | - "google.cloud.storage.asyncio.retry.reads_resumption_strategy.Checksum" | ||
| 588 | - ) as mock_chk: | ||
| 589 | - mock_chk.return_value.digest.return_value = (123).to_bytes(4, "big") | ||
| 579 | + "google.cloud.storage.asyncio.retry.reads_resumption_strategy.google_crc32c.value" | ||
| 580 | + ) as mock_crc_value: | ||
| 581 | + mock_crc_value.return_value = 123 | ||
| 590 | 582 | await mock_mrd.download_ranges([(0, 4, buffer)]) | |
| 591 | 583 | ||
| 592 | 584 | # Assert | |
| Back | FazBrowse Home | New Git URL |
0 commit comments