# Path: google/resumable_media/common.py
# _SLEEP_RETRY_ERROR_MSG = (
#     "At most one of `max_cumulative_retry` and `max_retries` " "can be specified."
# )
# UPLOAD_CHUNK_SIZE = 262144  # 256 * 1024
# PERMANENT_REDIRECT = http.client.PERMANENT_REDIRECT  # type: ignore
# TOO_MANY_REQUESTS = http.client.TOO_MANY_REQUESTS
# MAX_SLEEP = 64.0
# MAX_CUMULATIVE_RETRY = 600.0
# RETRYABLE = (
#     http.client.TOO_MANY_REQUESTS,  # 429
#     http.client.REQUEST_TIMEOUT,  # 408
#     http.client.INTERNAL_SERVER_ERROR,  # 500
#     http.client.BAD_GATEWAY,  # 502
#     http.client.SERVICE_UNAVAILABLE,  # 503
#     http.client.GATEWAY_TIMEOUT,  # 504
# )
# class InvalidResponse(Exception):
# class DataCorruption(Exception):
# class RetryStrategy(object):
#     def __init__(self, response, *args):
#     def __init__(self, response, *args):
#     def __init__(
#         self,
#         max_sleep=MAX_SLEEP,
#         max_cumulative_retry=None,
#         max_retries=None,
#         initial_delay=1.0,
#         multiplier=2.0,
#     ):
#     def retry_allowed(self, total_sleep, num_retries):
# 
# Path: tests/unit/test__download.py
# EXAMPLE_URL = (
#     "https://www.googleapis.com/download/storage/v1/b/{BUCKET}/o/{OBJECT}?alt=media"
# )
# class TestDownloadBase(object):
# class TestDownload(object):
# class TestChunkedDownload(object):
# class Test__add_bytes_range(object):
# class Test_get_range_info(object):
# class Test__check_for_zero_content_range(object):
#     def test_constructor_defaults(self):
#     def test_constructor_explicit(self):
#     def test_finished_property(self):
#     def test__get_status_code(self):
#     def test__get_headers(self):
#     def test__get_body(self):
#     def test__prepare_request_already_finished(self):
#     def test__prepare_request(self):
#     def test__prepare_request_with_headers(self):
#     def test__process_response(self):
#     def test__process_response_bad_status(self):
#     def test_consume(self):
#     def test_constructor_defaults(self):
#     def test_constructor_bad_start(self):
#     def test_bytes_downloaded_property(self):
#     def test_total_bytes_property(self):
#     def test__get_byte_range(self):
#     def test__get_byte_range_with_end(self):
#     def test__get_byte_range_with_total_bytes(self):
#     def _response_content_range(start_byte, end_byte, total_bytes):
#     def _response_headers(self, start_byte, end_byte, total_bytes):
#     def _mock_response(
#         self, start_byte, end_byte, total_bytes, content=None, status_code=None
#     ):
#     def test__prepare_request_already_finished(self):
#     def test__prepare_request_invalid(self):
#     def test__prepare_request(self):
#     def test__prepare_request_with_headers(self):
#     def test__make_invalid(self):
#     def test__process_response(self):
#     def test__process_response_transfer_encoding(self):
#     def test__process_response_bad_status(self):
#     def test__process_response_missing_content_length(self):
#     def test__process_response_bad_content_range(self):
#     def test__process_response_body_wrong_length(self):
#     def test__process_response_when_finished(self):
#     def test__process_response_when_reaching_end(self):
#     def test__process_response_when_content_range_is_zero(self):
#     def test_consume_next_chunk(self):
#     def test_do_nothing(self):
#     def test_both_vals(self):
#     def test_end_only(self):
#     def test_start_only(self):
#     def test_start_as_offset(self):
#     def _make_response(content_range):
#     def _success_helper(self, **kwargs):
#     def test_success(self):
#     def test_success_with_callback(self):
#     def _failure_helper(self, **kwargs):
#     def test_failure(self):
#     def test_failure_with_callback(self):
#     def _missing_header_helper(self, **kwargs):
#     def test_missing_header(self):
#     def test_missing_header_with_callback(self):
#     def _make_response(content_range, status_code):
#     def test_status_code_416_and_test_content_range_zero_both(self):
#     def test_status_code_416_only(self):
#     def test_content_range_zero_only(self):
# def _get_status_code(response):
# def _get_headers(response):
# def _get_body(response):
# def _fix_up_virtual(download):
# def _check_retry_strategy(download):


import http.client
import io
import google.auth.transport._aiohttp_requests as aiohttp_requests  # type: ignore
import mock
import pytest  # type: ignore
from google._async_resumable_media import _download
from google.resumable_media import common
from tests.unit import test__download as sync_test
        assert len(error.args) == 3
        assert error.args[1] == headers["content-range"]
        # Check internal state after.
        assert not download.finished
        assert download.bytes_downloaded == 0
        assert download.total_bytes is None
        assert download.invalid

    @pytest.mark.asyncio
    async def test__process_response_body_wrong_length(self):
        chunk_size = 10
        stream = mock.Mock(spec=["write"])
        download = _download.ChunkedDownload(EXAMPLE_URL, chunk_size, stream)
        _fix_up_virtual(download)

        total_bytes = 100

        # Check internal state before.
        assert not download.finished
        assert download.bytes_downloaded == 0
        assert download.total_bytes is None
        # Actually call the method to update.
        data = b"not 10"
        response = self._mock_response(
            0,
            chunk_size - 1,
            total_bytes,
            content=data,
            status_code=int(http.client.PARTIAL_CONTENT),
        )

# Path: google/resumable_media/common.py
# _SLEEP_RETRY_ERROR_MSG = (
#     "At most one of `max_cumulative_retry` and `max_retries` " "can be specified."
# )
# UPLOAD_CHUNK_SIZE = 262144  # 256 * 1024
# PERMANENT_REDIRECT = http.client.PERMANENT_REDIRECT  # type: ignore
# TOO_MANY_REQUESTS = http.client.TOO_MANY_REQUESTS
# MAX_SLEEP = 64.0
# MAX_CUMULATIVE_RETRY = 600.0
# RETRYABLE = (
#     http.client.TOO_MANY_REQUESTS,  # 429
#     http.client.REQUEST_TIMEOUT,  # 408
#     http.client.INTERNAL_SERVER_ERROR,  # 500
#     http.client.BAD_GATEWAY,  # 502
#     http.client.SERVICE_UNAVAILABLE,  # 503
#     http.client.GATEWAY_TIMEOUT,  # 504
# )
# class InvalidResponse(Exception):
# class DataCorruption(Exception):
# class RetryStrategy(object):
#     def __init__(self, response, *args):
#     def __init__(self, response, *args):
#     def __init__(
#         self,
#         max_sleep=MAX_SLEEP,
#         max_cumulative_retry=None,
#         max_retries=None,
#         initial_delay=1.0,
#         multiplier=2.0,
#     ):
#     def retry_allowed(self, total_sleep, num_retries):
# 
# Path: tests/unit/test__download.py
# EXAMPLE_URL = (
#     "https://www.googleapis.com/download/storage/v1/b/{BUCKET}/o/{OBJECT}?alt=media"
# )
# class TestDownloadBase(object):
# class TestDownload(object):
# class TestChunkedDownload(object):
# class Test__add_bytes_range(object):
# class Test_get_range_info(object):
# class Test__check_for_zero_content_range(object):
#     def test_constructor_defaults(self):
#     def test_constructor_explicit(self):
#     def test_finished_property(self):
#     def test__get_status_code(self):
#     def test__get_headers(self):
#     def test__get_body(self):
#     def test__prepare_request_already_finished(self):
#     def test__prepare_request(self):
#     def test__prepare_request_with_headers(self):
#     def test__process_response(self):
#     def test__process_response_bad_status(self):
#     def test_consume(self):
#     def test_constructor_defaults(self):
#     def test_constructor_bad_start(self):
#     def test_bytes_downloaded_property(self):
#     def test_total_bytes_property(self):
#     def test__get_byte_range(self):
#     def test__get_byte_range_with_end(self):
#     def test__get_byte_range_with_total_bytes(self):
#     def _response_content_range(start_byte, end_byte, total_bytes):
#     def _response_headers(self, start_byte, end_byte, total_bytes):
#     def _mock_response(
#         self, start_byte, end_byte, total_bytes, content=None, status_code=None
#     ):
#     def test__prepare_request_already_finished(self):
#     def test__prepare_request_invalid(self):
#     def test__prepare_request(self):
#     def test__prepare_request_with_headers(self):
#     def test__make_invalid(self):
#     def test__process_response(self):
#     def test__process_response_transfer_encoding(self):
#     def test__process_response_bad_status(self):
#     def test__process_response_missing_content_length(self):
#     def test__process_response_bad_content_range(self):
#     def test__process_response_body_wrong_length(self):
#     def test__process_response_when_finished(self):
#     def test__process_response_when_reaching_end(self):
#     def test__process_response_when_content_range_is_zero(self):
#     def test_consume_next_chunk(self):
#     def test_do_nothing(self):
#     def test_both_vals(self):
#     def test_end_only(self):
#     def test_start_only(self):
#     def test_start_as_offset(self):
#     def _make_response(content_range):
#     def _success_helper(self, **kwargs):
#     def test_success(self):
#     def test_success_with_callback(self):
#     def _failure_helper(self, **kwargs):
#     def test_failure(self):
#     def test_failure_with_callback(self):
#     def _missing_header_helper(self, **kwargs):
#     def test_missing_header(self):
#     def test_missing_header_with_callback(self):
#     def _make_response(content_range, status_code):
#     def test_status_code_416_and_test_content_range_zero_both(self):
#     def test_status_code_416_only(self):
#     def test_content_range_zero_only(self):
# def _get_status_code(response):
# def _get_headers(response):
# def _get_body(response):
# def _fix_up_virtual(download):
# def _check_retry_strategy(download):


# Path: tests_async/unit/test__download.py
import http.client
import io
import google.auth.transport._aiohttp_requests as aiohttp_requests  # type: ignore
import mock
import pytest  # type: ignore
from google._async_resumable_media import _download
from google.resumable_media import common
from tests.unit import test__download as sync_test

        assert len(error.args) == 3
        assert error.args[1] == headers["content-range"]
        # Check internal state after.
        assert not download.finished
        assert download.bytes_downloaded == 0
        assert download.total_bytes is None
        assert download.invalid

    @pytest.mark.asyncio
    async def test__process_response_body_wrong_length(self):
        chunk_size = 10
        stream = mock.Mock(spec=["write"])
        download = _download.ChunkedDownload(EXAMPLE_URL, chunk_size, stream)
        _fix_up_virtual(download)

        total_bytes = 100

        # Check internal state before.
        assert not download.finished
        assert download.bytes_downloaded == 0
        assert download.total_bytes is None
        # Actually call the method to update.
        data = b"not 10"
        response = self._mock_response(
            0,
            chunk_size - 1,
            total_bytes,
            content=data,
            status_code=int(http.client.PARTIAL_CONTENT),
        )

        with pytest.raises(common.InvalidResponse) as exc_info: