AlkantarClanX12

Your IP : 18.226.93.138


Current Path : /opt/alt/python39/lib64/python3.9/unittest/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/unittest/__pycache__/mock.cpython-39.pyc

a

R�f���@s�dZddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
mZmZddl
mZddlmZmZdd�ee�D�Zd	ZeZd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zd�dd�Zdd�Zdd�Zdd�Z dd �Z!d�d!d"�Z"d#d$�Z#d%d&�Z$d'd(�Z%Gd)d*�d*e&�Z'Gd+d,�d,e&�Z(e(�Z)e)j*Z*e)j+Z,e)j-Z.hd-�Z/d.d/�Z0Gd0d1�d1e1�Z2d2d3�Z3Gd4d5�d5e&�Z4Gd6d7�d7e&�Z5Gd8d9�d9e5�Z6e�7e6j8�Z9Gd:d;�d;e1�Z:d<d=�Z;Gd>d?�d?e5�Z<Gd@dA�dAe<e6�Z=dBdC�Z>dDdE�Z?GdFdG�dGe&�Z@dHdI�ZAe*dddddfdJdK�ZBd�dLdM�ZCe*dddddfdNdO�ZDGdPdQ�dQe&�ZEdRdS�ZFdTdU�ZGeBeD_&eEeD_HeCeD_IeGeD_JdVeD_KdWZLdXZMdY�NdZd[�eM�O�D��ZPdY�Nd\d[�eM�O�D��ZQhd]�ZRd^d_�ZSd`d�dY�NeLeMePeQg��O�D�ZThda�ZUdbhZVeUeVBZWeTeRBZXeXeWBZYhdc�ZZddde�dfde�dgde�dhde�di�Z[e\e\e\e\djddddkdld	djddm�
Z]dndo�Z^dpdq�Z_drds�Z`dtdu�Zae^e_e`eadv�Zbdwdx�ZcGdydz�dze5�ZdGd{d|�d|ede6�ZeGd}d~�d~ed�ZfGdd��d�ede=�ZgGd�d��d�e5�ZhGd�d��d�e5�ZiGd�d��d�eiefe=�ZjGd�d��d�e&�Zkek�Zld�d��ZmGd�d��d�en�Zoeodd��Zpd�d�d��Zqd�d��ZrGd�d��d�e&�Zseteq�etelju�fZvdawd�d��Zxd�d�d��ZyGd�d��d�e=�Zzd�d��Z{Gd�d��d��Z|dS)�)�Mock�	MagicMock�patch�sentinel�DEFAULT�ANY�call�create_autospec�	AsyncMock�
FILTER_DIR�NonCallableMock�NonCallableMagicMock�	mock_open�PropertyMock�seal�N)�iscoroutinefunction)�CodeType�
ModuleType�
MethodType)�	safe_repr)�wraps�partialcCsh|]}|�d�s|�qS��_��
startswith)�.0�name�r�2/opt/alt/python39/lib64/python3.9/unittest/mock.py�	<setcomp>'�r TcCs<t|�rt|t�sdSt|d�r*t|d�}t|�p:t�|�S)NF�__func__)�_is_instance_mock�
isinstancer	�hasattr�getattrr�inspectZisawaitable��objrrr�
_is_async_obj/s


r*cCst|dd�rt|�SdSdS)N�__code__F)r&r��funcrrr�_is_async_func7sr.cCstt|�t�S�N)�
issubclass�typerr(rrrr#>sr#cCst|t�pt|t�ot|t�Sr/)r$�
BaseExceptionr1r0r(rrr�
_is_exceptionDs
�r3cCs"t|t�rt|d�r|jS|SdS�N�mock)r$�
FunctionTypesr%r5r(rrr�
_extract_mockKsr7cCs�t|t�r|s|j}d}n*t|t�sDz
|j}WntyBYdS0|rTt|d�}n|}z|t�|�fWSt	y|YdS0dS)z�
    Given an arbitrary, possibly callable object, try to create a suitable
    signature object.
    Return a (reduced func, signature) tuple, or None.
    TN)
r$r1�__init__r6�__call__�AttributeErrorrr'�	signature�
ValueError)r-Zas_instanceZeat_selfZsig_funcrrr�_get_signature_objectTs

r=FcsNt|||���durdS�\}��fdd�}t||�|t|�_�t|�_dS)Ncs�j|i|��dSr/��bind��self�args�kwargs��sigrr�checksigvsz"_check_signature.<locals>.checksig)r=�_copy_func_detailsr1�_mock_check_sig�
__signature__)r-r5�	skipfirst�instancerFrrDr�_check_signatureqs

rLc	Cs8dD].}zt||t||��Wqty0Yq0qdS)N)�__name__�__doc__�__text_signature__�
__module__�__defaults__�__kwdefaults__)�setattrr&r:)r-�funcopy�	attributerrrrG}s
rGcCs@t|t�rdSt|tttf�r(t|j�St|dd�dur<dSdS)NTr9F)r$r1�staticmethod�classmethodr�	_callabler"r&r(rrrrX�s

rXcCst|�ttfvSr/)r1�list�tupler(rrr�_is_list�sr[cCsFt|t�st|dd�duS|f|jD]}|j�d�dur&dSq&dS)ztGiven an object, return True if the object is callable.
    For classes, return True if instances would be callable.r9NTF)r$r1r&�__mro__�__dict__�get)r)�baserrr�_instance_callable�s
