HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.10/unittest/test/testmock/__pycache__/testasync.cpython-310.opt-2.pyc
o

�i���@s�ddlZddlZddlZddlZddlZddlmZddlmZmZddlm	Z	ddl
mZmZm
Z
mZmZmZmZmZmZmZdd�ZGdd	�d	�ZGd
d�d�Zdd
�Zdd�Zdd�ZGdd�de�Ze�d�Ze�d�Zedd��Z Gdd�dej!�Z"Gdd�dej!�Z#Gdd�dej!�Z$Gdd�dej!�Z%Gd d!�d!ej!�Z&Gd"d#�d#ej!�Z'Gd$d%�d%e	�Z(Gd&d'�d'ej!�Z)Gd(d)�d)ej!�Z*Gd*d+�d+ej!�Z+Gd,d-�d-ej!�Z,ed.kr�e�-�dSdS)/�N)�contextmanager)�run�iscoroutinefunction)�IsolatedAsyncioTestCase)
�ANY�call�	AsyncMock�patch�	MagicMock�Mock�create_autospec�sentinel�	_CallList�sealcCst�d�dS�N)�asyncioZset_event_loop_policy�rr�=/usr/local/lib/python3.10/unittest/test/testmock/testasync.py�tearDownModule�rc@s<eZdZdd�Zdd�Zdd�Zedd��Zed	d
��Z	dS)�
AsyncClasscC�dSrr��selfrrr�__init__�zAsyncClass.__init__c���dSrrrrrr�async_method��zAsyncClass.async_methodcCrrrrrrr�
normal_methodrzAsyncClass.normal_methodc�rrr)�clsrrr�async_class_method��zAsyncClass.async_class_methodc�rrrrrrr�async_static_methodr"zAsyncClass.async_static_methodN)
�__name__�
__module__�__qualname__rrr�classmethodr!�staticmethodr#rrrrrs
rc@�eZdZdd�ZdS)�AwaitableClassccs�dVdSrrrrrr�	__await__s�
zAwaitableClass.__await__N)r$r%r&r+rrrrr*�r*c�rrrrrrr�
async_func!rr-c�rrr)�a�b�crrr�async_func_args#rr1cCrrrrrrr�normal_func%rr2c@r))�NormalClasscCrrrrrrrr.(rz
NormalClass.aN)r$r%r&r.rrrrr3'r,r3z.AsyncClassz.NormalClassccsB�|�td��dVt��Wd�dS1swYdS)Nzwas never awaited$)ZassertWarnsRegex�RuntimeWarning�gcZcollect)�testrrr�assertNeverAwaited/s
�
"�r7c@�<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�AsyncPatchDecoratorTestc�"t�td��fdd��}|�dS)Nrcs��t|��dSr)�
assertTruer��mock_methodrrr�
test_async:�zLAsyncPatchDecoratorTest.test_is_coroutine_function_patch.<locals>.test_async�r	�objectr�rr>rrr� test_is_coroutine_function_patch9s

z8AsyncPatchDecoratorTest.test_is_coroutine_function_patchcsBt�td��fdd��}tt�d���fdd��}|�|�dS)Nrc�"|�}��t�|��t|�dSr�r;�inspect�isawaitabler�r=�mrrrr>@�z?AsyncPatchDecoratorTest.test_is_async_patch.<locals>.test_asyncz
.async_methodcrDrrErHrrr�test_no_parent_attributeFrJzMAsyncPatchDecoratorTest.test_is_async_patch.<locals>.test_no_parent_attribute)r	rAr�async_foo_name)rr>rKrrr�test_is_async_patch?s

z+AsyncPatchDecoratorTest.test_is_async_patchcr:)Nrc���|t�dSr��assertIsInstancerr<rrrr>P�zCAsyncPatchDecoratorTest.test_is_AsyncMock_patch.<locals>.test_asyncr@rBrrr�test_is_AsyncMock_patchO�

z/AsyncPatchDecoratorTest.test_is_AsyncMock_patchcr:)Nr#crNrrOr<rrrr>WrQzPAsyncPatchDecoratorTest.test_is_AsyncMock_patch_staticmethod.<locals>.test_asyncr@rBrrr�$test_is_AsyncMock_patch_staticmethodVrSz<AsyncPatchDecoratorTest.test_is_AsyncMock_patch_staticmethodcr:)Nr!crNrrOr<rrrr>^rQzOAsyncPatchDecoratorTest.test_is_AsyncMock_patch_classmethod.<locals>.test_asyncr@rBrrr�#test_is_AsyncMock_patch_classmethod]rSz;AsyncPatchDecoratorTest.test_is_AsyncMock_patch_classmethodcsNtt�d�dd�tt�d�dd��fdd���}t|����t�t��dS)N�.async_func���return_value�.async_func_args�c�sj���|jd���|jd���tt���tt���t�IdHd���tdddd�IdHd�dS)Nr1r-rWr[��r0)�assertEqualZ
_mock_namerPr-rr1)Zfunc_args_mockZ	func_mockrrrr>es� z@AsyncPatchDecoratorTest.test_async_def_patch.<locals>.test_async)r	r$rr;rFrr-rBrrr�test_async_def_patchds


z,AsyncPatchDecoratorTest.test_async_def_patchN)	r$r%r&rCrMrRrTrUr_rrrrr98sr9c@r8)�AsyncPatchCMTestc��fdd�}|�dS)Ncs@t�td��}��t|��Wd�dS1swYdS�Nr)r	rArr;rr<rrrr>ws"�z>AsyncPatchCMTest.test_is_async_function_cm.<locals>.test_asyncrrBrrr�test_is_async_function_cmv�
z*AsyncPatchCMTest.test_is_async_function_cmcra)NcsPt�td��}|�}��t�|��t|�Wd�dS1s!wYdSrb)r	rArr;rFrGrrHrrrr>~s

"�z5AsyncPatchCMTest.test_is_async_cm.<locals>.test_asyncrrBrrr�test_is_async_cm}s
z!AsyncPatchCMTest.test_is_async_cmcra)Ncs>t�td��}��|t�Wd�dS1swYdSrb)r	rArrPrr<rrrr>�s"�z9AsyncPatchCMTest.test_is_AsyncMock_cm.<locals>.test_asyncrrBrrr�test_is_AsyncMock_cm�rdz%AsyncPatchCMTest.test_is_AsyncMock_cmc��fdd�}t|��dS)Nc�sT�tt�d�t�����tt�Wd�n1swY��t�t��dS)NrV)r	r$rrPr-r;rFrrrrrr>�s
��z6AsyncPatchCMTest.test_async_def_cm.<locals>.test_async�rrBrrr�test_async_def_cm�sz"AsyncPatchCMTest.test_async_def_cmcsBddi�t��ddi���fdd��}��t|��t|��dS)Nr.r/c�s����dd�dS�Nr.r/)r^r��foorrrr>�s�z>AsyncPatchCMTest.test_patch_dict_async_def.<locals>.test_async)r	�dictr;rrrBrrkr�test_patch_dict_async_def�s
z*AsyncPatchCMTest.test_patch_dict_async_defcs$ddi���fdd�}t|��dS)Nr.c�sH�t��ddi�����dd�Wd�dS1swYdSrj)r	rmr^rrkrrr>�s�"�zFAsyncPatchCMTest.test_patch_dict_async_def_context.<locals>.test_asyncrhrBrrkr�!test_patch_dict_async_def_context�sz2AsyncPatchCMTest.test_patch_dict_async_def_contextN)	r$r%r&rcrerfrirnrorrrrr`us		r`c@�4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
AsyncMockTestcCst�}|�t|��dSr)rr;r�r�mockrrr� test_iscoroutinefunction_default�sz.AsyncMockTest.test_iscoroutinefunction_defaultcC�2dd�}t|�}|�t|��|�t�|��dS)Nc�rrrrrrrrl�rz<AsyncMockTest.test_iscoroutinefunction_function.<locals>.foo�rr;rrF�rrlrsrrr�!test_iscoroutinefunction_function��z/AsyncMockTest.test_iscoroutinefunction_functioncCs8t�}|�}|�t�|��t|�|�dt|��dS)N�assert_awaited)rr;rFrGrZassertIn�dir�rrsrIrrr�test_isawaitable�s
zAsyncMockTest.test_isawaitablecCru)NcSrrrrrrrrl�rzCAsyncMockTest.test_iscoroutinefunction_normal_function.<locals>.foorvrwrrr�(test_iscoroutinefunction_normal_function�ryz6AsyncMockTest.test_iscoroutinefunction_normal_functioncCsDt��}t�|�t��}|��|��t|�}|�|tj�dSr)rZnew_event_loopZset_event_loop�Future�stop�closerrP)rZloop�futrsrrr�test_future_isfuture�s
z"AsyncMockTest.test_future_isfutureN)r$r%r&rtrxr}r~r�rrrrrq�srqc@s>eZdZdd�Zdd�Ze�d�dd��Zdd	�Zd
d�Z	dS)
�AsyncAutospecTestcs@ttdd��fdd��}ttdd��fdd��}|�|�dS)NT�Zautospecc���|jt���|t�dSr�rPrrr
r<rrrr>��z=AsyncAutospecTest.test_is_AsyncMock_patch.<locals>.test_asynccs��|jt�dSr)rPrr
r<rrr�test_normal_method�r?zEAsyncAutospecTest.test_is_AsyncMock_patch.<locals>.test_normal_method�r	rL)rr>r�rrrrR�s


z)AsyncAutospecTest.test_is_AsyncMock_patchcCs<|�t��ttdd�Wd�dS1swYdS)NT)�instance)�assertRaises�RuntimeErrorrr-rrrr�test_create_autospec_instance�s"�z/AsyncAutospecTest.test_create_autospec_instancez3Broken test from https://bugs.python.org/issue37251cCs|�tt�t�dSr)rPrr*rrrrr�$test_create_autospec_awaitable_class�sz6AsyncAutospecTest.test_create_autospec_awaitable_classcs&tt�}|dddd���fdd�}|�|jd�|�|j�|�|jg�|��t|��|�	t
|��|�	t����|�|jd�|�|jt
dddd��|�|jt
dddd�g�|��|jdddd�|jdddd�|��|�t��|jdd�Wd�dS1s�wYdS)	NrWr[r\r]c�s��IdHdSrrr��	awaitablerr�main�s�z4AsyncAutospecTest.test_create_autospec.<locals>.mainr)�e)rr1r^�await_count�assertIsNone�
await_args�await_args_list�assert_not_awaitedrr;rr�iscoroutiner�assert_awaited_once�assert_awaited_once_with�assert_awaited_withrzr��AssertionError�assert_any_await)r�specr�rr�r�test_create_autospec�s(
"�z&AsyncAutospecTest.test_create_autospeccrg)Nc�s\�tt�d�dd��J}|dddd�}��|jt���t|����t�|����t	�
|����|jd���|j
g���|j�|��|IdHWd�n1sWwY��|jd���|jtdddd����|j
tdddd�g�|��|jdddd�|jdddd�|��|����|jd���|j���|j
g�dS)	NrZTr�rWr[r\r]r)r	r$rPrsrr;rrr�rFrGr^r�r�r�r�r�rr�r�r�rz�
reset_mock)r=r�rrrr>�s0��z>AsyncAutospecTest.test_patch_with_autospec.<locals>.test_asyncrhrBrrr�test_patch_with_autospec�sz*AsyncAutospecTest.test_patch_with_autospecN)
r$r%r&rRr��unittest�skipr�r�r�rrrrr��s

r�c@sleZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�
AsyncSpecTestc	�V�fdd�}ttfD]}��d|����||�Wd�n1s#wYq
dS)Ncs(|t�}��|jt���|jt�dSr)rrPrrrr
)�	mock_typersrrr�
inner_test�zCAsyncSpecTest.test_spec_normal_methods_on_class.<locals>.inner_testztest method types with �rr
�subTest�rr�r�rrr�!test_spec_normal_methods_on_classs
���z/AsyncSpecTest.test_spec_normal_methods_on_classcCs(tt�}|�|jt�|�|jt�dSr)rrrPrrrrrrrr�+test_spec_normal_methods_on_class_with_mock(r�z9AsyncSpecTest.test_spec_normal_methods_on_class_with_mockcCsvtt�}t|�|�t��|jWd�n1swY|�t��|jWd�dS1s4wYdSr)rrrr��AttributeErrorrrrrrrr�0test_spec_normal_methods_on_class_with_mock_seal-s�"�z>AsyncSpecTest.test_spec_normal_methods_on_class_with_mock_sealc	�X�fdd�}tttfD]}��d|����||�Wd�n1s$wYqdS)Ncsj|td�}��||�t�����t�|���Wd�n1s#wY|td�}��||�dS�N�r��r-rPr7r;rFrGr2�r��
async_mockZ	sync_mockrrrr�6s

�
z8AsyncSpecTest.test_spec_mock_type_kw.<locals>.inner_testztest spec kwarg with �rr
rr�r�rrr�test_spec_mock_type_kw5�	
���z$AsyncSpecTest.test_spec_mock_type_kwc	r�)Ncsf|t�}��||�t�����t�|���Wd�n1s"wY|t�}��||�dSrr�r�rrrr�Ds
�z@AsyncSpecTest.test_spec_mock_type_positional.<locals>.inner_testztest spec positional with r�r�rrr�test_spec_mock_type_positionalCr�z,AsyncSpecTest.test_spec_mock_type_positionalcCs8ttd�}|�|t�|�}|�t�|��t|�dSr��rr2rPr;rFrGrr|rrr� test_spec_as_normal_kw_AsyncMockQs

z.AsyncSpecTest.test_spec_as_normal_kw_AsyncMockcCs6tt�}|�|t�|�}|�t�|��t|�dSrr�r|rrr�(test_spec_as_normal_positional_AsyncMockXs
z6AsyncSpecTest.test_spec_as_normal_positional_AsyncMockc�&tjtddd��fdd��}|�dS)NrTr�crNrrOr<rrrr>`rQz6AsyncSpecTest.test_spec_async_mock.<locals>.test_asyncr@rBrrr�test_spec_async_mock_s
z"AsyncSpecTest.test_spec_async_mockcs"ttdd��fdd��}|�dS)NTr�cs��|t���|jt�dSr)rPr
rrr<rrrr>gszIAsyncSpecTest.test_spec_parent_not_async_attribute_is.<locals>.test_asyncr�rBrrr�'test_spec_parent_not_async_attribute_isf�

z5AsyncSpecTest.test_spec_parent_not_async_attribute_iscs(tjtdtjd��fdd��}|�dS)Nrr�cs0��|t���t�|����t�|��dSr)rPr
�assertFalserFr�rGr<rrr�test_async_attributeoszFAsyncSpecTest.test_target_async_spec_not.<locals>.test_async_attribute)r	rArr3r.)rr�rrr�test_target_async_spec_notns
z(AsyncSpecTest.test_target_async_spec_notcs&tjtdtd��fdd��}|�dS)Nr.r�crNrrO)Zmock_async_funcrrr� test_attribute_not_async_spec_isxrQzUAsyncSpecTest.test_target_not_async_spec_is.<locals>.test_attribute_not_async_spec_is)r	rAr3r-)rr�rrr�test_target_not_async_spec_isw�
z+AsyncSpecTest.test_target_not_async_spec_iscs"tttd��fdd��}|�dS)Nr�cr�rr�)ZMockNormalClassrrr� test_async_attributes_coroutines~r�zRAsyncSpecTest.test_spec_async_attributes.<locals>.test_async_attributes_coroutines)r	�normal_foo_namer)rr�rrr�test_spec_async_attributes}r�z(AsyncSpecTest.test_spec_async_attributesN)r$r%r&r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�s
	r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�AsyncSpecSetTestcr�)NrT�Zspec_setcrNrrO)rrrrr>�rQz<AsyncSpecSetTest.test_is_AsyncMock_patch.<locals>.test_asyncr@rBrrrrR�r�z(AsyncSpecSetTest.test_is_AsyncMock_patchcCs*ttjd�}|�t|��|�|t�dS�Nr�)rrrr;rrPrrrrr�test_is_async_AsyncMock�sz(AsyncSpecSetTest.test_is_async_AsyncMockcCsVttd�}|�t|j��|�t|j��|�|jt�|�|jt�|�|t�dSr�)	r
rr;rrr�rrPrrrrrr�test_is_child_AsyncMock�s
z(AsyncSpecSetTest.test_is_child_AsyncMockcCsTt�}tdd�d�|_t�|d��}|�|t�Wd�dS1s#wYdS)NcSs|Srr��xrrr�<lambda>�rz=AsyncSpecSetTest.test_magicmock_lambda_spec.<locals>.<lambda>r��	mock_func)r
r�r	rArP)rZmock_obj�cmrrr�test_magicmock_lambda_spec�s
"�z+AsyncSpecSetTest.test_magicmock_lambda_specN)r$r%r&rRr�r�r�rrrrr��s
r�c@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�AsyncArgumentsc�s4�dd�}t|dd�}|d�IdH}|�|d�dS)Nc�rrr)r�varrrr�addition�rz6AsyncArguments.test_add_return_value.<locals>.addition�
rX��rr^)rr�rs�outputrrr�test_add_return_value�s
�z$AsyncArguments.test_add_return_valuec�sX�dd�}t|td�d�}|�t��|d�IdHWd�dS1s%wYdS)Nc�rrr�r�rrrr��rz?AsyncArguments.test_add_side_effect_exception.<locals>.addition�err�Zside_effectr�)r�	Exceptionr�)rr�rsrrr�test_add_side_effect_exception�s�"�z-AsyncArguments.test_add_side_effect_exceptionc��2�dd�}t|d�}|d�IdH}|�|d�dS)Nc�s
�|dS�NrWrr�rrrr��s�z?AsyncArguments.test_add_side_effect_coroutine.<locals>.additionr�r��r��rr�rs�resultrrr�test_add_side_effect_coroutine��
�
z-AsyncArguments.test_add_side_effect_coroutinec�r�)NcSs|dSr�rr�rrrr��szEAsyncArguments.test_add_side_effect_normal_function.<locals>.additionr�r�r�r�r�rrr�$test_add_side_effect_normal_function�r�z3AsyncArguments.test_add_side_effect_normal_functionc�sn�gd�}t|d�}|D]}|�|�IdH|�q|�t��}|�IdHWd�dS1s0wYdS)N�rWr[r\r�)rr^r��StopAsyncIteration)r�valsrs�itemr�rrr�test_add_side_effect_iterable�s�
"�z,AsyncArguments.test_add_side_effect_iterablec�sx�Gdd�dt�}d|d�g}t|d�}|�|�IdHd�|�|��}|�IdHWd�dS1s5wYdS)Nc@seZdZdS)zOAsyncArguments.test_add_side_effect_exception_iterable.<locals>.SampleExceptionN)r$r%r&rrrr�SampleException�sr�rWrlr�)r�rr^r�)rr�r�rsr�rrr�'test_add_side_effect_exception_iterable�s�
"�z6AsyncArguments.test_add_side_effect_exception_iterablec�s2�tdd�}t|d�}|�IdH}|�||�dS)Nr�rX)r�assertIs)r�valuersr�rrr�test_return_value_AsyncMock�s
�

z*AsyncArguments.test_return_value_AsyncMockc�s<�t��}|�d�t|d�}|�IdH}|�|tj�dS)NrX)rr�
set_resultrrP�rr�rsr�rrr�test_return_value_awaitable�s�

z*AsyncArguments.test_return_value_awaitablec�sv�t��}|�d�t|gd�}|�IdH}|�|tj�|�t��|�IdHWd�dS1s4wYdS)Nr�)rrr�rrPr�r�r�rrr�!test_side_effect_awaitable_values�s�
"�z0AsyncArguments.test_side_effect_awaitable_valuesc�s2�tdd�}t|d�}|�IdH}|�|d�dS)Nr�rXr�r�)rZeffectrsr�rrr�test_side_effect_is_AsyncMock�s
�

z,AsyncArguments.test_side_effect_is_AsyncMockc�sT�t���d���fdd�}t|d�}|�IdH}|�|��|��|���dS)NFc�s
�d��S�NTrr�Zranr�rr�inner�s�z2AsyncArguments.test_wraps_coroutine.<locals>.inner��wraps)rrrr^rzr;�rr�rsr�rr�r�test_wraps_coroutine�s�
z#AsyncArguments.test_wraps_coroutinec�sP�d�d���fdd�}t|d�}|�IdH}|�|��|��|���dS)NrWFcsd��Sr�rrr�rrr�sz8AsyncArguments.test_wraps_normal_function.<locals>.innerr�)rr^rzr;r�rr�r�test_wraps_normal_functions�
z)AsyncArguments.test_wraps_normal_functionc�sz�t�}|d�}|d�}|IdH|IdH|�td�td�g�|�|jtd�td�g�|�|jtd�td�g�dS)Nr[rW)r�assert_has_awaitsrr^r��call_args_list)rr�Zmock2Zmock1rrr�test_await_args_list_orders�

z)AsyncArguments.test_await_args_list_orderN)r$r%r&r�r�r�r�r�r�r�r�r�r�rrrrrrrr��s	r�c@rp)�AsyncMagicMethodscCsBt�}|�|jt�|�|jt�|�|jt�|�|jt�dSr)r
rP�
__aenter__r�	__aexit__�	__anext__�	__aiter__�rZm_mockrrr�+test_async_magic_methods_return_async_mockss
z=AsyncMagicMethods.test_async_magic_methods_return_async_mockscCsBt�}|�|jt�|�|jt�|�|jt�|�|jt�dSr)rrP�	__enter__r
�__exit__�__next__�__len__�r�a_mockrrr�*test_sync_magic_methods_return_magic_mocks%s
z<AsyncMagicMethods.test_sync_magic_methods_return_magic_mockscCs:t�}|�t|d��|�t|d��|�t|d��dS)Nrrr)r
r;�hasattrr
rrr�&test_magicmock_has_async_magic_methods,sz8AsyncMagicMethods.test_magicmock_has_async_magic_methodscCsJt�}|�t|d��|�t|d��|�t|d��|�t|d��dS)Nrr
rr)rr;rrrrr�%test_asyncmock_has_sync_magic_methods2s
z7AsyncMagicMethods.test_asyncmock_has_sync_magic_methodscCsFt�}|�|jt�|�|jt�|�t|j��|�t|j��dSr)r
rPrrrr;rr
rrr�&test_magic_methods_are_async_functions9s
z8AsyncMagicMethods.test_magic_methods_are_async_functionsN)r$r%r&rrrrrrrrrrs	rc@s^eZdZGdd�d�ZGdd�d�ZGdd�d�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�AsyncContextManagerTestc@�eZdZdd�Zdd�ZdS)z/AsyncContextManagerTest.WithAsyncContextManagerc�rrr�r�args�kwargsrrrrDrz:AsyncContextManagerTest.WithAsyncContextManager.__aenter__c�rrrrrrrrFrz9AsyncContextManagerTest.WithAsyncContextManager.__aexit__N)r$r%r&rrrrrr�WithAsyncContextManagerC�rc@r)z.AsyncContextManagerTest.WithSyncContextManagercOrrrrrrrrIrz8AsyncContextManagerTest.WithSyncContextManager.__enter__cOrrrrrrrr
Krz7AsyncContextManagerTest.WithSyncContextManager.__exit__N)r$r%r&rr
rrrr�WithSyncContextManagerHrrc@r)z&AsyncContextManagerTest.ProductionCodecCs
d|_dSr)�sessionrrrrrOs
z/AsyncContextManagerTest.ProductionCode.__init__c	�sX�|j�d�4IdH�}|��IdH}|Wd�IdHS1IdHs%wYdS)Nzhttps://python.org)r�post�json)r�response�valrrrr�Rs
�0�z+AsyncContextManagerTest.ProductionCode.mainN)r$r%r&rr�rrrr�ProductionCodeMsr$c	r�)Ncsj���}tdd�|_|dd�}tdd�}tddid�|_||j_||jj_t|�	��}��
|ddi�dS)NZsessionmock��nameZmagic_cmr"r!�{rX)r$r
rrr!rrYr rr�r^)r�Zpcr�r"r�rrrr�Xs


zKAsyncContextManagerTest.test_set_return_value_of_aenter.<locals>.inner_testz%test set return value of aenter with r�r�rrr�test_set_return_value_of_aenterW�
���z7AsyncContextManagerTest.test_set_return_value_of_aenterc	r�)Ncsvd����}||����fdd�}t|��}�������jj����jj��j���j�����|�dS)NFc	�sD��4IdH�}d�Wd�IdH|S1IdHswY|Sr�r�r���calledZcm_mockrr�use_context_managerms���zqAsyncContextManagerTest.test_mock_supports_async_context_manager.<locals>.inner_test.<locals>.use_context_manager)rrr;rr,rrzZassertIsNot)r�r�r-Z	cm_resultrr+rr�hs



zTAsyncContextManagerTest.test_mock_supports_async_context_manager.<locals>.inner_testz!test context manager magics with r�r�rrr�(test_mock_supports_async_context_managergs
���z@AsyncContextManagerTest.test_mock_supports_async_context_managercs@|��}t|��t�}|�j_�fdd�}|�t|��|�dS)Nc	�sB��4IdH�
}|Wd�IdHS1IdHswYdSrrr*��
mock_instancerrr-�s�0�z^AsyncContextManagerTest.test_mock_customize_async_context_manager.<locals>.use_context_manager)rr
rArrYr�r)rr�Zexpected_resultr-rr/r�)test_mock_customize_async_context_manager�szAAsyncContextManagerTest.test_mock_customize_async_context_managercsjd�d��fdd�}�fdd�}|��}t|��|�_|�_�fdd�}t|��|���|���dS)NFc��
�d�dSr�r�r)�enter_calledrr�enter_coroutine���ziAsyncContextManagerTest.test_mock_customize_async_context_manager_with_coroutine.<locals>.enter_coroutinec�r2r�rr3)�exit_calledrr�exit_coroutine�r6zhAsyncContextManagerTest.test_mock_customize_async_context_manager_with_coroutine.<locals>.exit_coroutinec	�s@��4IdH�Wd�IdHdS1IdHswYdSrrrr/rrr-�s�.�zmAsyncContextManagerTest.test_mock_customize_async_context_manager_with_coroutine.<locals>.use_context_manager)rr
rrrr;)rr5r8r�r-r)r4r7r0r�8test_mock_customize_async_context_manager_with_coroutine�s

zPAsyncContextManagerTest.test_mock_customize_async_context_manager_with_coroutinecCsTdd�}|��}t|�}|�t��t||��Wd�dS1s#wYdS)Nc	�s0�|4IdH�t��1IdHswYdSr)�	TypeError)Zcontext_managerrrr�raise_in�s��zYAsyncContextManagerTest.test_context_manager_raise_exception_by_default.<locals>.raise_in)rr
r�r:r)rr;r�r0rrr�/test_context_manager_raise_exception_by_default�s"�zGAsyncContextManagerTest.test_context_manager_raise_exception_by_defaultN)r$r%r&rrr$r(r.r1r9r<rrrrrAs

rc@s4eZdZGdd�de�Zdd�Zdd�Zdd�Zd	S)
�AsyncIteratorTestc@s$eZdZdd�Zdd�Zdd�ZdS)z#AsyncIteratorTest.WithAsyncIteratorcCsgd�|_dS)N)rlZ	NormalFoo�baz)�itemsrrrrr�rz,AsyncIteratorTest.WithAsyncIterator.__init__cCrrrrrrrr	�rz-AsyncIteratorTest.WithAsyncIterator.__aiter__c�rrrrrrrr�rz-AsyncIteratorTest.WithAsyncIterator.__anext__N)r$r%r&rr	rrrrr�WithAsyncIterator�sr@cs@tdd��gd��j_�fdd�}t|��}|�|gd��dS)NZtesterr%r�c�s�dd��2�IdHS)Nc�s�g|z3dHW}|�q6Srr)�.0�irrr�
<listcomp>�s�zOAsyncIteratorTest.test_aiter_set_return_value.<locals>.main.<locals>.<listcomp>rr�Z	mock_iterrrr��s�z;AsyncIteratorTest.test_aiter_set_return_value.<locals>.main)rr	rYrr^)rr�r�rrDr�test_aiter_set_return_value�s


z-AsyncIteratorTest.test_aiter_set_return_valuec	r�)NcsT���}||�}��t|j����t|j����t|j����t|j��dSr)r@r�rr	r;r)r�r�r0rrrr��szIAsyncIteratorTest.test_mock_aiter_and_anext_asyncmock.<locals>.inner_testz%test aiter and anext corourtine with r�r�rrr�#test_mock_aiter_and_anext_asyncmock�r)z5AsyncIteratorTest.test_mock_aiter_and_anext_asyncmockc	s�dd��gd����fdd�}���fdd�}���fdd	�}ttfD]V}��d
|����||�Wd�n1s<wY��d|����||�Wd�n1sXwY��d|����||�Wd�n1stwYq#dS)
Nc�s(�g}|2z3dHW}|�|�q6|Sr)�append)�iteratorZaccumulatorr�rrr�iterate�s��z6AsyncIteratorTest.test_mock_async_for.<locals>.iterate)ZFOOZBARZBAZcs$|����}��t�|��g�dSr)r@r^r�r�r0)rIrrr�test_default�sz;AsyncIteratorTest.test_mock_async_for.<locals>.test_defaultcs4|����}�dd�|j_��t�|����dSr)r@r	rYr^rrJ�ZexpectedrIrrr�test_set_return_value�szDAsyncIteratorTest.test_mock_async_for.<locals>.test_set_return_valuecs8|����}t�dd��|j_��t�|����dSr)r@�iterr	rYr^rrJrLrr�test_set_return_value_iter�szIAsyncIteratorTest.test_mock_async_for.<locals>.test_set_return_value_iterzdefault value with zset return_value with zset return_value iterator with r�)rrKrMrOr�rrLr�test_mock_async_for�s"
�
�
���z%AsyncIteratorTest.test_mock_async_forN)r$r%r&rAr@rErFrPrrrrr=�s
r=c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3S)4�AsyncMockAssertcCst�|_dSr)rrsrrrr�setUp�szAsyncMockAssert.setUpc�s�|j|i|��IdHdSr)rsrrrr�_runnable_test�s�zAsyncMockAssert._runnable_testc�s�|IdHSrr)r�	coroutinerrr�_await_coroutine�s�
z AsyncMockAssert._await_coroutinecCs�tt�}t|��|��Wd�n1swY|�t|j��|j��|j��|j��|�	t
��|��Wd�n1sGwY|�	t
��|j��Wd�dS1sbwYdSr)rrr7rr;r�
assert_called�assert_called_once�assert_called_once_withr�r�rzrrrrr�"test_assert_called_but_not_awaiteds

�



�"�z2AsyncMockAssert.test_assert_called_but_not_awaitedcCs�tt�}|��}|j��|j��|j��|�t��
|j��Wd�n1s,wYt	|�
|��|j��|j��|j��|j��dSr)
rrrrVrWrXr�r�rzrrUr�r�)rrsZmock_coroutinerrr�test_assert_called_then_awaiteds


�


z/AsyncMockAssert.test_assert_called_then_awaitedcCs�|�t��
|j��Wd�n1swY|�t��
|j��Wd�n1s/wYt|���|j��|j��dSr)	r�r�rsrzrVrrSrWr�rrrr�+test_assert_called_and_awaited_at_same_times��
z;AsyncMockAssert.test_assert_called_and_awaited_at_same_timecCs�tt�}|��}t|��|��Wd�n1swY|�t��
|j��Wd�n1s5wY|j��t|�	|��|j��|j�
�dSr)rrrr7r�r�rzrVrrUr��rrsrTrrr�)test_assert_called_twice_and_awaited_once*s

��

z9AsyncMockAssert.test_assert_called_twice_and_awaited_oncecCsntt�}|��}|j��t|�|��|�t��t|�|��Wd�n1s+wY|j��dSr)	rrrrWrrUr�r�rzr\rrr�)test_assert_called_once_and_awaited_twice8s
�z9AsyncMockAssert.test_assert_called_once_and_awaited_twicecCs|�t��
|j��Wd�n1swY|�t��
|j��Wd�n1s/wY|�t��t|�|j��Wd�n1sLwY|�t��
|j��Wd�n1sfwY|�t��|j��Wd�dS1s�wYdSr)r�r�rsrzrVr:rrUrrrr�"test_assert_awaited_but_not_calledBs����"�z2AsyncMockAssert.test_assert_awaited_but_not_calledcCs�td�g}t|��
|�d�Wd�n1swY|j�|�|�t��|j�|�Wd�dS1s;wYdS�Nrl)rr7rsZassert_has_callsr�r�r)rZkallsrrr� test_assert_has_calls_not_awaitsPs

�"�z0AsyncMockAssert.test_assert_has_calls_not_awaitscCs�t|��|��Wd�n1swYddifg}|�|jj|�t|��
|�d�Wd�n1s:wYt|��
|�d�Wd�n1sSwYt�td�td�g}|�|jj|�dS)N�rrlr>)r7rsr^�
mock_callsr)r�kalls_empty�
mock_kallsrrr�0test_assert_has_mock_calls_on_async_mock_no_specXs

�
�
�z@AsyncMockAssert.test_assert_has_mock_calls_on_async_mock_no_speccCs�tt�}t|��|��Wd�n1swYddifg}|�|jj|�|�|jt��g�t|��|jdddddd�Wd�n1sMwYt�tdddddd�g}t��tjdddddd�g}|�|jj|�|�|j|�dS)	NrbrrWr[r\�r�)r.r/)rrr7rr^rcr)rZa_class_mockrdZmethod_kallsrerrr�2test_assert_has_mock_calls_on_async_mock_with_speces

�
�zBAsyncMockAssert.test_assert_has_mock_calls_on_async_mock_with_speccCs�t|��|jjddd�Wd�n1swYt|��|jjjdtjd�Wd�n1s5wY|�|jjddddifdd	d
tjifgd�|�|jjjdd	d
tjifgd�dS)Nr\)�fishr�)�cake�	something)r\rizsomething_else.something)r�rjz#method calls not recorded correctly)r7rsrkZsomething_elser
ZCaker^�method_callsrrrr� test_async_method_calls_recordedts 
�
�
���z0AsyncMockAssert.test_async_method_calls_recordedcsD�fdd�}|�j�t������Wd�n1swYt�����dd�Wd�n1s8wYt����jdd�Wd�n1sRwY�j��|�j�tt�}t���|��Wd�n1sxwYt���|jddd�Wd�n1s�wY|��||�dS)Ncs@d}|D]}t||�}��|t���|t���|g�qdS)N)rrlrc)�getattrrPr�listr^)rs�namesr&�attrrrr�assert_attrs�s
�z:AsyncMockAssert.test_async_arg_lists.<locals>.assert_attrsrWr[r\)r.)rsr7r�rrr)rrrrrrr�test_async_arg_lists�s,


�
�
�



�
�z$AsyncMockAssert.test_async_arg_listscCsN|�t��
|j��Wd�n1swYt|���|j��dSr)r�r�rsrzrrSrrrr�test_assert_awaited�s
�z#AsyncMockAssert.test_assert_awaitedcCs�|�t��
|j��Wd�n1swYt|���|j��t|���|�t��|j��Wd�dS1sAwYdSr)r�r�rsr�rrSrrrr�test_assert_awaited_once�s�
"�z(AsyncMockAssert.test_assert_awaited_oncecCs�d}|�t|��|j�d�Wd�n1swYt|���d}|�t|��|j�d�Wd�n1s=wYt|�d��|j�d�t|�d��|�t��|j�d�Wd�dS1smwYdS)NzNot awaitedrlzexpected await not found�
SomethingElse)�assertRaisesRegexr�rsr�rrSr�)r�msgrrr�test_assert_awaited_with�s��"�z(AsyncMockAssert.test_assert_awaited_withcCs�|�t��|j�d�Wd�n1swYt|�d��|j�d�t|�d��|�t��|j�d�Wd�dS1sFwYdSr`)r�r�rsr�rrSrrrr�test_assert_awaited_once_with�s�"�z-AsyncMockAssert.test_assert_awaited_once_withcCs�|�t��|j�d�Wd�n1swYt|�d��|�t��|j�d�Wd�n1s8wYt|�d��|j�d�t|�d��|j�d�dS)Nrlr>rv)r�r�rsr�rrSrrrr�test_assert_any_wait�s��z$AsyncMockAssert.test_assert_any_waitcCstd�td�g}|�t��}|j�|�Wd�n1swY|�t|jj�d�t	|�
d��|�t��|j�|�Wd�n1sJwYt	|�
d��|�t��|j�|�Wd�n1slwYt	|�
d��|j�|�t	|�
d��|j�|�dS)Nrlr>rWrv)rr�r�rsrr^�len�	exceptionrrrS)r�callsr�rrr�test_assert_has_awaits_no_order�s"���z/AsyncMockAssert.test_assert_has_awaits_no_ordercCsTGdd�d�}t|�|�d��|j�ttd�g�|j�td�|j�td�dS)Nc@r))z9AsyncMockAssert.test_awaits_asserts_with_any.<locals>.FoocSrrr�r�otherrrr�__eq__�rz@AsyncMockAssert.test_awaits_asserts_with_any.<locals>.Foo.__eq__N�r$r%r&r�rrrr�Foo�r,r�rW)rrSrsrrrr�r�)rr�rrr�test_awaits_asserts_with_any�s
z,AsyncMockAssert.test_awaits_asserts_with_anycsbGdd�d�}t|d���fdd�}t||�d����ttd�g���td���td�dS)Nc@r))zBAsyncMockAssert.test_awaits_asserts_with_spec_and_any.<locals>.FoocSrrrr�rrrr��rzIAsyncMockAssert.test_awaits_asserts_with_spec_and_any.<locals>.Foo.__eq__Nr�rrrrr��r,r�r�c�s��|�IdHdSrrr3�Zmock_with_specrr�_custom_mock_runnable_tests�zYAsyncMockAssert.test_awaits_asserts_with_spec_and_any.<locals>._custom_mock_runnable_testrW)rrrrrr�r�)rr�r�rr�r�%test_awaits_asserts_with_spec_and_any�s
z5AsyncMockAssert.test_awaits_asserts_with_spec_and_anycCstd�td�g}|�t��|jj|dd�Wd�n1s wYt|�d��|�t��|jj|dd�Wd�n1sDwYt|�d��|�t��|jj|dd�Wd�n1shwYt|�d��|jj|dd�t|�d��|jj|dd�dS)Nrlr>T)Z	any_orderZbamfZqux)rr�r�rsrrrS)rr~rrr�test_assert_has_awaits_ordered	s ���z.AsyncMockAssert.test_assert_has_awaits_orderedcCsP|j��t|���|�t��|j��Wd�dS1s!wYdSr)rsr�rrSr�r�rrrr�test_assert_not_awaiteds

"�z'AsyncMockAssert.test_assert_not_awaitedcCs�d	dd�}t|d�|_t|�d��|�td�t�d����}|j�	t
�g�Wd�n1s1wY|�|jj
�|�td�t�d����}|j�	t
�t
dd�g�Wd�n1s`wY|�|jj
t�dS)
Nc�rrrr�rrr�f$rzIAsyncMockAssert.test_assert_has_awaits_not_matching_spec_error.<locals>.fr�rWz^{}$z6Awaits not found.
Expected: [call()]
Actual: [call(1)]z�Error processing expected awaits.
Errors: [None, TypeError('too many positional arguments')]
Expected: [call(), call(1, 2)]
Actual: [call(1)]r[r)rrsrrSrwr��format�re�escaperrr�r}�	__cause__rPr:)rr�r�rrr�.test_assert_has_awaits_not_matching_spec_error#s2
�������
z>AsyncMockAssert.test_assert_has_awaits_not_matching_spec_errorN)r$r%r&rRrSrUrYrZr[r]r^r_rarfrhrmrsrtruryrzr{rr�r�r�r�r�rrrrrQ�s4



rQ�__main__).rr5rFr�r��
contextlibrrrrZ
unittest.mockrrrr	r
rrr
rrrrr*r-r1r2rAr3r$rLr�r7ZTestCaser9r`rqr�r�r�r�rrr=rQr�rrrr�<module>sH0


=2"Tiy&rEI