o
    ˷eF                     @   sd   d Z ddlmZ G dd deZG dd deZdd Ze Z[G d	d
 d
eZG dd deZ	dS )zShared testing utilities.    )absolute_importc                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	_MonkeyzBContext-manager for replacing module names in the scope of a test.c                    sH    | _ |s	td fdd|D | _| D ]
\}}t || qd S )Nz-_Monkey was used with nothing to monkey-patchc                    s   i | ]}|t  |qS  )getattr).0keymoduler   U/var/www/ideatree/venv/lib/python3.10/site-packages/google/cloud/_testing/__init__.py
<dictcomp>   s    z$_Monkey.__init__.<locals>.<dictcomp>)r	   
ValueError
to_restoreitemssetattr)selfr	   kwr   valuer   r   r
   __init__   s   z_Monkey.__init__c                 C      | S Nr   r   r   r   r
   	__enter__      z_Monkey.__enter__c                 C   s&   | j  D ]\}}t| j|| qd S r   )r   r   r   r	   )r   exc_typeexc_valexc_tbr   r   r   r   r
   __exit__"   s   z_Monkey.__exit__N)__name__
__module____qualname____doc__r   r   r   r   r   r   r
   r      s
    r   c                   @   s&   e Zd Zd	ddZdd Zdd ZdS )
_NamedTemporaryFile c                 C   s0   dd l }dd l}|j|d\}| _|| d S )Nr   )suffix)ostempfilemkstempnameclose)r   r#   r$   r%   
filehandler   r   r
   r   (   s   z_NamedTemporaryFile.__init__c                 C   r   r   r   r   r   r   r
   r   /   r   z_NamedTemporaryFile.__enter__c                 C   s   dd l }|| j d S )Nr   )r$   remover'   )r   r   r   r   r$   r   r   r
   r   2   s   z_NamedTemporaryFile.__exit__N)r"   )r   r   r   r   r   r   r   r   r   r
   r!   '   s    
r!   c                     s0   dd l } dd l dd l| j fdd}|S )Nr   c                  3   s      } | V   |  d S r   )mkdtemprmtree)temp_dirshutilr%   r   r
   _tempdir_mgr=   s   z$_tempdir_maker.<locals>._tempdir_mgr)
contextlibr/   r%   contextmanager)r1   r0   r   r.   r
   _tempdir_maker8   s   r3   c                   @   sF   e Zd ZdZdd ZedddZdd Zd	d
 Zdd Z	dd Z
dS )_GAXBaseAPIFc                 K   s   | j | d S r   )__dict__update)r   r   r   r   r
   r   R   s   z_GAXBaseAPI.__init__Nc                 C   s:   ddl m} ddlm} d}|dd || |}||d d d S )Nr   )	_RPCState)GrpcRendezvouszSome error details.r   )grpc._channelr7   google.cloud.exceptionsr8   )status_codetrailingr7   r8   details	exc_stater   r   r
   _make_grpc_errorU   s
   z_GAXBaseAPI._make_grpc_errorc                 C      ddl m} | |jS Nr   )
StatusCode)grpcrB   r?   	NOT_FOUNDr   rB   r   r   r
   _make_grpc_not_found^      z _GAXBaseAPI._make_grpc_not_foundc                 C   r@   rA   )rC   rB   r?   FAILED_PRECONDITIONrE   r   r   r
   _make_grpc_failed_preconditionc   rG   z*_GAXBaseAPI._make_grpc_failed_preconditionc                 C   r@   rA   )rC   rB   r?   ALREADY_EXISTSrE   r   r   r
   _make_grpc_already_existsh   rG   z%_GAXBaseAPI._make_grpc_already_existsc                 C   r@   rA   )rC   rB   r?   DEADLINE_EXCEEDEDrE   r   r   r
   _make_grpc_deadline_exceededm   rG   z(_GAXBaseAPI._make_grpc_deadline_exceededr   )r   r   r   _random_gax_errorr   staticmethodr?   rF   rI   rK   rM   r   r   r   r
   r4   N   s    r4   c                   @   s   e Zd Zdd Zdd ZdS )_GAXPageIteratorc                 O   s   t || _|d| _d S )N
page_token)iter_pagesgetrQ   )r   pageskwargsr   r   r
   r   t   s   
z_GAXPageIterator.__init__c                 C   s
   t | jS )zIterate to the next page.)nextrS   r   r   r   r
   __next__x   s   
z_GAXPageIterator.__next__N)r   r   r   r   rX   r   r   r   r
   rP   s   s    rP   N)
r    
__future__r   objectr   r!   r3   _tempdirr4   rP   r   r   r   r
   <module>   s   %