r`cs�t|t�}t|||�}|dur"|S|\}��fdd�}t||�|j}|��sRd}||d�}d|}	t|	|�||}
t|
|��|
S)Ncs�j|i|��dSr/r>�rBrCrDrrrF�sz _set_signature.<locals>.checksigrT)Z
_checksig_r5zYdef %s(*args, **kwargs):
    _checksig_(*args, **kwargs)
    return mock(*args, **kwargs))r$r1r=rGrM�isidentifier�exec�_setup_func)r5�originalrKrJ�resultr-rFr�context�srcrTrrDr�_set_signature�s$


�
rics���_�fdd�}�fdd�}�fdd�}�fdd�}�fd	d
�}�fdd�}�fd
d�}	��fdd�}
d�_d�_d�_t��_t��_t��_�j�_�j	�_	�j
�_
|�_|�_|�_
|	�_|
�_|�_|�_|�_|�_��_dS)Ncs�j|i|��Sr/)�assert_called_withra�r5rrrj�sz'_setup_func.<locals>.assert_called_withcs�j|i|��Sr/)�
assert_calledrarkrrrl�sz"_setup_func.<locals>.assert_calledcs�j|i|��Sr/)�assert_not_calledrarkrrrm�sz&_setup_func.<locals>.assert_not_calledcs�j|i|��Sr/)�assert_called_oncerarkrrrn�sz'_setup_func.<locals>.assert_called_oncecs�j|i|��Sr/)�assert_called_once_withrarkrrro�sz,_setup_func.<locals>.assert_called_once_withcs�j|i|��Sr/)�assert_has_callsrarkrrrp�sz%_setup_func.<locals>.assert_has_callscs�j|i|��Sr/)�assert_any_callrarkrrrq�sz$_setup_func.<locals>.assert_any_callcs:t��_t��_����j}t|�r6|�ur6|��dSr/)�	_CallList�method_calls�
mock_calls�
reset_mock�return_valuer#)�ret�rTr5rrru�sz_setup_func.<locals>.reset_mockFr)r5�called�
call_count�	call_argsrr�call_args_listrsrtrv�side_effect�_mock_childrenrjrorprqrurlrmrnrI�_mock_delegate)rTr5rErjrlrmrnrorprqrurrxrrd�s8rdcsJtjj�_d�_d�_t��_�fdd�}dD]}t�|t||��q.dS)Nrcst�j|�|i|��Sr/)r&r5)�attrrBrCrkrr�wrapper�sz"_setup_async_mock.<locals>.wrapper)�assert_awaited�assert_awaited_once�assert_awaited_with�assert_awaited_once_with�assert_any_await�assert_has_awaits�assert_not_awaited)	�asyncio�
coroutines�
_is_coroutine�await_count�
await_argsrr�await_args_listrSr)r5r�rUrrkr�_setup_async_mock�s
r�cCsd|dd�|kS)N�__%s__����r�rrrr�	_is_magicsr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�_SentinelObjectz!A unique, named, sentinel object.cCs
||_dSr/r��rArrrrr8sz_SentinelObject.__init__cCs
d|jS�Nzsentinel.%sr��rArrr�__repr__sz_SentinelObject.__repr__cCs
d|jSr�r�r�rrr�
__reduce__sz_SentinelObject.__reduce__N)rMrP�__qualname__rNr8r�r�rrrrr�sr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�	_SentinelzAAccess attributes to return a named object, usable as a sentinel.cCs
i|_dSr/)�
_sentinelsr�rrrr8"sz_Sentinel.__init__cCs|dkrt�|j�|t|��S)N�	__bases__)r:r��
setdefaultr�r�rrr�__getattr__%sz_Sentinel.__getattr__cCsdS)Nrrr�rrrr�+sz_Sentinel.__reduce__N)rMrPr�rNr8r�r�rrrrr� sr�>�_mock_side_effectrv�_mock_new_parentr}�
_mock_name�_mock_new_name�_mock_parent�_mock_return_valuecCs8t�|�d|}||fdd�}||fdd�}t||�S)NZ_mock_cSs"|j}|durt||�St||�Sr/)rr&)rAr�	_the_namerErrr�_get@s
z"_delegating_property.<locals>._getcSs*|j}|dur||j|<nt|||�dSr/)rr]rS)rA�valuerr�rErrr�_setEsz"_delegating_property.<locals>._set)�_allowed_names�add�property)rr�r�r�rrr�_delegating_property=s

r�c@seZdZdd�Zdd�ZdS)rrcCslt|t�st�||�St|�}t|�}||kr2dStd||d�D]"}||||�}||krDdSqDdS)NFr�T)r$rY�__contains__�len�range)rAr�Z	len_valueZlen_self�iZsub_listrrrr�Rs
z_CallList.__contains__cCst�t|��Sr/)�pprintZpformatrYr�rrrr�`sz_CallList.__repr__N)rMrPr�r�r�rrrrrrPsrrcCs|t|�}t|�sdS|js4|js4|jdus4|jdur8dS|}|durX||urPdS|j}q<|rh||_||_|rx||_||_dS)NFT)r7r#r�r�r�r�)�parentr�r�new_name�_parentrrr�_check_and_set_parentds*��r�c@seZdZdd�Zdd�ZdS)�	_MockItercCst|�|_dSr/)�iterr))rAr)rrrr8�sz_MockIter.__init__cCs
t|j�Sr/)�nextr)r�rrr�__next__�sz_MockIter.__next__N)rMrPr�r8r�rrrrr�sr�c@seZdZeZdZdd�ZdS)�BaseNcOsdSr/rr@rrrr8�sz
Base.__init__)rMrPr�rr�r�r8rrrrr��sr�c@sdeZdZdZdd�ZdLdd�Zd	d
�ZdMdd�ZdNd
d�Zdd�Z	dd�Z
dZee	e
e�Z
edd��Zed�Zed�Zed�Zed�Zed�Zdd�Zdd�Zeee�ZdOddd�d d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Z dPd3d4�Z!d5d6�Z"d7d8�Z#d9d:�Z$d;d<�Z%d=d>�Z&d?d@�Z'dAdB�Z(dQdCdD�Z)dEdF�Z*dGdH�Z+dRdJdK�Z,dS)Srz A non-callable version of `Mock`cOs||f}t|t�sTtj|g|�Ri|��j}|�d|�d��}|durTt|�rTt|f}t|j|d|j	i�}t
t|��|�}|S)N�spec_set�specrN)
r0�AsyncMockMixin�	_MOCK_SIGZbind_partialZ	argumentsr^r*r1rMrN�_safe_superr�__new__)�clsrB�kw�basesZ
bound_argsZspec_arg�newrKrrrr��s
zNonCallableMock.__new__N�FcKs�|dur|}|j}
||
d<||
d<||
d<||
d<d|
d<|durJ|}d}|
durZ|du}
|�|||	|
�i|
d<||
d	<d|
d
<d|
d<d|
d<d
|
d<t�|
d<t�|
d<t�|
d<||
d<|r�|jfi|��tt|��||||||�dS)Nr�r�r�r�F�_mock_sealedTr~�_mock_wrapsrZ_mock_calledZ_mock_call_argsrZ_mock_call_countZ_mock_call_args_listZ_mock_mock_callsrs�_mock_unsafe)r]�_mock_add_specrr�configure_mockr�rr8)rAr�rrr�r��_spec_state�	_new_name�_new_parent�_spec_as_instance�	_eat_selfZunsaferCr]rrrr8�s<




�zNonCallableMock.__init__cCs0t|�}d|_d|_d|_d|_t|||�dS)z�
        Attach a mock as an attribute of this one, replacing its name and
        parent. Calls to the attached mock will be recorded in the
        `method_calls` and `mock_calls` attributes of this one.Nr�)r7r�r�r�r�rS)rAr5rUZ
inner_mockrrr�attach_mock�szNonCallableMock.attach_mockcCs|�||�dS�z�Add a spec to a mock. `spec` can either be an object or a
        list of strings. Only attributes on the `spec` can be fetched as
        attributes from the mock.

        If `spec_set` is True then only attributes on the spec can be set.N)r��rAr�r�rrr�
mock_add_spec�szNonCallableMock.mock_add_speccCs�d}d}g}t|�D]}tt||d��r|�|�q|dur|t|�s|t|t�rT|}nt|�}t|||�}	|	or|	d}t|�}|j}
||
d<||
d<||
d<||
d<||
d<dS)Nr��_spec_class�	_spec_set�_spec_signature�
_mock_methods�_spec_asyncs)	�dirrr&�appendr[r$r1r=r])rAr�r�r�r�r�r�r�r��resr]rrrr��s*
�zNonCallableMock._mock_add_speccCs8|j}|jdur|jj}|tur4|j|dd�}||_|S)N�()�r�r�)r�rrvr�_get_child_mock)rArwrrrZ__get_return_values
�z"NonCallableMock.__get_return_valuecCs,|jdur||j_n||_t||dd�dS)Nr�)rrvr�r�)rAr�rrrZ__set_return_values

z"NonCallableMock.__set_return_valuez1The value to be returned when the mock is called.cCs|jdurt|�S|jSr/)r�r1r�rrr�	__class__s
zNonCallableMock.__class__ryrzr{r|rtcCsN|j}|dur|jS|j}|durJt|�sJt|t�sJt|�sJt|�}||_|Sr/)rr�r}�callabler$r�r3)rA�	delegatedZsfrrrZ__get_side_effect's��z!NonCallableMock.__get_side_effectcCs(t|�}|j}|dur||_n||_dSr/)�	_try_iterrr�r})rAr�r�rrrZ__set_side_effect2s
z!NonCallableMock.__set_side_effect�rvr}cCs�|durg}t|�|vrdS|�t|��d|_d|_d|_t�|_t�|_t�|_|r^t	|_
|rhd|_|j�
�D](}t|t�sr|tur�qr|j|||d�qr|j
}t|�r�||ur�|�|�dS)z-Restore the mock object to its initial state.NFrr�)�idr�ryr{rzrrrtr|rsrr�r�r~�valuesr$�
_SpecState�_deletedrur#)rAZvisitedrvr}�childrwrrrru=s,zNonCallableMock.reset_mockcKsXt|��dd�d�D]>\}}|�d�}|��}|}|D]}t||�}q6t|||�qdS)aZSet attributes on the mock through keyword arguments.

        Attributes plus return values and side effects can be set on child
        mocks using standard dot notation and unpacking a dictionary in the
        method call:

        >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError}
        >>> mock.configure_mock(**attrs)cSs|d�d�S)Nr�.)�count)�entryrrr�<lambda>hr!z0NonCallableMock.configure_mock.<locals>.<lambda>)�keyr�N)�sorted�items�split�popr&rS)rArC�arg�valrB�finalr)r�rrrr�[s	�
zNonCallableMock.configure_mockcCs�|dvrt|��n:|jdur<||jvs.|tvrLtd|��nt|�rLt|��|jsd|�d�rdtd��|j�|�}|tur�t|��np|dur�d}|j	dur�t
|j	|�}|j|||||d�}||j|<n.t|t
�r�t|j|j|j|j|j�}||j|<|S)N>r�r�zMock object has no attribute %r)�assertZassretz1Attributes cannot start with 'assert' or 'assret')r�rrr�r�)r:r��_all_magicsr�r�rr~r^r�r�r&r�r$r�rr�r�rKr�r)rArrfrrrrr�qs:




�
�
zNonCallableMock.__getattr__cCs�|jg}|j}|}d}|dgkr$d}|durZ|}|�|j|�d}|jdkrRd}|j}q$tt|��}|jpnd}t|�dkr�|ddvr�|d7}||d<d�|�S)Nr�r�r�r5r�)r�z().r)r�r�r�rY�reversedr�r��join)rAZ
_name_listr�Zlast�dotZ_firstrrr�_extract_mock_name�s(


z"NonCallableMock._extract_mock_namecCs^|��}d}|dvrd|}d}|jdurDd}|jr8d}||jj}dt|�j||t|�fS)Nr�)r5zmock.z name=%rz spec=%rz spec_set=%rz<%s%s%s id='%s'>)r�r�r�rMr1r�)rArZname_stringZspec_stringrrrr��s 
�zNonCallableMock.__repr__cCsvtst�|�S|jpg}tt|��}t|j�}dd�|j�	�D�}dd�|D�}dd�|D�}t
t||||��S)z8Filter the output of `dir(mock)` to only useful members.cSsg|]\}}|tur|�qSr)r�)rZm_nameZm_valuerrr�
<listcomp>�s�z+NonCallableMock.__dir__.<locals>.<listcomp>cSsg|]}|�d�s|�qSrr�r�errrr��r!cSs"g|]}|�d�rt|�r|�qSr)rr�r�rrrr��s�)r
�object�__dir__r�r�r1rYr]r~r�r��set)rAZextrasZ	from_typeZ	from_dictZfrom_child_mocksrrrr�s


�zNonCallableMock.__dir__csT|tvrt��||�S�jrH�jdurH|�jvrH|�jvrHtd|��n�|tvrbd|}t|��n�|tvr�jdur�|�jvr�td|��t	|�s�t
t��|t||��|���fdd�}n(t
�|d|�t
t��||�|�j|<n,|dkr�|�_dSt
�|||��r|�j|<�j�rFt�|��sF����d|��}td|����t��||�S)Nz!Mock object has no attribute '%s'z.Attempting to set unsupported magic method %r.cs��g|�Ri|��Sr/r�rBr��rerArrr��r!z-NonCallableMock.__setattr__.<locals>.<lambda>r�r�zCannot set )r�r�__setattr__r�r�r]r:�_unsupported_magicsr�r#rSr1�_get_methodr�r~r�r�r%r�)rArr��msg�	mock_namerrrr�s<��

zNonCallableMock.__setattr__cCs�|tvr2|t|�jvr2tt|�|�||jvr2dS|j�|t�}||jvr\tt|��	|�n|t
urlt|��|tur||j|=t
|j|<dSr/)r�r1r]�delattrr~r^�_missingr�r�__delattr__r�r:)rArr)rrrr
s

zNonCallableMock.__delattr__cCs|jpd}t|||�Sr4)r��_format_call_signature�rArBrCrrrr�_format_mock_call_signatures
z+NonCallableMock._format_mock_call_signaturercCs.d}|�||�}|j}|j|�}||||fS)Nz.expected %s not found.
Expected: %s
Actual: %s)rr{)rArBrC�action�message�expected_stringr{Z
actual_stringrrr�_format_mock_failure_messages

z,NonCallableMock._format_mock_failure_messagecCsj|s
|jSd}|�dd��d�}|j}|D]:}|�|�}|dusJt|t�rPqfq*t|�}|j}|j}q*|S)aH
        * If call objects are asserted against a method/function like obj.meth1
        then there could be no name for the call object to lookup. Hence just
        return the spec_signature of the method/function being asserted against.
        * If the name is not empty then remove () and split by '.' to get
        list of names to iterate through the children until a potential
        match is found. A child mock is created only during attribute access
        so if we get a _SpecState then no attributes of the spec were accessed
        and can be safely exited.
        Nr�r�r�)r��replacer�r~r^r$r�r7)rArrE�namesZchildrenr�rrr�_get_call_signature_from_name s
z-NonCallableMock._get_call_signature_from_namec
Cs�t|t�r&t|�dkr&|�|d�}n|j}|dur�t|�dkrNd}|\}}n
|\}}}z"|j|i|��}t||j|j�WSt	y�}z|�
d�WYd}~Sd}~00n|SdS)a
        Given a call (or simply an (args, kwargs) tuple), return a
        comparison key suitable for matching with other calls.
        This is a best effort method which relies on the spec's signature,
        if available, or falls back on the arguments themselves.
        r�rNr�)r$rZr�rr�r?rrBrC�	TypeError�with_traceback)rA�_callrErrBrCZ
bound_callrrrr�
_call_matcherAs

"zNonCallableMock._call_matchercCs0|jdkr,d|jpd|j|��f}t|��dS)z/assert that the mock was never called.
        rz9Expected '%s' to not have been called. Called %s times.%sr5N�rzr��_calls_repr�AssertionError�rAr	rrrrm\s
��z!NonCallableMock.assert_not_calledcCs$|jdkr d|jpd}t|��dS)z6assert that the mock was called at least once
        rz"Expected '%s' to have been called.r5N)rzr�rrrrrrlfs

�zNonCallableMock.assert_calledcCs0|jdks,d|jpd|j|��f}t|��dS)z3assert that the mock was called only once.
        r�z:Expected '%s' to have been called once. Called %s times.%sr5Nrrrrrrnns
��z"NonCallableMock.assert_called_oncecs��jdur.�����}d}d||f}t|�����fdd�}��t��fdd��}���j�}||kr�t|t�rv|nd}t|��|�dS)z�assert that the last call was made with the specified arguments.

        Raises an AssertionError if the args and keyword args passed in are
        different to the last call to the mock.Nznot called.z0expected call not found.
Expected: %s
Actual: %scs�����}|Sr/�r�r	�rBrCrArr�_error_message�sz:NonCallableMock.assert_called_with.<locals>._error_messageT��two)r{rrr�_Callr$�	Exception)rArBrC�expected�actualZ
error_messager#�causerr"rrjxs
�z"NonCallableMock.assert_called_withcOs<|jdks,d|jpd|j|��f}t|��|j|i|��S)ziassert that the mock was called exactly once and that that call was
        with the specified arguments.r�z3Expected '%s' to be called once. Called %s times.%sr5)rzr�rrrj�rArBrCr	rrrro�s
��z'NonCallableMock.assert_called_once_withc		s�fdd�|D�}tdd�|D�d�}t�fdd��jD��}|s�||vr�|durXd}nd�d	d�|D��}t|�d
t|���jdd��d
����|�dSt|�}g}|D]0}z|�|�Wq�t	y�|�
|�Yq�0q�|r�td�jp�dt|�|f�|�dS)a�assert the mock has been called with the specified calls.
        The `mock_calls` list is checked for the calls.

        If `any_order` is False (the default) then the calls must be
        sequential. There can be extra calls before or after the
        specified calls.

        If `any_order` is True then the calls can be in any order, but
        they must all appear in `mock_calls`.csg|]}��|��qSr�r�r�cr�rrr��r!z4NonCallableMock.assert_has_calls.<locals>.<listcomp>css|]}t|t�r|VqdSr/�r$r'r�rrr�	<genexpr>�r!z3NonCallableMock.assert_has_calls.<locals>.<genexpr>Nc3s|]}��|�VqdSr/r,r-r�rrr0�r!zCalls not found.z+Error processing expected calls.
Errors: {}cSsg|]}t|t�r|nd�qSr/r/r�rrrr��s��
Expected: ZActual)�prefixr�z@%r does not contain all of %r in its call list, found %r insteadr5)
r�rrrt�formatrr�rstriprY�remover<r�r�rZ)	rA�calls�	any_orderr(r*Z	all_calls�problem�	not_found�kallrr�rrp�sN
����������z NonCallableMock.assert_has_callscsj��t||fdd��}t|t�r$|nd}�fdd��jD�}|sL|t|�vrf��||�}td|�|�dS)z�assert the mock has been called with the specified arguments.

        The assert passes if the mock has *ever* been called, unlike
        `assert_called_with` and `assert_called_once_with` that only pass if
        the call is the most recent one.Tr$Ncsg|]}��|��qSrr,r-r�rrr��r!z3NonCallableMock.assert_any_call.<locals>.<listcomp>z%s call not found)rr&r$r'r|�_AnyComparerrr�rArBrCr(r*r)rrr�rrq�s��zNonCallableMock.assert_any_callcKs�|�d�}||jdvr&tfi|��S|jrZd|vrBd|d��nd}|��|}t|��t|�}t|t�rz|t	vrzt}nbt|t
�r�|tvs�|jr�||jvr�t}q�t}n4t|t
�s�t|t�r�t}q�t|t�r�t}n
|jd}|fi|��S)aPCreate the child mocks for attributes and return value.
        By default child mocks will be the same type as the parent.
        Subclasses of Mock may want to override this to customize the way
        child mocks are made.

        For non-callable mocks the callable variant will be used (rather than
        any custom subclass).r�r�rr�r�r�)r^r]r	r�r�r:r1r0r�_async_method_magicsr��_all_sync_magicsr��
CallableMixinrrrr\)rAr�r�rUr
�_type�klassrrrr��s2

��



zNonCallableMock._get_child_mock�CallscCs"|js
dSd|�dt|j��d�S)z�Renders self.mock_calls as a string.

        Example: "
Calls: [call(1), call(2)]."

        If self.mock_calls is empty, an empty string is returned. The
        output will be truncated if very long.
        r��
z: r�)rtr)rAr2rrrr�szNonCallableMock._calls_repr)NNNNNNr�NFNF)F)FF)N)r)F)rB)-rMrPr�rNr�r8r�r�r�Z"_NonCallableMock__get_return_valueZ"_NonCallableMock__set_return_valueZ"_NonCallableMock__return_value_docr�rvr�r�ryrzr{r|rtZ!_NonCallableMock__get_side_effectZ!_NonCallableMock__set_side_effectr}rur�r�r�r�rrr
rrrrrmrlrnrjrorprqr�rrrrrr�s`�
-
	�

�

''
!


-&rc@seZdZdZdd�ZdS)r;z�A list which checks if it contains a call which may have an
    argument of ANY, flipping the components of item and self from
    their traditional locations so that ANY is guaranteed to be on
    the left.cCs@|D]6}t|�t|�ksJ�tdd�t||�D��rdSqdS)NcSsg|]\}}||k�qSrr)rr(r)rrrr�s�z-_AnyComparer.__contains__.<locals>.<listcomp>TF)r��all�zip)rA�itemrrrrr�s�z_AnyComparer.__contains__N)rMrPr�rNr�rrrrr;
sr;cCsJ|dur|St|�r|St|�r$|Sz
t|�WStyD|YS0dSr/)r3rXr�rr(rrrr�s
r�c
@sReZdZddedddddddf
dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)r?Nr�c	Ks:||jd<tt|�j|||||||	|
fi|��||_dS)Nr�)r]r�r?r8r})rAr�r}rvrrr�r�r�r�r�rCrrrr8.s


��zCallableMixin.__init__cOsdSr/rr@rrrrH:szCallableMixin._mock_check_sigcOs0|j|i|��|j|i|��|j|i|��Sr/)rH�_increment_mock_call�
_mock_callr@rrrr9?szCallableMixin.__call__cOs|j|i|��Sr/)�_execute_mock_callr@rrrrHGszCallableMixin._mock_callcOsd|_|jd7_t||fdd�}||_|j�|�|jdu}|j}|j}|dk}|j	�td||f��|j
}|dur�|r�|j�t|||f��|jdu}|r�|jd|}t|||f�}	|j	�|	�|jr�|r�d}
nd}
|jdk}|j|
|}|j
}qpdS)NTr�r$r�r�r�)ryrzr&r{r|r�r�r�r�rtr�rs)rArBrCrZdo_method_callsZmethod_call_nameZmock_call_nameZ	is_a_callr�Zthis_mock_callr�rrrrGJs4


z"CallableMixin._increment_mock_callcOs�|j}|durTt|�r|�n,t|�s:t|�}t|�rH|�n||i|��}|turT|S|jturd|jS|jdur~|j|i|��S|jSr/)r}r3rXr�rr�rvr�)rArBrC�effectrfrrrrIxs 

z CallableMixin._execute_mock_call)
rMrPr�rr8rHr9rHrGrIrrrrr?,s�
.r?c@seZdZdZdS)ra�	
    Create a new `Mock` object. `Mock` takes several optional arguments
    that specify the behaviour of the Mock object:

    * `spec`: This can be either a list of strings or an existing object (a
      class or instance) that acts as the specification for the mock object. If
      you pass in an object then a list of strings is formed by calling dir on
      the object (excluding unsupported magic attributes and methods). Accessing
      any attribute not in this list will raise an `AttributeError`.

      If `spec` is an object (rather than a list of strings) then
      `mock.__class__` returns the class of the spec object. This allows mocks
      to pass `isinstance` tests.

    * `spec_set`: A stricter variant of `spec`. If used, attempting to *set*
      or get an attribute on the mock that isn't on the object passed as
      `spec_set` will raise an `AttributeError`.

    * `side_effect`: A function to be called whenever the Mock is called. See
      the `side_effect` attribute. Useful for raising exceptions or
      dynamically changing return values. The function is called with the same
      arguments as the mock, and unless it returns `DEFAULT`, the return
      value of this function is used as the return value.

      If `side_effect` is an iterable then each call to the mock will return
      the next value from the iterable. If any of the members of the iterable
      are exceptions they will be raised instead of returned.

    * `return_value`: The value returned when the mock is called. By default
      this is a new Mock (created on first access). See the
      `return_value` attribute.

    * `wraps`: Item for the mock object to wrap. If `wraps` is not None then
      calling the Mock will pass the call through to the wrapped object
      (returning the real result). Attribute access on the mock will return a
      Mock object that wraps the corresponding attribute of the wrapped object
      (so attempting to access an attribute that doesn't exist will raise an
      `AttributeError`).

      If the mock has an explicit `return_value` set then calls are not passed
      to the wrapped object and the `return_value` is returned instead.

    * `name`: If the mock has a name then it will be used in the repr of the
      mock. This can be useful for debugging. The name is propagated to child
      mocks.

    Mocks can also be called with arbitrary keyword arguments. These will be
    used to set attributes on the mock after it is created.
    N�rMrPr�rNrrrrr�srcCs6zt||�WSty0t|�t||�YS0dSr/)r&r:�
__import__)�thing�comp�import_pathrrr�_dot_lookup�s
rPcCsB|�d�}|�d�}t|�}|D]}|d|7}t|||�}q |S)Nr�rz.%s)r�r�rLrP)�targetZ
componentsrOrMrNrrr�	_importer�s

rRc@szeZdZdZgZdd�Zdd�Zdd�Zdd	�Ze	j
d
d��Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)�_patchNc

Csn|dur(|turtd��|dur(td��||_||_||_||_||_||_d|_||_	||_
|	|_g|_dS)Nz,Cannot use 'new' and 'new_callable' togetherz1Cannot use 'autospec' and 'new_callable' togetherF)
rr<�getterrUr��new_callabler��createZ	has_localr��autospecrC�additional_patchers)
rArTrUr�r�rVr�rWrUrCrrrr8�s(��z_patch.__init__c
CsHt|j|j|j|j|j|j|j|j|j	�	}|j
|_
dd�|jD�|_|S)NcSsg|]}|���qSr)�copy)r�prrrr�sz_patch.copy.<locals>.<listcomp>)rSrTrUr�r�rVr�rWrUrC�attribute_namerX)rA�patcherrrrrY�s��z_patch.copycCs2t|t�r|�|�St�|�r(|�|�S|�|�Sr/)r$r1�decorate_classr'r�decorate_async_callable�decorate_callable�rAr-rrrr9s




z_patch.__call__cCsNt|�D]@}|�tj�sqt||�}t|d�s0q|��}t||||��q|S�Nr9)r�rr�TEST_PREFIXr&r%rYrS)rArAr��
attr_valuer\rrrr]s

z_patch.decorate_classccs�g}t���f}|jD]8}|�|�}|jdur8|�|�q|jtur|�|�q|t	|�7}||fVWd�n1sx0YdSr/)
�
contextlib�	ExitStack�	patchings�
enter_contextr[�updater�rr�rZ)rA�patchedrB�keywargs�
extra_args�
exit_stack�patchingr�rrr�decoration_helpers




z_patch.decoration_helpercs>t�d�r�j����St�����fdd����g�_�S)NrfcsD���||��"\}}�|i|��Wd�S1s60YdSr/�rn�rBrjZnewargsZnewkeywargs�r-rirArrri3s�z)_patch.decorate_callable.<locals>.patched�r%rfr�rr`rrqrr_-s
z_patch.decorate_callablecs>t�d�r�j����St�����fdd����g�_�S)Nrfc�sJ���||��(\}}�|i|��IdHWd�S1s<0YdSr/rorprqrrriDs�z/_patch.decorate_async_callable.<locals>.patchedrrr`rrqrr^>s
z_patch.decorate_async_callablec	Cs�|��}|j}t}d}z|j|}Wn"ttfyFt||t�}Yn0d}|tvrdt|t	�rdd|_
|j
s�|tur�td||f��||fS)NFTz!%s does not have the attribute %r)rTrUrr]r:�KeyErrorr&�	_builtinsr$rrV)rArQrre�localrrr�get_originalOs 
�z_patch.get_originalcCs�|j|j|j}}}|j|j}}|j}|��|_|dur@d}|durLd}|durXd}|durp|durptd��|dus�|dur�|dvr�td��|�	�\}}|t
u�r�|du�r�d}	|dur�|}|dur�|}d}n&|dur�|dur�|}d}n|dur�|}|du�s|du�r.|t
u�rtd��t|t��r.d}	|du�rHt
|��rHt}
nt}
i}|du�r`|}
n^|du�st|du�r�|}|du�r�|}t|��r�d|v}
n
t|�}
t
|��r�t}
n
|
�r�t}
|du�r�||d	<|du�r�||d
<t|
t��rt|
t��r|j�r|j|d<|�|�|
fi|��}|	�r�t|��r�|}|du�rF|}t|��s^t|��s^t}
|�d�|
f|dd
�|��|_nl|du�r�|t
u�r�td��|t
u�r�td��t|�}|du�r�|}t|f||jd�|��}n|�r�td��|}||_||_t� �|_!zrt"|j|j|�|j#du�rti}|jt
u�r>|||j#<|j$D](}|j!�%|�}|jt
u�rD|�|��qD|WS|WS|j&t'�(���s��Yn0dS)zPerform the patch.FNzCan't specify spec and autospec)TNz6Can't provide explicit spec_set *and* spec or autospecTz!Can't use 'spec' with create=Truer9r�r�rr�r�zBautospec creates the mock for you. Can't specify autospec and new.z%Can't use 'autospec' with create=True)r��_namez.Can't pass kwargs to a mock we aren't creating))r�r�r�rWrCrUrTrQrrvrr$r1r*r	rr[r�rr0rrUrhr#r`r�rv�boolr�
temp_original�is_localrdre�_exit_stackrSr[rXrg�__exit__�sys�exc_info)rAr�r�r�rWrCrUreruZinherit�Klass�_kwargsZ	this_specZnot_callableZnew_attrrkrmr�rrr�	__enter__gs�
�








��



�
�


�

��


z_patch.__enter__cGs�|jr$|jtur$t|j|j|j�n>t|j|j�|jsbt|j|j�rP|jdvrbt|j|j|j�|`|`|`|j	}|`	|j
|�S)zUndo the patch.)rNrPrQ�__annotations__rR)rzryrrSrQrUrrVr%r{r|)rAr~rlrrrr|�s�z_patch.__exit__cCs|��}|j�|�|S�z-Activate a patch, returning any created mock.)r��_active_patchesr��rArfrrr�startsz_patch.startcCs4z|j�|�Wnty$YdS0|�ddd�S�zStop an active patch.N)r�r5r<r|r�rrr�stop	s
z_patch.stop)rMrPr�r[r�r8rYr9r]rd�contextmanagerrnr_r^rvr�r|r�r�rrrrrS�s 

rSc
sPz��dd�\�}Wn&tttfy:td�����Yn0�fdd�}||fS)Nr�r�z,Need a valid target to patch. You supplied: cst��Sr/�rRr�rQrrr�r!z_get_target.<locals>.<lambda>)�rsplitrr<r:)rQrUrTrr�r�_get_targets�
r�c

s>t��turt��d����fdd�}	t|	||||||||�	S)a
    patch the named member (`attribute`) on an object (`target`) with a mock
    object.

    `patch.object` can be used as a decorator, class decorator or a context
    manager. Arguments `new`, `spec`, `create`, `spec_set`,
    `autospec` and `new_callable` have the same meaning as for `patch`. Like
    `patch`, `patch.object` takes arbitrary keyword arguments for configuring
    the mock object it creates.

    When used as a class decorator `patch.object` honours `patch.TEST_PREFIX`
    for choosing which methods to wrap.
    z3 must be the actual object to be patched, not a strcs�Sr/rrr�rrr�5r!z_patch_object.<locals>.<lambda>)r1�strrrS)
rQrUr�r�rVr�rWrUrCrTrr�r�
_patch_objects�
�r�c
s�t��tur�fdd�}n�fdd�}|s2td��t|���}|d\}	}
t||	|
|||||i�	}|	|_|dd�D]2\}	}
t||	|
|||||i�	}|	|_|j�|�qt|S)a�Perform multiple patches in a single call. It takes the object to be
    patched (either as an object or a string to fetch the object by importing)
    and keyword arguments for the patches::

        with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'):
            ...

    Use `DEFAULT` as the value if you want `patch.multiple` to create
    mocks for you. In this case the created mocks are passed into a decorated
    function by keyword, and a dictionary is returned when `patch.multiple` is
    used as a context manager.

    `patch.multiple` can be used as a decorator, class decorator or a context
    manager. The arguments `spec`, `spec_set`, `create`,
    `autospec` and `new_callable` have the same meaning as for `patch`. These
    arguments will be applied to *all* patches done by `patch.multiple`.

    When used as a class decorator `patch.multiple` honours `patch.TEST_PREFIX`
    for choosing which methods to wrap.
    cst��Sr/r�rr�rrr�Sr!z!_patch_multiple.<locals>.<lambda>cs�Sr/rrr�rrr�Ur!z=Must supply at least one keyword argument with patch.multiplerr�N)	r1r�r<rYr�rSr[rXr�)
rQr�rVr�rWrUrCrTr�rUr�r\Zthis_patcherrr�r�_patch_multiple<s,���r�c

Ks$t|�\}}	t||	|||||||�	S)az
    `patch` acts as a function decorator, class decorator or a context
    manager. Inside the body of the function or with statement, the `target`
    is patched with a `new` object. When the function/with statement exits
    the patch is undone.

    If `new` is omitted, then the target is replaced with an
    `AsyncMock if the patched object is an async function or a
    `MagicMock` otherwise. If `patch` is used as a decorator and `new` is
    omitted, the created mock is passed in as an extra argument to the
    decorated function. If `patch` is used as a context manager the created
    mock is returned by the context manager.

    `target` should be a string in the form `'package.module.ClassName'`. The
    `target` is imported and the specified object replaced with the `new`
    object, so the `target` must be importable from the environment you are
    calling `patch` from. The target is imported when the decorated function
    is executed, not at decoration time.

    The `spec` and `spec_set` keyword arguments are passed to the `MagicMock`
    if patch is creating one for you.

    In addition you can pass `spec=True` or `spec_set=True`, which causes
    patch to pass in the object being mocked as the spec/spec_set object.

    `new_callable` allows you to specify a different class, or callable object,
    that will be called to create the `new` object. By default `AsyncMock` is
    used for async functions and `MagicMock` for the rest.

    A more powerful form of `spec` is `autospec`. If you set `autospec=True`
    then the mock will be created with a spec from the object being replaced.
    All attributes of the mock will also have the spec of the corresponding
    attribute of the object being replaced. Methods and functions being
    mocked will have their arguments checked and will raise a `TypeError` if
    they are called with the wrong signature. For mocks replacing a class,
    their return value (the 'instance') will have the same spec as the class.

    Instead of `autospec=True` you can pass `autospec=some_object` to use an
    arbitrary object as the spec instead of the one being replaced.

    By default `patch` will fail to replace attributes that don't exist. If
    you pass in `create=True`, and the attribute doesn't exist, patch will
    create the attribute for you when the patched function is called, and
    delete it again afterwards. This is useful for writing tests against
    attributes that your production code creates at runtime. It is off by
    default because it can be dangerous. With it switched on you can write
    passing tests against APIs that don't actually exist!

    Patch can be used as a `TestCase` class decorator. It works by
    decorating each test method in the class. This reduces the boilerplate
    code when your test methods share a common patchings set. `patch` finds
    tests by looking for method names that start with `patch.TEST_PREFIX`.
    By default this is `test`, which matches the way `unittest` finds tests.
    You can specify an alternative prefix by setting `patch.TEST_PREFIX`.

    Patch can be used as a context manager, with the with statement. Here the
    patching applies to the indented block after the with statement. If you
    use "as" then the patched object will be bound to the name after the
    "as"; very useful if `patch` is creating a mock object for you.

    `patch` takes arbitrary keyword arguments. These will be passed to
    `AsyncMock` if the patched object is asynchronous, to `MagicMock`
    otherwise or to `new_callable` if specified.

    `patch.dict(...)`, `patch.multiple(...)` and `patch.object(...)` are
    available for alternate use-cases.
    )r�rS)
rQr�r�rVr�rWrUrCrTrUrrrrms
G
�rc@sZeZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�ZdS)�_patch_dicta#
    Patch a dictionary, or dictionary like object, and restore the dictionary
    to its original state after the test.

    `in_dict` can be a dictionary or a mapping like container. If it is a
    mapping then it must at least support getting, setting and deleting items
    plus iterating over keys.

    `in_dict` can also be a string specifying the name of the dictionary, which
    will then be fetched by importing it.

    `values` can be a dictionary of values to set in the dictionary. `values`
    can also be an iterable of `(key, value)` pairs.

    If `clear` is True then the dictionary will be cleared before the new
    values are set.

    `patch.dict` can also be called with arbitrary keyword arguments to set
    values in the dictionary::

        with patch.dict('sys.modules', mymodule=Mock(), other_module=Mock()):
            ...

    `patch.dict` can be used as a context manager, decorator or class
    decorator. When used as a class decorator `patch.dict` honours
    `patch.TEST_PREFIX` for choosing which methods to wrap.
    rFcKs,||_t|�|_|j�|�||_d|_dSr/)�in_dict�dictr�rh�clear�	_original)rAr�r�r�rCrrrr8�s

z_patch_dict.__init__cs.t�t�r����St����fdd��}|S)Ncs0���z�|i|��W���S���0dSr/)r��
_unpatch_dictr��frArr�_inner�s�z$_patch_dict.__call__.<locals>._inner)r$r1r]r)rAr�r�rr�rr9�s


z_patch_dict.__call__cCsXt|�D]J}t||�}|�tj�rt|d�rt|j|j|j	�}||�}t
|||�q|Sra)r�r&rrrbr%r�r�r�r�rS)rArAr�rc�	decoratorZ	decoratedrrrr]�s
�z_patch_dict.decorate_classcCs|��|jS)zPatch the dict.)r�r�r�rrrr��sz_patch_dict.__enter__cCs�|j}t|jt�rt|j�|_|j}|j}z|��}Wn,tybi}|D]}||||<qLYn0||_|rvt	|�z|�
|�Wn(ty�|D]}||||<q�Yn0dSr/)r�r$r�r�rRr�rYr:r��_clear_dictrh)rAr�r�r�rer�rrrr�s&z_patch_dict._patch_dictcCsP|j}|j}t|�z|�|�Wn(tyJ|D]}||||<q4Yn0dSr/)r�r�r�rhr:)rAr�rer�rrrr�sz_patch_dict._unpatch_dictcGs|jdur|��dS)zUnpatch the dict.NF)r�r�)rArBrrrr|)s
z_patch_dict.__exit__cCs|��}tj�|�|Sr�)r�rSr�r�r�rrrr�0sz_patch_dict.startcCs4ztj�|�Wnty$YdS0|�ddd�Sr�)rSr�r5r<r|r�rrrr�7s
z_patch_dict.stopN)rF)
rMrPr�rNr8r9r]r�r�r�r|r�r�rrrrr��s
	
r�cCs<z|��Wn*ty6t|�}|D]
}||=q&Yn0dSr/)r�r:rY)r��keysr�rrrr�Bsr�cCsttj�D]}|��q
dS)z7Stop all active patches. LIFO to unroll nested patches.N)r�rSr�r�)rrrr�_patch_stopallKsr��testz�lt le gt ge eq ne getitem setitem delitem len contains iter hash str sizeof enter exit divmod rdivmod neg pos abs invert complex int float index round trunc floor ceil bool next fspath aiter zHadd sub mul matmul div floordiv mod lshift rshift and xor or pow truediv� ccs|]}d|VqdS)zi%sNr�r�nrrrr0jr!r0ccs|]}d|VqdS)zr%sNrr�rrrr0kr!>rr��__subclasses__Z__getinitargs__�
__setformat__�__getstate__�
__format__�__reversed__�__set__�__getnewargs__�__missing__�
__getformat__�__getnewargs_ex__r��
__reduce_ex__�__get__�
__delete__�__setstate__cs�fdd�}||_|S)z:Turns a callable object (like a mock) into a real functioncs�|g|�Ri|��Sr/r�rArBr�r,rr�method|sz_get_method.<locals>.method)rM)rr-r�rr,rrzsrcCsh|]}d|�qS)r�r)rr�rrrr �s>�	__aexit__�	__anext__�
__aenter__�	__aiter__>rr�r8�__prepare__�__del__�__instancecheck__r��__subclasscheck__cCs
t�|�Sr/)r�__hash__r�rrrr��r!r�cCs
t�|�Sr/)r�__str__r�rrrr��r!cCs
t�|�Sr/)r�
__sizeof__r�rrrr��r!cCs"t|�j�d|���dt|���S)N�/)r1rMr�r�r�rrrr��r!)r�r�r��
__fspath__r�y�?g�?)
�__lt__�__gt__�__le__�__ge__�__int__r��__len__r|�__complex__�	__float__�__bool__�	__index__r�cs�fdd�}|S)Ncs$�jj}|tur|S�|ur dStS�NT)�__eq__r�r�NotImplemented)�other�ret_valr�rrr��sz_get_eq.<locals>.__eq__r)rAr�rr�r�_get_eq�sr�cs�fdd�}|S)Ncs �jjturtS�|urdStS�NF)�__ne__r�rr�)r�r�rrr��s
z_get_ne.<locals>.__ne__r)rAr�rr�r�_get_ne�sr�cs�fdd�}|S)Ncs �jj}|turtg�St|�Sr/)�__iter__r�rr��r�r�rrr��sz_get_iter.<locals>.__iter__r)rAr�rr�r�	_get_iter�sr�cs�fdd�}|S)Ncs(�jj}|turttg��Stt|��Sr/)r�r�r�_AsyncIteratorr�r�r�rrr��sz"_get_async_iter.<locals>.__aiter__r)rAr�rr�r�_get_async_iter�sr�)r�r�r�r�cCsbt�|t�}|tur||_dSt�|�}|durB||�}||_dSt�|�}|dur^||�|_dSr/)�_return_valuesr^rrv�_calculate_return_value�_side_effect_methodsr})r5r�rZfixedZreturn_calculatorrvZ
side_effectorrrr�_set_return_value�s

r�c@seZdZdd�Zdd�ZdS)�
MagicMixincOs*|��tt|�j|i|��|��dSr/)�_mock_set_magicsr�r�r8r�rrrr8�szMagicMixin.__init__cCs�ttB}|}t|dd�durX|�|j�}t�}||}|D]}|t|�jvr:t||�q:|tt|�j�}t|�}|D]}t	||t
||��qvdS)Nr�)�_magicsr=r&�intersectionr�rr1r]rrS�
MagicProxy)rAZorig_magicsZthese_magicsZ
remove_magicsr�r@rrrr��szMagicMixin._mock_set_magicsN)rMrPr�r8r�rrrrr��sr�c@seZdZdZddd�ZdS)rz-A version of `MagicMock` that isn't callable.FcCs|�||�|��dSr��r�r�r�rrrr�sz"NonCallableMagicMock.mock_add_specN)F�rMrPr�rNr�rrrrrsrc@seZdZdd�ZdS)�AsyncMagicMixincOs*|��tt|�j|i|��|��dSr/)r�r�r�r8r�rrrr8szAsyncMagicMixin.__init__N�rMrPr�r8rrrrr�sr�c@seZdZdZddd�ZdS)ra�
    MagicMock is a subclass of Mock with default implementations
    of most of the magic methods. You can use MagicMock without having to
    configure the magic methods yourself.

    If you use the `spec` or `spec_set` arguments then *only* magic
    methods that exist in the spec will be created.

    Attributes and the return value of a `MagicMock` will also be `MagicMocks`.
    FcCs|�||�|��dSr�r�r�rrrr�+szMagicMock.mock_add_specN)Fr�rrrrr s
rc@s&eZdZdd�Zdd�Zddd�ZdS)	r�cCs||_||_dSr/�rr�)rArr�rrrr87szMagicProxy.__init__cCs8|j}|j}|j|||d�}t|||�t|||�|S)N)rr�r�)rr�r�rSr�)rAr�r��mrrr�create_mock;s�zMagicProxy.create_mockNcCs|��Sr/)r�)rAr)r@rrrr�DszMagicProxy.__get__)N)rMrPr�r8r�r�rrrrr�6s	r�cs�eZdZed�Zed�Zed�Z�fdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
ddd�Zdd�Z�fdd�Z�ZS)r�r�r�r�cs`t�j|i|��tjj|jd<d|jd<d|jd<t�|jd<ttd�}t	j
|_||jd<dS)Nr�rZ_mock_await_countZ_mock_await_argsZ_mock_await_args_list�r�r+)�superr8r�r�r�r]rrrrr'ZCO_COROUTINE�co_flags)rArBrC�	code_mock�r�rrr8Ms


zAsyncMockMixin.__init__c�st||fdd�}|jd7_||_|j�|�|j}|dur�t|�rL|�nft|�s�zt|�}Wnt	yvt
�Yn0t|�r�|�n,t|�r�||i|��IdH}n||i|��}|tur�|S|j
tur�|jS|jdu�r
t|j�r�|j|i|��IdHS|j|i|��S|jS)NTr$r�)r&r�r�r�r�r}r3rXr��
StopIteration�StopAsyncIterationrrr�rvr�)rArBrCrrJrfrrrrI]s6


