# Path: google/api_core/exceptions.py
# _HTTP_CODE_TO_EXCEPTION: Dict[int, Exception] = {}
# _GRPC_CODE_TO_EXCEPTION: Dict[int, Exception] = {}
# _INT_TO_GRPC_CODE = {}
# class GoogleAPIError(Exception):
# class DuplicateCredentialArgs(GoogleAPIError):
# class RetryError(GoogleAPIError):
# class _GoogleAPICallErrorMeta(type):
# class GoogleAPICallError(GoogleAPIError, metaclass=_GoogleAPICallErrorMeta):
# class Redirection(GoogleAPICallError):
# class MovedPermanently(Redirection):
# class NotModified(Redirection):
# class TemporaryRedirect(Redirection):
# class ResumeIncomplete(Redirection):
# class ClientError(GoogleAPICallError):
# class BadRequest(ClientError):
# class InvalidArgument(BadRequest):
# class FailedPrecondition(BadRequest):
# class OutOfRange(BadRequest):
# class Unauthorized(ClientError):
# class Unauthenticated(Unauthorized):
# class Forbidden(ClientError):
# class PermissionDenied(Forbidden):
# class NotFound(ClientError):
# class MethodNotAllowed(ClientError):
# class Conflict(ClientError):
# class AlreadyExists(Conflict):
# class Aborted(Conflict):
# class LengthRequired(ClientError):
# class PreconditionFailed(ClientError):
# class RequestRangeNotSatisfiable(ClientError):
# class TooManyRequests(ClientError):
# class ResourceExhausted(TooManyRequests):
# class Cancelled(ClientError):
# class ServerError(GoogleAPICallError):
# class InternalServerError(ServerError):
# class Unknown(ServerError):
# class DataLoss(ServerError):
# class MethodNotImplemented(ServerError):
# class BadGateway(ServerError):
# class ServiceUnavailable(ServerError):
# class GatewayTimeout(ServerError):
# class DeadlineExceeded(GatewayTimeout):
#     def __init__(self, message, cause):
#     def cause(self):
#     def __str__(self):
#     def __new__(mcs, name, bases, class_dict):
#     def __init__(self, message, errors=(), details=(), response=None, error_info=None):
#     def __str__(self):
#     def reason(self):
#     def domain(self):
#     def metadata(self):
#     def errors(self):
#     def details(self):
#     def response(self):
# def exception_class_for_http_status(status_code):
# def from_http_status(status_code, message, **kwargs):
# def from_http_response(response):
# def exception_class_for_grpc_status(status_code):
# def from_grpc_status(status_code, message, **kwargs):
# def _is_informative_grpc_error(rpc_exc):
# def _parse_grpc_error_details(rpc_exc):
# def from_grpc_error(rpc_exc):


import datetime
import itertools
import re
import mock
import pytest
import requests.exceptions
from google.api_core import exceptions
from google.api_core import retry
from google.auth import exceptions as auth_exceptions
    return_value=datetime.datetime.min,
    autospec=True,
)
def test_retry_target_non_retryable_error(utcnow, sleep):
    predicate = retry.if_exception_type(ValueError)
    exception = TypeError()
    target = mock.Mock(side_effect=exception)

    with pytest.raises(TypeError) as exc_info:
        retry.retry_target(target, predicate, range(10), None)

    assert exc_info.value == exception
    sleep.assert_not_called()


@mock.patch("time.sleep", autospec=True)
@mock.patch("google.api_core.datetime_helpers.utcnow", autospec=True)
def test_retry_target_deadline_exceeded(utcnow, sleep):
    predicate = retry.if_exception_type(ValueError)
    exception = ValueError("meep")
    target = mock.Mock(side_effect=exception)
    # Setup the timeline so that the first call takes 5 seconds but the second
    # call takes 6, which puts the retry over the deadline.
    utcnow.side_effect = [
        # The first call to utcnow establishes the start of the timeline.
        datetime.datetime.min,
        datetime.datetime.min + datetime.timedelta(seconds=5),
        datetime.datetime.min + datetime.timedelta(seconds=11),
    ]