z!AsyncMockMixin._execute_mock_callcCs(|jdkr$d|jpd�d�}t|��dS)zA
        Assert that the mock was awaited at least once.
        r�	Expected r5z to have been awaited.N�r�r�rrrrrr��s
zAsyncMockMixin.assert_awaitedcCs0|jdks,d|jpd�d|j�d�}t|��dS)z@
        Assert that the mock was awaited exactly once.
        r�r�r5�$ to have been awaited once. Awaited � times.Nr�rrrrr��s

�z"AsyncMockMixin.assert_awaited_oncecs��jdur&�����}td|�d������fdd�}��t��fdd��}���j�}||kr~t|t�rn|nd}t|��|�dS)zN
        Assert that the last await was with the specified arguments.
        NzExpected await: z
Not awaitedcs�j��dd�}|S)N�await)rr r!r"rrr#�sz:AsyncMockMixin.assert_awaited_with.<locals>._error_messageTr$)r�rrrr&r$r')rArBrCr(r#r)r*rr"rr��s
z"AsyncMockMixin.assert_awaited_withcOs<|jdks,d|jpd�d|j�d�}t|��|j|i|��S)zi
        Assert that the mock was awaited exactly once and with the specified
        arguments.
        r�r�r5r�r�)r�r�rr�r+rrrr��s
�z'AsyncMockMixin.assert_awaited_once_withcsj��t||fdd��}t|t�r$|nd}�fdd��jD�}|sL|t|�vrf��||�}td|�|�dS)zU
        Assert the mock has ever been awaited with the specified arguments.
        Tr$Ncsg|]}��|��qSrr,r-r�rrr��r!z3AsyncMockMixin.assert_any_await.<locals>.<listcomp>z%s await not found)rr&r$r'r�r;rrr<rr�rr��s��zAsyncMockMixin.assert_any_awaitFc		s��fdd�|D�}tdd�|D�d�}t�fdd��jD��}|s�||vr�|durXd}nd�d	d�|D��}t|�d
t|��d�j���|�dSt|�}g}|D]0}z|�|�Wq�ty�|�|�Yq�0q�|r�tdt	|�f�|�dS)
a�
        Assert the mock has been awaited with the specified calls.
        The :attr:`await_args_list` list is checked for the awaits.

        If `any_order` is False (the default) then the awaits must be
        sequential. There can be extra calls before or after the
        specified awaits.

        If `any_order` is True then the awaits can be in any order, but
        they must all appear in :attr:`await_args_list`.
        csg|]}��|��qSrr,r-r�rrr��r!z4AsyncMockMixin.assert_has_awaits.<locals>.<listcomp>css|]}t|t�r|VqdSr/r/r�rrrr0�r!z3AsyncMockMixin.assert_has_awaits.<locals>.<genexpr>Nc3s|]}��|�VqdSr/r,r-r�rrr0�r!zAwaits not found.z,Error processing expected awaits.
Errors: {}cSsg|]}t|t�r|nd�qSr/r/r�rrrr��s�r1z	
Actual: z%r not all found in await list)
r�rrr�r3rrYr5r<r�rZ)	rAr6r7r(r*Z
all_awaitsr8r9r:rr�rr��sF��������z AsyncMockMixin.assert_has_awaitscCs0|jdkr,d|jpd�d|j�d�}t|��dS)z9
        Assert that the mock was never awaited.
        rr�r5z# to not have been awaited. Awaited r�Nr�rrrrr��s

�z!AsyncMockMixin.assert_not_awaitedcs*t�j|i|��d|_d|_t�|_dS)z0
        See :func:`.Mock.reset_mock()`
        rN)r�rur�r�rrr�r@r�rrru�szAsyncMockMixin.reset_mock)F)rMrPr�r�r�r�r�r8rIr�r�r�r�r�r�r�ru�
__classcell__rrr�rr�Hs(	
,	r�c@seZdZdZdS)r	aY
    Enhance :class:`Mock` with features allowing to mock
    an async function.

    The :class:`AsyncMock` object will behave so the object is
    recognized as an async function, and the result of a call is an awaitable:

    >>> mock = AsyncMock()
    >>> iscoroutinefunction(mock)
    True
    >>> inspect.isawaitable(mock())
    True


    The result of ``mock()`` is an async function which will have the outcome
    of ``side_effect`` or ``return_value``:

    - if ``side_effect`` is a function, the async function will return the
      result of that function,
    - if ``side_effect`` is an exception, the async function will raise the
      exception,
    - if ``side_effect`` is an iterable, the async function will return the
      next value of the iterable, however, if the sequence of result is
      exhausted, ``StopIteration`` is raised immediately,
    - if ``side_effect`` is not defined, the async function will return the
      value defined by ``return_value``, hence, by default, the async function
      returns a new :class:`AsyncMock` object.

    If the outcome of ``side_effect`` or ``return_value`` is an async function,
    the mock async function obtained when the mock object is called will be this
    async function itself (and not an async function returning an async
    function).

    The test author can also specify a wrapped object with ``wraps``. In this
    case, the :class:`Mock` object behavior is the same as with an
    :class:`.Mock` object: the wrapped object may have methods
    defined as async function functions.

    Based on Martin Richard's asynctest project.
    NrKrrrrr	�sr	c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�_ANYz2A helper object that compares equal to everything.cCsdSr�r�rAr�rrrr�-	sz_ANY.__eq__cCsdSr�rr�rrrr�0	sz_ANY.__ne__cCsdS)Nz<ANY>rr�rrrr�3	sz
_ANY.__repr__N)rMrPr�rNr�r�r�rrrrr�*	sr�cCs`d|}d}d�dd�|D��}d�dd�|��D��}|r@|}|rX|rP|d7}||7}||S)Nz%s(%%s)r�z, cSsg|]}t|��qSr)�repr)rr�rrrr�=	r!z*_format_call_signature.<locals>.<listcomp>cSsg|]\}}d||f�qS)z%s=%rr)rr�r�rrrr�>	s)r�r�)rrBrCrZformatted_argsZargs_stringZ
kwargs_stringrrrr:	s
�rc@szeZdZdZddd�Zdd	d
�Zdd�ZejZd
d�Z	dd�Z
dd�Zdd�Ze
dd��Ze
dd��Zdd�Zdd�ZdS)r&a�
    A tuple for holding the results of a call to a mock, either in the form
    `(args, kwargs)` or `(name, args, kwargs)`.

    If args or kwargs are empty then a call tuple will compare equal to
    a tuple without those values. This makes comparisons less verbose::

        _Call(('name', (), {})) == ('name',)
        _Call(('name', (1,), {})) == ('name', (1,))
        _Call(((), {'a': 'b'})) == ({'a': 'b'},)

    The `_Call` object provides a useful shortcut for comparing with call::

        _Call(((1, 2), {'a': 3})) == call(1, 2, a=3)
        _Call(('foo', (1, 2), {'a': 3})) == call.foo(1, 2, a=3)

    If the _Call has no name then it will match any name.
    rr�NFTcCs�d}i}t|�}|dkr$|\}}}nr|dkrd|\}	}
t|	t�rX|	}t|
t�rR|
}qb|
}q�|	|
}}n2|dkr�|\}t|t�r�|}nt|t�r�|}n|}|r�t�|||f�St�||||f�S)Nr�r�r�)r�r$r�rZr�)r�r�rr�r%�	from_kallrBrC�_len�first�secondrrrr�_	s.



z
_Call.__new__cCs||_||_||_dSr/)r�r��_mock_from_kall)rAr�rr�r%r�rrrr8	sz_Call.__init__cCs\zt|�}Wnty"tYS0d}t|�dkr>|\}}n
|\}}}t|dd�rpt|dd�rp|j|jkrpdSd}|dkr�di}}n�|dkr�|\}}}n�|dkr�|\}	t|	t�r�|	}i}n"t|	t�r�|	}di}}nd}|	}nV|dk�r4|\}
}t|
t��r(|
}t|t��r|i}}n
d|}}n
|
|}}ndS|�rL||k�rLdS||f||fkS)	Nr�r�r�Frrr�r�)r�rr�r&r�r$rZr�)rAr�Z	len_otherZ	self_nameZ	self_argsZself_kwargsZ
other_nameZ
other_argsZother_kwargsr�r�r�rrrr��	sN



�


z_Call.__eq__cOs<|jdurtd||fdd�S|jd}t|j||f||d�S)Nr�r�r�r��r�r&rrrrr9�	s

z_Call.__call__cCs2|jdurt|dd�Sd|j|f}t||dd�S)NF)rr�z%s.%s)rr�r�r�)rAr�rrrrr��	s
z_Call.__getattr__cCs|tjvrt�t�||�Sr/)rZr]r:�__getattribute__)rAr�rrrr��	s
z_Call.__getattribute__cCs(t|�dkr|\}}n
|\}}}||fS)Nr�)r�rrrr�_get_call_arguments�	s

z_Call._get_call_argumentscCs|��dS�Nr�r�r�rrrrB�	sz
_Call.argscCs|��dS)Nr�rr�rrrrC�	sz_Call.kwargscCs||js&|jpd}|�d�r"d|}|St|�dkr@d}|\}}n0|\}}}|sTd}n|�d�shd|}nd|}t|||�S)Nrr�zcall%sr�zcall.%s)r�r�rr�r)rArrBrCrrrr��	s





z_Call.__repr__cCs4g}|}|dur(|jr |�|�|j}qtt|��S)z�For a call object that represents multiple calls, `call_list`
        returns a list of all the intermediate calls as well as the
        final call.N)r�r�r�rrr�)rAZvalsrMrrr�	call_list�	s
z_Call.call_list)rr�NFT)rNNFT)rMrPr�rNr�r8r�rr�r9r�r�r�r�rBrCr�rrrrrr&L	s&�
 �
5

r&)r�c	Ksht|�rt|�}t|t�}t|�}d|i}|r8d|i}n|durDi}|rT|rTd|d<|�|�t}	t�|�rri}n8|r�|r�td��t	}	n"t
|�s�t}	n|r�|r�t|�s�t}	|�
d|�}|}
|dur�d}
|	f|||
|d	�|��}t|t��rt||�}|�rt|�nt||||�|du�r,|�s,||j|<|�rV|�sVd
|v�rVt||dd|d�|_t|�D�]}t|��rr�q^zt||�}
Wnt�y�Y�q^Yn0d|
i}|�r�d|
i}t|
t��s�t|
||||�}||j|<nn|}t|t��r�|j}t|||�}||d
<t|
��rt	}nt}|f||||d�|��}||j|<t|
||d�t|t��r^t|||��q^|S)aICreate a mock object using another object as a spec. Attributes on the
    mock will use the corresponding attribute on the `spec` object as their
    spec.

    Functions or methods being mocked will have their arguments checked
    to check that they are called with the correct signature.

    If `spec_set` is True then attempting to set attributes that don't exist
    on the spec object will raise an `AttributeError`.

    If a class is used as a spec then the return value of the mock (the
    instance of the class) will have the same spec. You can use a class as the
    spec for an instance object by passing `instance=True`. The returned mock
    will only be callable if instances of the mock are callable.

    `create_autospec` also takes arbitrary keyword arguments that are passed to
    the constructor of the created mock.r�r�NTr�zJInstance can not be True when create_autospec is mocking an async functionrr�)r�r�r�rrvr�)rKrwr�r�)r�rr�r�)rJ)r[r1r$r.rhrr'Zisdatadescriptor�RuntimeErrorr	rXrr`r�r6rir�rLr~rrvr�r�r&r:r�r5�
_must_skiprrS)r�r�rKr�rwrC�is_typeZ
is_async_funcr�rr�r5r�rer�r�rJZchild_klassrrrr
s�




��


�


��
rcCsxt|t�s$|t|di�vrdS|j}|jD]H}|j�|t�}|turFq*t|tt	f�rZdSt|t
�rl|SdSq*|S)z[
    Return whether we should skip the first argument on spec's `entry`
    attribute.
    r]F)r$r1r&r�r\r]r^rrVrWr6)r�r�rrArfrrrr�
s


rc@seZdZddd�ZdS)r�FNcCs(||_||_||_||_||_||_dSr/)r��idsr�r�rKr)rAr�r�r�rrrKrrrr8�
sz_SpecState.__init__)FNNNFr�rrrrr��
s�r�cCs"t|t�rt�|�St�|�SdSr/)r$�bytes�io�BytesIO�StringIO)�	read_datarrr�
_to_stream�
s

rr�cs&t��}|dg���fdd�}��fdd�}��fdd����fdd	����fd
d�}tdur�ddl}ttt|j���tt|j����a|dur�t	d
t
d�}t	td����j_d�j
_d�j_d�j_d�j_|�j_���d<�d�j_|�j_��j_|�j_����fdd�}||_�|_|S)a�
    A helper function to create a mock to replace the use of `open`. It works
    for `open` called directly or used as a context manager.

    The `mock` argument is the mock object to configure. If `None` (the
    default) then a `MagicMock` will be created for you, with the API limited
    to methods or attributes available on standard file handles.

    `read_data` is a string for the `read`, `readline` and `readlines` of the
    file handle to return.  This is an empty string by default.
    Ncs(�jjdur�jjS�dj|i|��Sr)�	readlinesrvra��_state�handlerr�_readlines_side_effect�
sz)mock_open.<locals>._readlines_side_effectcs(�jjdur�jjS�dj|i|��Sr)�readrvrarrr�_read_side_effect�
sz$mock_open.<locals>._read_side_effectc?s(��EdH�dj|i|��VqdSr)�readlinera)�_iter_side_effectrrr�_readline_side_effect�
sz(mock_open.<locals>._readline_side_effectc3s0�jjdur�jjVq�dD]
}|Vq dSr)rrv)�linerrrr�
sz$mock_open.<locals>._iter_side_effectcs �jjdur�jjSt�d�Sr)rrvr�rrrr�_next_side_effect�
sz$mock_open.<locals>._next_side_effectr�open)rr�)r�r�cs6t���d<�jj�dkr2���d<�d�j_tS)Nrr�)rrr}rra)rrrrrr�
reset_datas

zmock_open.<locals>.reset_data)r�	file_spec�_iorYrr��
TextIOWrapper�unionr	rrr�rv�writerrr
r}r�r�)r5rZ
_read_datarrrrrr)rrrrrrr
�
s8"

r
c@s*eZdZdZdd�Zd	dd�Zdd�ZdS)
raW
    A mock intended to be used as a property, or other descriptor, on a class.
    `PropertyMock` provides `__get__` and `__set__` methods so you can specify
    a return value when it is fetched.

    Fetching a `PropertyMock` instance from an object calls the mock, with
    no args. Setting it calls the mock with the value being set.
    cKstfi|��Sr/)r)rArCrrrr�szPropertyMock._get_child_mockNcCs|�Sr/r)rAr)Zobj_typerrrr�szPropertyMock.__get__cCs||�dSr/r)rAr)r�rrrr�!szPropertyMock.__set__)N)rMrPr�rNr�r�r�rrrrrs
rc	Cspd|_t|�D]\}zt||�}Wnty6YqYn0t|t�sDqt|j�|�t�rXq|j	|urt
|�qdS)a�Disable the automatic generation of child mocks.

    Given an input Mock, seals it to ensure no further mocks will be generated
    when accessing an attribute that was not already defined.

    The operation recursively seals the mock passed in, meaning that
    the mock itself, any mocks generated by accessing one of its attributes,
    and all assigned mocks without a name or spec will be sealed.
    TN)r�r�r&r:r$rr~r^r�r�r)r5r�r�rrrr%s



rc@s eZdZdZdd�Zdd�ZdS)r�z8
    Wraps an iterator in an asynchronous iterator.
    cCs&||_ttd�}tj|_||jd<dS)Nr�r+)�iteratorrrr'ZCO_ITERABLE_COROUTINEr�r])rAr r�rrrr8As
z_AsyncIterator.__init__c�s(zt|j�WStyYn0t�dSr/)r�r r�r�r�rrrr�Gs
z_AsyncIterator.__anext__N)rMrPr�rNr8r�rrrrr�=sr�)F)F)NFNNN)FFNN)Nr�)}�__all__r�rdrr'r�r}�builtinsr�typesrrrZ
unittest.utilr�	functoolsrrr�rtr
r�r�r*r.r#r3r7r=rLrGrXr[r`rirdr�r�rr�r�rr�MISSINGrZDELETEDr�r�r�rYrrr�r�r�rr;r8r�r;r�r?rrPrRrSr�r�r�rr�r�r�r�ZmultipleZstopallrbZ
magic_methodsZnumericsr�r�Zinplace�rightZ
_non_defaultsrr�r=Z_sync_async_magicsZ
_async_magicsr>r�rr�r�r�r�r�r�r�r�r�r�rr�rr�r�r	r�rrrZr&rrrr�r1r�r6rrr
rrr�rrrr�<module>s0	



1h4<�
�
2�
N	��	���
	
	�	8+:
�
�
N