# Path: google/api_core/exceptions.py
# _HTTP_CODE_TO_EXCEPTION: Dict[int, Exception] = {}
# _GRPC_CODE_TO_EXCEPTION: Dict[int, Exception] = {}
# _INT_TO_GRPC_CODE = {}
# class GoogleAPIError(Exception):
# class DuplicateCredentialArgs(GoogleAPIError):
# class RetryError(GoogleAPIError):
# class _GoogleAPICallErrorMeta(type):
# class GoogleAPICallError(GoogleAPIError, metaclass=_GoogleAPICallErrorMeta):
# class Redirection(GoogleAPICallError):
# class MovedPermanently(Redirection):
# class NotModified(Redirection):
# class TemporaryRedirect(Redirection):
# class ResumeIncomplete(Redirection):
# class ClientError(GoogleAPICallError):
# class BadRequest(ClientError):
# class InvalidArgument(BadRequest):
# class FailedPrecondition(BadRequest):
# class OutOfRange(BadRequest):
# class Unauthorized(ClientError):
# class Unauthenticated(Unauthorized):
# class Forbidden(ClientError):
# class PermissionDenied(Forbidden):
# class NotFound(ClientError):
# class MethodNotAllowed(ClientError):
# class Conflict(ClientError):
# class AlreadyExists(Conflict):
# class Aborted(Conflict):
# class LengthRequired(ClientError):
# class PreconditionFailed(ClientError):
# class RequestRangeNotSatisfiable(ClientError):
# class TooManyRequests(ClientError):
# class ResourceExhausted(TooManyRequests):
# class Cancelled(ClientError):
# class ServerError(GoogleAPICallError):
# class InternalServerError(ServerError):
# class Unknown(ServerError):
# class DataLoss(ServerError):
# class MethodNotImplemented(ServerError):
# class BadGateway(ServerError):
# class ServiceUnavailable(ServerError):
# class GatewayTimeout(ServerError):
# class DeadlineExceeded(GatewayTimeout):
#     def __init__(self, message, cause):
#     def cause(self):
#     def __str__(self):
#     def __new__(mcs, name, bases, class_dict):
#     def __init__(self, message, errors=(), details=(), response=None, error_info=None):
#     def __str__(self):
#     def reason(self):
#     def domain(self):
#     def metadata(self):
#     def errors(self):
#     def details(self):
#     def response(self):
# def exception_class_for_http_status(status_code):
# def from_http_status(status_code, message, **kwargs):
# def from_http_response(response):
# def exception_class_for_grpc_status(status_code):
# def from_grpc_status(status_code, message, **kwargs):
# def _is_informative_grpc_error(rpc_exc):
# def _parse_grpc_error_details(rpc_exc):
# def from_grpc_error(rpc_exc):


# Path: tests/unit/test_retry.py
import datetime
import itertools
import re
import mock
import pytest
import requests.exceptions
from google.api_core import exceptions
from google.api_core import retry
from google.auth import exceptions as auth_exceptions

    return_value=datetime.datetime.min,
    autospec=True,
)
def test_retry_target_non_retryable_error(utcnow, sleep):
    predicate = retry.if_exception_type(ValueError)
    exception = TypeError()
    target = mock.Mock(side_effect=exception)

    with pytest.raises(TypeError) as exc_info:
        retry.retry_target(target, predicate, range(10), None)

    assert exc_info.value == exception
    sleep.assert_not_called()


@mock.patch("time.sleep", autospec=True)
@mock.patch("google.api_core.datetime_helpers.utcnow", autospec=True)
def test_retry_target_deadline_exceeded(utcnow, sleep):
    predicate = retry.if_exception_type(ValueError)
    exception = ValueError("meep")
    target = mock.Mock(side_effect=exception)
    # Setup the timeline so that the first call takes 5 seconds but the second
    # call takes 6, which puts the retry over the deadline.
    utcnow.side_effect = [
        # The first call to utcnow establishes the start of the timeline.
        datetime.datetime.min,
        datetime.datetime.min + datetime.timedelta(seconds=5),
        datetime.datetime.min + datetime.timedelta(seconds=11),
    ]


    with pytest.raises(exceptions.RetryError) as exc_info: