
    =e                        d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ  ej	        d           d dl m
Z
mZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZ d	 Z G d
 d          Z G d d          Zd Zd Zd Z G d de          Ze  dZ!e  dZ"ed             Z# G d dej$                  Z% G d dej$                  Z& G d dej$                  Z' G d dej$                  Z( G d dej$                  Z) G d  d!ej$                  Z* G d" d#e          Z+ G d$ d%ej$                  Z, G d& d'ej$                  Z- G d( d)ej$                  Z. G d* d+ej$                  Z/e d,k    r ej0                     dS dS )-    N)contextmanager)supportT)module)runiscoroutinefunction)IsolatedAsyncioTestCase)
ANYcall	AsyncMockpatch	MagicMockMockcreate_autospecsentinel	_CallListsealc                  .    t          j        d            d S N)asyncioset_event_loop_policy     7/usr/lib/python3.11/unittest/test/testmock/testasync.pytearDownModuler      s    !$'''''r   c                   L    e Zd Zd Zd Zd Zed             Zed             Z	dS )
AsyncClassc                     d S r   r   selfs    r   __init__zAsyncClass.__init__         r   c                 
   K   d S r   r   r   s    r   async_methodzAsyncClass.async_method   
        r   c                     d S r   r   r   s    r   normal_methodzAsyncClass.normal_method   r!   r   c                 
   K   d S r   r   )clss    r   async_class_methodzAsyncClass.async_class_method   s      '+tr   c                  
   K   d S r   r   r   r   r   async_static_methodzAsyncClass.async_static_method   s      %)Tr   N)
__name__
__module____qualname__r    r#   r&   classmethodr)   staticmethodr+   r   r   r   r   r      sQ        &&&!!!++ [+)) \)))r   r   c                       e Zd Zd ZdS )AwaitableClassc              #      K   d V  d S r   r   r   s    r   	__await__zAwaitableClass.__await__"   s      r   N)r,   r-   r.   r4   r   r   r   r2   r2   !   s        r   r2   c                  
   K   d S r   r   r   r   r   
async_funcr6   $   r$   r   c                
   K   d S r   r   )abcs      r   async_func_argsr;   &   r$   r   c                      d S r   r   r   r   r   normal_funcr=   (   r!   r   c                       e Zd Zd ZdS )NormalClassc                     d S r   r   r   s    r   r8   zNormalClass.a+   r!   r   N)r,   r-   r.   r8   r   r   r   r?   r?   *   s        r   r?   z.AsyncClassz.NormalClassc              #      K   |                      t          d          5  d V  t          j                     d d d            d S # 1 swxY w Y   d S )Nzwas never awaited$)assertWarnsRegexRuntimeWarninggccollect)tests    r   assertNeverAwaitedrG   2   s      			~/C	D	D   	
	                 s   AA
Ac                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )AsyncPatchDecoratorTestc                 f     t          j        t          d           fd            } |             d S )Nr#   c                 L                         t          |                      d S r   )
assertTruer   mock_methodr   s    r   
test_asynczLAsyncPatchDecoratorTest.test_is_coroutine_function_patch.<locals>.test_async=   s$    OO/<<=====r   r   objectr   r   rO   s   ` r    test_is_coroutine_function_patchz8AsyncPatchDecoratorTest.test_is_coroutine_function_patch<   sB    	j.	1	1	> 	> 	> 	> 
2	1	>
r   c                      t          j        t          d           fd            }t          t           d           fd            } |              |             d S )Nr#   c                      |             }                     t          j        |                     t          |           d S r   rL   inspectisawaitabler   rN   mr   s     r   rO   z?AsyncPatchDecoratorTest.test_is_async_patch.<locals>.test_asyncC   :    AOOG/22333FFFFFr   z.async_methodc                      |             }                     t          j        |                     t          |           d S r   rV   rY   s     r   test_no_parent_attributezMAsyncPatchDecoratorTest.test_is_async_patch.<locals>.test_no_parent_attributeI   r[   r   )r   rQ   r   async_foo_name)r   rO   r]   s   `  r   test_is_async_patchz+AsyncPatchDecoratorTest.test_is_async_patchB   s    	j.	1	1	 	 	 	 
2	1	
 
.///	0	0	 	 	 	 
1	0	
 	
  """""r   c                 f     t          j        t          d           fd            } |             d S )Nr#   c                 >                         | t                     d S r   assertIsInstancer   rM   s    r   rO   zCAsyncPatchDecoratorTest.test_is_AsyncMock_patch.<locals>.test_asyncS       !!+y99999r   rP   rR   s   ` r   test_is_AsyncMock_patchz/AsyncPatchDecoratorTest.test_is_AsyncMock_patchR   sD    	j.	1	1	: 	: 	: 	: 
2	1	: 	
r   c                 f     t          j        t          d           fd            } |             d S )Nr+   c                 >                         | t                     d S r   rb   rM   s    r   rO   zPAsyncPatchDecoratorTest.test_is_AsyncMock_patch_staticmethod.<locals>.test_asyncZ   rd   r   rP   rR   s   ` r   $test_is_AsyncMock_patch_staticmethodz<AsyncPatchDecoratorTest.test_is_AsyncMock_patch_staticmethodY   sE    	j"7	8	8	: 	: 	: 	: 
9	8	: 	
r   c                 f     t          j        t          d           fd            } |             d S )Nr)   c                 >                         | t                     d S r   rb   rM   s    r   rO   zOAsyncPatchDecoratorTest.test_is_AsyncMock_patch_classmethod.<locals>.test_asynca   rd   r   rP   rR   s   ` r   #test_is_AsyncMock_patch_classmethodz;AsyncPatchDecoratorTest.test_is_AsyncMock_patch_classmethod`   sE    	j"6	7	7	: 	: 	: 	: 
8	7	: 	
r   c                     t          t           dd          t          t           dd           fd                        }t           |                                            t	          j        t                               d S )N.async_func   return_value.async_func_args   c                   K                        | j        d                                |j        d                               t          t                                         t
          t                                          t                       d {V d                                t          ddd           d {V d           d S )Nr;   r6   rn   rr      r:   )assertEqual
_mock_namerc   r6   r   r;   )func_args_mock	func_mockr   s     r   rO   z@AsyncPatchDecoratorTest.test_async_def_patch.<locals>.test_asynch   s       ^68IJJJY1<@@@!!*i888!!/9===:<<//////333?1a1#=#=#=======qAAAAAr   )r   r,   r   rL   rW   r   r6   rR   s   ` r   test_async_def_patchz,AsyncPatchDecoratorTest.test_async_def_patchg   s    	('''a	8	8	8	(,,,1	=	=	=	B 	B 	B 	B 
>	= 
9	8	B 	JJLL3J??@@@@@r   N)	r,   r-   r.   rS   r_   re   rh   rk   rz   r   r   r   rI   rI   ;   ss          # # #       A A A A Ar   rI   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )AsyncPatchCMTestc                 &      fd} |             d S )Nc                      t          j        t          d          5 }                     t	          |                      d d d            d S # 1 swxY w Y   d S Nr#   )r   rQ   r   rL   r   rM   s    r   rO   z>AsyncPatchCMTest.test_is_async_function_cm.<locals>.test_asyncz   s    j.99 B[ 3K @ @AAAB B B B B B B B B B B B B B B B B Bs   #AAAr   rR   s   ` r   test_is_async_function_cmz*AsyncPatchCMTest.test_is_async_function_cmy   s2    	B 	B 	B 	B 	B 	
r   c                 &      fd} |             d S )Nc                      t          j        t          d          5 }  |             }                    t	          j        |                     t          |           d d d            d S # 1 swxY w Y   d S r   )r   rQ   r   rL   rW   rX   r   rY   s     r   rO   z5AsyncPatchCMTest.test_is_async_cm.<locals>.test_async   s    j.99 [KMM 3A 6 6777A                 s   AA**A.1A.r   rR   s   ` r   test_is_async_cmz!AsyncPatchCMTest.test_is_async_cm   s-    	 	 	 	 	 	
r   c                 &      fd} |             d S )Nc                      t          j        t          d          5 }                     | t                     d d d            d S # 1 swxY w Y   d S r   )r   rQ   r   rc   r   rM   s    r   rO   z9AsyncPatchCMTest.test_is_AsyncMock_cm.<locals>.test_async   s    j.99 >[%%k9===> > > > > > > > > > > > > > > > > >s   AA	A	r   rR   s   ` r   test_is_AsyncMock_cmz%AsyncPatchCMTest.test_is_AsyncMock_cm   s-    	> 	> 	> 	> 	> 	
r   c                 @      fd}t           |                       d S )Nc                    K   t          t           dt                                5                       t          t                     d d d            n# 1 swxY w Y                        t          j        t                               d S )Nrm   )r   r,   r   rc   r6   rL   rW   r   r   s   r   rO   z6AsyncPatchCMTest.test_async_def_cm.<locals>.test_async   s      (///== = =%%j)<<<= = = = = = = = = = = = = = =OOG7
CCDDDDDs   !AAAr   rR   s   ` r   test_async_def_cmz"AsyncPatchCMTest.test_async_def_cm   s=    	E 	E 	E 	E 	E
 	JJLLr   c                      ddit          j        ddi           fd            }                     t          |                     t	           |                       d S )Nr8   r9   c                  D   K                         d         d           d S Nr8   r9   )rv   foor   s   r   rO   z>AsyncPatchCMTest.test_patch_dict_async_def.<locals>.test_async   s'      SXs+++++r   )r   dictrL   r   r   r   rO   r   s   ` @r   test_patch_dict_async_defz*AsyncPatchCMTest.test_patch_dict_async_def   s}    Cj	C#s	$	$	, 	, 	, 	, 	, 
%	$	, 	+J77888JJLLr   c                 L     ddi fd}t           |                       d S )Nr8   c                     K   t          j         ddi          5                       d         d           d d d            d S # 1 swxY w Y   d S r   )r   r   rv   r   s   r   rO   zFAsyncPatchCMTest.test_patch_dict_async_def_context.<locals>.test_async   s      C#s,, 0 0  S3///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0s   AA	A	r   r   s   ` @r   !test_patch_dict_async_def_contextz2AsyncPatchCMTest.test_patch_dict_async_def_context   sG    Cj	0 	0 	0 	0 	0 	0 	JJLLr   N)	r,   r-   r.   r   r   r   r   r   r   r   r   r   r|   r|   x   sn                      r   r|   c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )AsyncMockTestc                 f    t                      }|                     t          |                     d S r   )r   rL   r   r   mocks     r    test_iscoroutinefunction_defaultz.AsyncMockTest.test_iscoroutinefunction_default   s,    {{+D1122222r   c                     d }t          |          }|                     t          |                     |                     t          j        |                     d S )Nc                  
   K   d S r   r   r   r   r   r   z<AsyncMockTest.test_iscoroutinefunction_function.<locals>.foo   r$   r   r   rL   r   rW   r   r   r   s      r   !test_iscoroutinefunction_functionz/AsyncMockTest.test_iscoroutinefunction_function   sT    ~~+D112223D99:::::r   c                     t                      } |            }|                     t          j        |                     t	          |           |                     dt          |                     d S )Nassert_awaited)r   rL   rW   rX   r   assertIndirr   r   rZ   s      r   test_isawaitablezAsyncMockTest.test_isawaitable   s_    {{DFF+A..///A&D		22222r   c                     d }t          |          }|                     t          |                     |                     t          j        |                     d S )Nc                      d S r   r   r   r   r   r   zCAsyncMockTest.test_iscoroutinefunction_normal_function.<locals>.foo   r!   r   r   r   s      r   (test_iscoroutinefunction_normal_functionz6AsyncMockTest.test_iscoroutinefunction_normal_function   sR    ~~+D112223D99:::::r   c                    t          j                    }|                                }|                                 |                                 t          |          }|                     |t           j                   d S r   )r   new_event_loopcreate_futurestopcloser   rc   Future)r   loopfutr   s       r   test_future_isfuturez"AsyncMockTest.test_future_isfuture   sd    %''  ""		

~~dGN33333r   N)r,   r-   r.   r   r   r   r   r   r   r   r   r   r      s_        3 3 3; ; ;3 3 3; ; ;4 4 4 4 4r   r   c                   X    e Zd Zd Zd Z ej        d          d             Zd Zd Z	dS )AsyncAutospecTestc                      t          t          d           fd            }t          t          d           fd            } |              |             d S )NTautospecc                 ~                         | j        t                                          | t                     d S r   rc   r#   r   r   rM   s    r   rO   z=AsyncAutospecTest.test_is_AsyncMock_patch.<locals>.test_async   s8    !!+":IFFF!!+y99999r   c                 H                         | j        t                     d S r   )rc   r&   r   rM   s    r   test_normal_methodzEAsyncAutospecTest.test_is_AsyncMock_patch.<locals>.test_normal_method   s"    !!+";YGGGGGr   r   r^   )r   rO   r   s   `  r   re   z)AsyncAutospecTest.test_is_AsyncMock_patch   s    	~	-	-	-	: 	: 	: 	: 
.	-	: 
~	-	-	-	H 	H 	H 	H 
.	-	H 	
r   c                     |                      t                    5  t          t          d           d d d            d S # 1 swxY w Y   d S )NT)instance)assertRaisesRuntimeErrorr   r6   r   s    r   test_create_autospec_instancez/AsyncAutospecTest.test_create_autospec_instance   s    |,, 	7 	7J6666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s   ?AAz3Broken test from https://bugs.python.org/issue37251c                 `    |                      t          t                    t                     d S r   )rc   r   r2   r   r   s    r   $test_create_autospec_awaitable_classz6AsyncAutospecTest.test_create_autospec_awaitable_class   s&    on==yIIIIIr   c                    t          t                    } |ddd          fd}|                     |j        d           |                     |j                   |                     |j        g            |                                 t           |                       | 	                    t          |                     | 	                    t          j                             |                     |j        d           |                     |j        t          ddd                     |                     |j        t          ddd          g           |                                 |                    ddd           |                    ddd           |                                 |                     t&                    5  |                    d           d d d            d S # 1 swxY w Y   d S )Nrn   rr   rt   ru   c                     K     d {V  d S r   r   )	awaitables   r   mainz4AsyncAutospecTest.test_create_autospec.<locals>.main   s      OOOOOOOOOr   r   )e)r   r;   rv   await_countassertIsNone
await_argsawait_args_listassert_not_awaitedr   rL   r   r   iscoroutiner
   assert_awaited_onceassert_awaited_once_withassert_awaited_withr   r   AssertionErrorassert_any_await)r   specr   r   s      @r   test_create_autospecz&AsyncAutospecTest.test_create_autospec   s/   //DAOOO		 	 	 	 	 	)1---$/***-r222!!!DDFF+D11222+I66777)1---$q!q///:::-QQ/@AAA  """%%aa%000  A +++~.. 	' 	'!!A!&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's   G55G9<G9c                 @      fd}t           |                       d S )Nc                    K   t          t           dd          5 }  | ddd          }                    | j        t                                         t          |                                          t          j        |                                         t          j
        |                                         | j        d                               | j        g                                | j                   |                                  | d {V  d d d            n# 1 swxY w Y                       | j        d                               | j        t#          ddd                                         | j        t#          ddd          g           |                                  |                     ddd           |                     ddd           |                                  |                                                      | j        d                               | j                                       | j        g            d S )	Nrq   Tr   rn   rr   rt   ru   r   )r   r,   rc   r   r   rL   r   r   r   rW   rX   rv   r   r   r   r   r   r
   r   r   r   r   
reset_mock)rN   r   r   s     r   rO   z>AsyncAutospecTest.test_patch_with_autospec.<locals>.test_async   s     (444tDDD  'K1222	%%k&6	BBB 3K @ @AAA 3I > >??? 3I > >???   !8!<<<  !<bAAA!!+"8999..000                               [4a888[3T!Q!___EEE[841???:KLLL++---00A0;;;++AqA+666&&(((""$$$[4a888k4555[8"=====s   DD44D8;D8r   rR   s   ` r   test_patch_with_autospecz*AsyncAutospecTest.test_patch_with_autospec   s8    	> 	> 	> 	> 	>< 	JJLLr   N)
r,   r-   r.   re   r   unittestskipr   r   r   r   r   r   r   r      s}          7 7 7 X]HIIJ J JIJ' ' '6         r   r   c                   V    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd ZdS )AsyncSpecTestc                       fd}t           t          fD ]=}                     d|           5   ||           d d d            n# 1 swxY w Y   >d S )Nc                      | t                     }                    |j        t                                         |j        t
                     d S r   )r   rc   r#   r   r&   r   )	mock_typer   r   s     r   
inner_testzCAsyncSpecTest.test_spec_normal_methods_on_class.<locals>.inner_test!  sJ    9Z((D!!$"3Y???!!$"4i@@@@@r   ztest method types with r   r   subTestr   r   r   s   `  r   !test_spec_normal_methods_on_classz/AsyncSpecTest.test_spec_normal_methods_on_class   s    	A 	A 	A 	A 	A
 $Y/ 	& 	&IC	CCDD & &
9%%%& & & & & & & & & & & & & & &	& 	&   AA	A	c                     t          t                    }|                     |j        t                     |                     |j        t                      d S r   )r   r   rc   r#   r   r&   r   s     r   +test_spec_normal_methods_on_class_with_mockz9AsyncSpecTest.test_spec_normal_methods_on_class_with_mock*  sG    Jd/;;;d0$77777r   c                 2   t          t                    }t          |           |                     t                    5  |j         d d d            n# 1 swxY w Y   |                     t                    5  |j         d d d            d S # 1 swxY w Y   d S r   )r   r   r   r   AttributeErrorr&   r#   r   s     r   0test_spec_normal_methods_on_class_with_mock_sealz>AsyncSpecTest.test_spec_normal_methods_on_class_with_mock_seal/  s   JT


~.. 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	~.. 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s#   AAA7BBBc                       fd}t           t          t          fD ]=}                     d|           5   ||           d d d            n# 1 swxY w Y   >d S )Nc                 P    | t                     }                    ||            t                    5                      t	          j         |                                 d d d            n# 1 swxY w Y    | t                    }                    ||            d S Nr   r6   rc   rG   rL   rW   rX   r=   r   
async_mock	sync_mockr   s      r   r   z8AsyncSpecTest.test_spec_mock_type_kw.<locals>.inner_test8  s    "
333J!!*i888#D)) C C 3JJLL A ABBBC C C C C C C C C C C C C C C "	{333I!!)Y77777s   0A44A8;A8ztest spec kwarg with r   r   r   r   r   s   `  r   test_spec_mock_type_kwz$AsyncSpecTest.test_spec_mock_type_kw7  s    	8 	8 	8 	8 	8 $Y5 	& 	&IAiAABB & &
9%%%& & & & & & & & & & & & & & &	& 	&   AA	A	c                       fd}t           t          t          fD ]=}                     d|           5   ||           d d d            n# 1 swxY w Y   >d S )Nc                 L    | t                     }                    ||            t                    5                      t	          j         |                                 d d d            n# 1 swxY w Y    | t                    }                    ||            d S r   r   r   s      r   r   z@AsyncSpecTest.test_spec_mock_type_positional.<locals>.inner_testF  s    ":..J!!*i888#D)) C C 3JJLL A ABBBC C C C C C C C C C C C C C C "	+..I!!)Y77777s   0A33A7:A7ztest spec positional with r   r   s   `  r   test_spec_mock_type_positionalz,AsyncSpecTest.test_spec_mock_type_positionalE  s    	8 	8 	8 	8 	8 $Y5 	& 	&IF9FFGG & &
9%%%& & & & & & & & & & & & & & &	& 	&r   c                     t          t                    }|                     |t                       |            }|                     t	          j        |                     t          |           d S r   r   r=   rc   rL   rW   rX   r   r   s      r    test_spec_as_normal_kw_AsyncMockz.AsyncSpecTest.test_spec_as_normal_kw_AsyncMockS  s_    k***dI...DFF+A..///Ar   c                     t          t                    }|                     |t                       |            }|                     t	          j        |                     t          |           d S r   r   r   s      r   (test_spec_as_normal_positional_AsyncMockz6AsyncSpecTest.test_spec_as_normal_positional_AsyncMockZ  s\    %%dI...DFF+A..///Ar   c                 j     t          j        t          dd           fd            } |             d S )Nr#   Tr   c                 >                         | t                     d S r   rb   rM   s    r   rO   z6AsyncSpecTest.test_spec_async_mock.<locals>.test_asyncb  rd   r   rP   rR   s   ` r   test_spec_async_mockz"AsyncSpecTest.test_spec_async_mocka  sI    	j.t	<	<	<	: 	: 	: 	: 
=	<	: 	
r   c                 ^     t          t          d           fd            } |             d S )NTr   c                 ~                         | t                                          | j        t                     d S r   )rc   r   r#   r   rM   s    r   rO   zIAsyncSpecTest.test_spec_parent_not_async_attribute_is.<locals>.test_asynci  s8    !!+y999!!+":IFFFFFr   r   rR   s   ` r   'test_spec_parent_not_async_attribute_isz5AsyncSpecTest.test_spec_parent_not_async_attribute_ish  sJ    	~D	)	)	)	G 	G 	G 	G 
*	)	G 	
r   c                 ~     t          j        t          dt          j                   fd            } |             d S )Nr#   r   c                                          | t                                         t          j        |                                          t          j        |                      d S r   )rc   r   assertFalserW   r   rX   rM   s    r   test_async_attributezFAsyncSpecTest.test_target_async_spec_not.<locals>.test_async_attributeq  s]    !!+y999W0==>>>W0==>>>>>r   )r   rQ   r   r?   r8   )r   r  s   ` r   test_target_async_spec_notz(AsyncSpecTest.test_target_async_spec_notp  sR    	j.{}	E	E	E	? 	? 	? 	? 
F	E	?
 	r   c                 t     t          j        t          dt                     fd            } |             d S )Nr8   r   c                 >                         | t                     d S r   rb   )mock_async_funcr   s    r    test_attribute_not_async_spec_iszUAsyncSpecTest.test_target_not_async_spec_is.<locals>.test_attribute_not_async_spec_isz  s    !!/9=====r   )r   rQ   r?   r6   )r   r  s   ` r   test_target_not_async_spec_isz+AsyncSpecTest.test_target_not_async_spec_isy  sM    	k3Z	8	8	8	> 	> 	> 	> 
9	8	>((*****r   c                 h     t          t          t                     fd            } |             d S )Nr   c                 ~                         | j        t                                          | t                     d S r   r   )MockNormalClassr   s    r    test_async_attributes_coroutineszRAsyncSpecTest.test_spec_async_attributes.<locals>.test_async_attributes_coroutines  s8    !!/">	JJJ!!/9=====r   )r   normal_foo_namer   )r   r  s   ` r   test_spec_async_attributesz(AsyncSpecTest.test_spec_async_attributes  sK    	Z	0	0	0	> 	> 	> 	> 
1	0	> 	)(*****r   N)r,   r-   r.   r   r   r   r   r   r   r   r  r  r	  r  r  r   r   r   r   r     s        & & &8 8 8
  & & && & &          + + ++ + + + +r   r   c                   &    e Zd Zd Zd Zd Zd ZdS )AsyncSpecSetTestc                 j     t          j        t          dd           fd            } |             d S )Nr#   Tspec_setc                 >                         | t                     d S r   rb   )r#   r   s    r   rO   z<AsyncSpecSetTest.test_is_AsyncMock_patch.<locals>.test_async  s    !!,	:::::r   rP   rR   s   ` r   re   z(AsyncSpecSetTest.test_is_AsyncMock_patch  sH    	j.4	@	@	@	; 	; 	; 	; 
A	@	;
r   c                     t          t          j                  }|                     t	          |                     |                     |t                      d S Nr  )r   r   r#   rL   r   rc   r   s     r   test_is_async_AsyncMockz(AsyncSpecSetTest.test_is_async_AsyncMock  sL    *"9:::+D11222dI.....r   c                    t          t                    }|                     t          |j                             |                     t          |j                             |                     |j        t                     |                     |j        t                      |                     |t                      d S r  )	r   r   rL   r   r#   r  r&   rc   r   r   s     r   test_is_child_AsyncMockz(AsyncSpecSetTest.test_is_child_AsyncMock  s    *---+D,=>>???,T-?@@AAAd/;;;d0)<<<dI.....r   c                     t                      }t          d           |_        t          j        |d          5 }|                     |t                      d d d            d S # 1 swxY w Y   d S )Nc                     | S r   r   xs    r   <lambda>z=AsyncSpecSetTest.test_magicmock_lambda_spec.<locals>.<lambda>  s    a r   r   	mock_func)r   r%  r   rQ   rc   )r   mock_objcms      r   test_magicmock_lambda_specz+AsyncSpecSetTest.test_magicmock_lambda_spec  s    ;;&KK888\(K00 	1B!!"i000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s   A##A'*A'N)r,   r-   r.   re   r  r  r(  r   r   r   r  r    sP          / / /
/ / /1 1 1 1 1r   r  c                   \    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd ZdS )AsyncArgumentsc                    K   d }t          |d          } |d           d {V }|                     |d           d S )Nc                 
   K   d S r   r   )r   vars     r   additionz6AsyncArguments.test_add_return_value.<locals>.addition  r$   r   
   ro      r   rv   )r   r.  r   outputs       r   test_add_return_valuez$AsyncArguments.test_add_return_value  sV      +++333tAww$$$$$r   c                    K    G d dt                     }d }t          | |d                    }|                     |d          5   |d           d {V  d d d            d S # 1 swxY w Y   d S )Nc                       e Zd ZdS )BAsyncArguments.test_add_side_effect_exception.<locals>.CustomErrorNr,   r-   r.   r   r   r   CustomErrorr6    s          r   r8  c                 
   K   d S r   r   r-  s    r   r.  z?AsyncArguments.test_add_side_effect_exception.<locals>.addition  r$   r   zside-effectside_effectr0  )	Exceptionr   assertRaisesRegex)r   r8  r.  r   s       r   test_add_side_effect_exceptionz-AsyncArguments.test_add_side_effect_exception  s      *****)***%%%{{=/I/IJJJ##K?? 	 	$q''MMMMMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   	A((A,/A,c                 ~   K   d }t          |          } |d           d {V }|                     |d           d S )Nc                    K   | dz   S Nrn   r   r:  s    r   r.  z?AsyncArguments.test_add_side_effect_coroutine.<locals>.addition  s      7Nr   r;  r0     r1  r   r.  r   results       r   test_add_side_effect_coroutinez-AsyncArguments.test_add_side_effect_coroutine  Z      	 	 	X...tAww#####r   c                 ~   K   d }t          |          } |d           d {V }|                     |d           d S )Nc                     | dz   S rB  r   r:  s    r   r.  zEAsyncArguments.test_add_side_effect_normal_function.<locals>.addition  s    7Nr   r;  r0  rC  r1  rD  s       r   $test_add_side_effect_normal_functionz3AsyncArguments.test_add_side_effect_normal_function  rG  r   c                 
  K   g d}t          |          }|D ]&}|                      |             d {V |           '|                     t                    5 } |             d {V  d d d            d S # 1 swxY w Y   d S )Nrn   rr   rt   r;  )r   rv   r   StopAsyncIteration)r   valsr   itemr   s        r   test_add_side_effect_iterablez,AsyncArguments.test_add_side_effect_iterable  s      yyT*** 	1 	1D4466\\\\\\40000122 	a$&&LLLLLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A88A<?A<c                 .  K    G d dt                     }d |d          g}t          |          }|                      |             d {V d           |                     |          5 } |             d {V  d d d            d S # 1 swxY w Y   d S )Nc                       e Zd ZdS )OAsyncArguments.test_add_side_effect_exception_iterable.<locals>.SampleExceptionNr7  r   r   r   SampleExceptionrS    s        Dr   rT  rn   r   r;  )r=  r   rv   r   )r   rT  rN  r   r   s        r   'test_add_side_effect_exception_iterablez6AsyncArguments.test_add_side_effect_exception_iterable  s
     	 	 	 	 	i 	 	 	 ??5))*T***ttvvq)))// 	1$&&LLLLLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   ,B

BBc                    K   t          d          }t          |          } |             d {V }|                     ||           d S )Nr/  ro   )r   assertIs)r   valuer   rE  s       r   test_return_value_AsyncMockz*AsyncArguments.test_return_value_AsyncMock  sW      r***e,,,tvvfe$$$$$r   c                    K   t          j                    }|                    d            t          |          } |             d {V }|                     |t           j                   d S )Nro   )r   r   
set_resultr   rc   r   r   r   rE  s       r   test_return_value_awaitablez*AsyncArguments.test_return_value_awaitable  sj      ntc***tvvfgn55555r   c                 b  K   t          j                    }|                    d            t          |g          } |             d {V }|                     |t           j                   |                     t                    5   |             d {V  d d d            d S # 1 swxY w Y   d S )Nr;  )r   r   r[  r   rc   r   rM  r\  s       r   !test_side_effect_awaitable_valuesz0AsyncArguments.test_side_effect_awaitable_values  s      ntcU+++tvvfgn555122 	 	$&&LLLLLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   B$$B(+B(c                    K   t          d          }t          |          } |             d {V }|                     |d           d S )Nr/  ro   r;  r1  )r   effectr   rE  s       r   test_side_effect_is_AsyncMockz,AsyncArguments.test_side_effect_is_AsyncMock  sY      +++V,,,tvv$$$$$r   c                   K   t          j                    dfd}t          |          } |             d {V }|                     |           |                                 |                                d S )NFc                     K   d S NTr   ranrX  s   r   innerz2AsyncArguments.test_wraps_coroutine.<locals>.inner  s      CLr   wraps)r   r   r   rv   r   rL   r   rh  r   rE  rg  rX  s       @@r   test_wraps_coroutinez#AsyncArguments.test_wraps_coroutine  s        	 	 	 	 	 	
 u%%%tvv'''r   c                    K   ddfd}t          |          } |             d {V }|                     |           |                                 |                                d S )Nrn   Fc                      d S re  r   rf  s   r   rh  z8AsyncArguments.test_wraps_normal_function.<locals>.inner  s    CLr   ri  )r   rv   r   rL   rk  s       @@r   test_wraps_normal_functionz)AsyncArguments.test_wraps_normal_function  s      	 	 	 	 	 	
 u%%%tvv'''r   c                   K   t                      } |d          } |d          }| d {V  | d {V  |                    t          d          t          d          g           |                     |j        t          d          t          d          g           |                     |j        t          d          t          d          g           d S )Nrr   rn   )r   assert_has_awaitsr
   rv   r   call_args_list)r   r   mock2mock1s       r   test_await_args_list_orderz)AsyncArguments.test_await_args_list_order  s      [[

1
1$$d1ggtAww%78883d1ggtAww5GHHH2T!WWd1gg4FGGGGGr   N)r,   r-   r.   r3  r?  rF  rJ  rP  rU  rY  r]  r_  rb  rl  ro  ru  r   r   r   r*  r*    s        % % %  $ $ $$ $ $  	 	 	% % %6 6 6	 	 	% % %    H H H H Hr   r*  c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )AsyncMagicMethodsc                 "   t                      }|                     |j        t                     |                     |j        t                     |                     |j        t                     |                     |j        t                      d S r   )r   rc   
__aenter__r   	__aexit__	__anext__	__aiter__r   m_mocks     r   +test_async_magic_methods_return_async_mocksz=AsyncMagicMethods.test_async_magic_methods_return_async_mocks  sw    f/;;;f.	:::f.	::: 	f.	:::::r   c                 "   t                      }|                     |j        t                     |                     |j        t                     |                     |j        t                     |                     |j        t                     d S r   )r   rc   	__enter__r   __exit____next____len__r   a_mocks     r   *test_sync_magic_methods_return_magic_mocksz<AsyncMagicMethods.test_sync_magic_methods_return_magic_mocks(  sr    f.	:::foy999foy999fni88888r   c                     t                      }|                     t          |d                     |                     t          |d                     |                     t          |d                     d S )Nry  rz  r{  )r   rL   hasattrr}  s     r   &test_magicmock_has_async_magic_methodsz8AsyncMagicMethods.test_magicmock_has_async_magic_methods/  se    55666445554455555r   c                 :   t                      }|                     t          |d                     |                     t          |d                     |                     t          |d                     |                     t          |d                     d S )Nr  r  r  r  )r   rL   r  r  s     r   %test_asyncmock_has_sync_magic_methodsz7AsyncMagicMethods.test_asyncmock_has_sync_magic_methods5  s    44555
33444
33444	2233333r   c                 >   t                      }|                     |j        t                     |                     |j        t                     |                     t          |j                             |                     t          |j                             d S r   )r   rc   ry  r   rz  rL   r   r}  s     r   &test_magic_methods_are_async_functionsz8AsyncMagicMethods.test_magic_methods_are_async_functions<  s    f/;;;f.	:::+F,=>>???+F,<==>>>>>r   N)r,   r-   r.   r  r  r  r  r  r   r   r   rw  rw    s_        ; ; ;9 9 96 6 64 4 4? ? ? ? ?r   rw  c                   z    e Zd Z G d d          Z G d d          Z G d d          Zd Zd Zd	 Zd
 Z	d Z
dS )AsyncContextManagerTestc                       e Zd Zd Zd ZdS )/AsyncContextManagerTest.WithAsyncContextManagerc                 
   K   d S r   r   r   argskwargss      r   ry  z:AsyncContextManagerTest.WithAsyncContextManager.__aenter__G  r$   r   c                 
   K   d S r   r   r  s      r   rz  z9AsyncContextManagerTest.WithAsyncContextManager.__aexit__I  r$   r   N)r,   r-   r.   ry  rz  r   r   r   WithAsyncContextManagerr  F  s"        99988888r   r  c                       e Zd Zd Zd ZdS ).AsyncContextManagerTest.WithSyncContextManagerc                     d S r   r   r  s      r   r  z8AsyncContextManagerTest.WithSyncContextManager.__enter__L  r!   r   c                     d S r   r   r  s      r   r  z7AsyncContextManagerTest.WithSyncContextManager.__exit__N  r!   r   N)r,   r-   r.   r  r  r   r   r   WithSyncContextManagerr  K  s"        22211111r   r  c                       e Zd Zd Zd ZdS )&AsyncContextManagerTest.ProductionCodec                     d | _         d S r   )sessionr   s    r   r    z/AsyncContextManagerTest.ProductionCode.__init__R  s    DLLLr   c                    K   | j                             d          4 d {V }|                                 d {V }|cd d d           d {V  S # 1 d {V swxY w Y   d S )Nzhttps://python.org)r  postjson)r   responsevals      r   r   z+AsyncContextManagerTest.ProductionCode.mainU  s      |(()=>>       ($MMOO++++++                             s   A
AAN)r,   r-   r.   r    r   r   r   r   ProductionCoder  P  s2        	  	  	 	 	 	 	 	r   r  c                       fd}t           t          fD ]=}                     d|           5   ||           d d d            n# 1 swxY w Y   >d S )Nc                 l                                    }t          d          |_         | d          }t          d          }t          ddi          |_        ||j        _        ||j        j        _        t          |	                                          }
                    |ddi           d S )Nsessionmocknamemagic_cmr  r  {   ro   )r  r   r  r   r  ry  rp   r  r   r   rv   )r   pcr'  r  rE  r   s        r   r   zKAsyncContextManagerTest.test_set_return_value_of_aenter.<locals>.inner_test[  s    $$&&B"666BJ
+++B j111H%FC=AAAHM)1BM&+-BJO(^^FVfc]33333r   z%test set return value of aenter with r   r   s   `  r   test_set_return_value_of_aenterz7AsyncContextManagerTest.test_set_return_value_of_aenterZ  s    		4 		4 		4 		4 		4 $Y/ 	& 	&IQiQQRR & &
9%%%& & & & & & & & & & & & & & &	& 	&r   c                       fd}t           t          fD ]=}                     d|           5   ||           d d d            n# 1 swxY w Y   >d S )Nc                    d                                 } | |          fd}t           |                      }                                                   j        j                                       j        j                   j                                         j                                                             |           d S )NFc                  h   K   4 d {V } dd d d           d {V  n# 1 d {V swxY w Y   | S re  r   )rE  calledcm_mocks    r   use_context_managerzqAsyncContextManagerTest.test_mock_supports_async_context_manager.<locals>.inner_test.<locals>.use_context_managerp  s      " " " " " " " "f!F" " " " " " " " " " " " " " " " " " " " " " " " " " "s   !
++)r  r   rL   ry  r  rz  r   assertIsNot)r   r'  r  	cm_resultr  r  r   s       @@r   r   zTAsyncContextManagerTest.test_mock_supports_async_context_manager.<locals>.inner_testk  s    F--//BimmG      //1122IOOF###OOG.5666OOG-4555--///,,...Wi00000r   z!test context manager magics with r   r   s   `  r   (test_mock_supports_async_context_managerz@AsyncContextManagerTest.test_mock_supports_async_context_managerj  s    	1 	1 	1 	1 	1( $Y/ 	& 	&IM)MMNN & &
9%%%& & & & & & & & & & & & & & &	& 	&r   c                     |                                  }t          |          t                      }|j        _        fd}|                     t           |                      |           d S )Nc                  h   K   4 d {V } | cd d d           d {V  S # 1 d {V swxY w Y   d S r   r   )rE  mock_instances    r   r  z^AsyncContextManagerTest.test_mock_customize_async_context_manager.<locals>.use_context_manager  s      $                                    s   !
++)r  r   rQ   ry  rp   rW  r   )r   r   expected_resultr  r  s       @r   )test_mock_customize_async_context_managerzAAsyncContextManagerTest.test_mock_customize_async_context_manager  s|    //11!(++ ((0? -	 	 	 	 	 	c--//00/BBBBBr   c                    ddfd}fd}|                                  }t          |          |_        |_        fd}t	           |                       |                                |                                d S )NFc                     K   dd S re  r   )r  enter_calleds    r   enter_coroutineziAsyncContextManagerTest.test_mock_customize_async_context_manager_with_coroutine.<locals>.enter_coroutine  s      LLLr   c                     K   dd S re  r   )r  exit_calleds    r   exit_coroutinezhAsyncContextManagerTest.test_mock_customize_async_context_manager_with_coroutine.<locals>.exit_coroutine  s      KKKr   c                  h   K    4 d {V  	 d d d           d {V  d S # 1 d {V swxY w Y   d S r   r   )r  s   r   r  zmAsyncContextManagerTest.test_mock_customize_async_context_manager_with_coroutine.<locals>.use_context_manager  s      $                                     s   !
++)r  r   ry  rz  r   rL   )r   r  r  r   r  r  r  r  s        @@@r   8test_mock_customize_async_context_manager_with_coroutinezPAsyncContextManagerTest.test_mock_customize_async_context_manager_with_coroutine  s    	  	  	  	  	 	 	 	 	 	 //11!(++#2 "0	 	 	 	 	 	!!"""%%%$$$$$r   c                     d }|                                  }t          |          }|                     t                    5  t	           ||                     d d d            d S # 1 swxY w Y   d S )Nc                 Z   K   | 4 d {V  t                      # 1 d {V swxY w Y   d S r   )	TypeError)context_managers    r   raise_inzYAsyncContextManagerTest.test_context_manager_raise_exception_by_default.<locals>.raise_in  s      & " " " " " " " "kk!" " " " " " " " " " " " " " " "s   
$$)r  r   r   r  r   )r   r  r   r  s       r   /test_context_manager_raise_exception_by_defaultzGAsyncContextManagerTest.test_context_manager_raise_exception_by_default  s    	" 	" 	" //11!(++y)) 	) 	)''(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)s   A''A+.A+N)r,   r-   r.   r  r  r  r  r  r  r  r  r   r   r   r  r  D  s        9 9 9 9 9 9 9 9
2 2 2 2 2 2 2 2
       & & & & & &4C C C% % %4) ) ) ) )r   r  c                   <    e Zd Z G d de          Zd Zd Zd ZdS )AsyncIteratorTestc                        e Zd Zd Zd Zd ZdS )#AsyncIteratorTest.WithAsyncIteratorc                     g d| _         d S )N)r   	NormalFoobaz)itemsr   s    r   r    z,AsyncIteratorTest.WithAsyncIterator.__init__  s    444DJJJr   c                     d S r   r   r   s    r   r|  z-AsyncIteratorTest.WithAsyncIterator.__aiter__  r!   r   c                 
   K   d S r   r   r   s    r   r{  z-AsyncIteratorTest.WithAsyncIterator.__anext__  r$   r   N)r,   r-   r.   r    r|  r{  r   r   r   WithAsyncIteratorr    s3        	5 	5 	5 	"!!'''''r   r  c                     t          d          g dj        _        fd}t           |                      }|                     |g d           d S )Ntesterr  rL  c                  ,   K   d  2              d {V S )Nc                 "   K   g | 3 d {V }|
6 S r   r   ).0is     r   
<listcomp>zOAsyncIteratorTest.test_aiter_set_return_value.<locals>.main.<locals>.<listcomp>  s.      ////////A////s   r   )	mock_iters   r   r   z;AsyncIteratorTest.test_aiter_set_return_value.<locals>.main  s-      //Y//////////r   )r   r|  rp   r   rv   )r   r   rE  r  s      @r   test_aiter_set_return_valuez-AsyncIteratorTest.test_aiter_set_return_value  sl    8,,,	+499	(	0 	0 	0 	0 	0TTVV+++++r   c                       fd}t           t          fD ]=}                     d|           5   ||           d d d            n# 1 swxY w Y   >d S )Nc                 ~                                    } | |          }                    t          |j                                                 t          |j                                                 t          |j                                                 t          |j                             d S r   )r  r  r   r|  rL   r{  )r   r   r  r   s      r   r   zIAsyncIteratorTest.test_mock_aiter_and_anext_asyncmock.<locals>.inner_test  s    --//H%Ih//M 01CDDEEE01HIIJJJOO/0BCCDDDOO/0GHHIIIIIr   z%test aiter and anext corourtine with r   r   s   `  r   #test_mock_aiter_and_anext_asyncmockz5AsyncIteratorTest.test_mock_aiter_and_anext_asyncmock  s    		J 		J 		J 		J 		J $Y/ 	& 	&IQiQQRR & &
9%%%& & & & & & & & & & & & & & &	& 	&r   c                     d g d fd} fd} fd}t           t          fD ]}                     d|           5   ||           d d d            n# 1 swxY w Y                        d|           5   ||           d d d            n# 1 swxY w Y                        d|           5   ||           d d d            n# 1 swxY w Y   d S )	Nc                 N   K   g }| 2 3 d {V }|                     |           6 |S r   )append)iteratoraccumulatorrO  s      r   iteratez6AsyncIteratorTest.test_mock_async_for.<locals>.iterate  sW      K& ) ) ) ) ) ) )d""4(((( ' s   $)FOOBARBAZc                      |                                            }                    t           |                    g            d S r   )r  rv   r   )r   r  r  r   s     r   test_defaultz;AsyncIteratorTest.test_mock_async_for.<locals>.test_default  sL    %Id&<&<&>&>??MS!7!788"=====r   c                      |                                            }d d          |j        _                            t	           |                               d S r   )r  r|  rp   rv   r   r   r  expectedr  r   s     r   test_set_return_valuezDAsyncIteratorTest.test_mock_async_for.<locals>.test_set_return_value  s_    %Id&<&<&>&>??M3;AAA;M#0S!7!788(CCCCCr   c                      |                                            }t          d d                    |j        _                            t           |                               d S r   )r  iterr|  rp   rv   r   r  s     r   test_set_return_value_iterzIAsyncIteratorTest.test_mock_async_for.<locals>.test_set_return_value_iter  sg    %Id&<&<&>&>??M373D3DM#0S!7!788(CCCCCr   zdefault value with zset return_value with zset return_value iterator with r   )r   r  r  r  r   r  r  s   `    @@r   test_mock_async_forz%AsyncIteratorTest.test_mock_async_for  s:   	 	 	 )((	> 	> 	> 	> 	> 	>
	D 	D 	D 	D 	D 	D 	D
	D 	D 	D 	D 	D 	D 	D
 $Y/ 	6 	6I?I??@@ ( (Y'''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ByBBCC 1 1%%i0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1 K	KKLL 6 6**95556 6 6 6 6 6 6 6 6 6 6 6 6 6 6	6 	6s6   AA#	&A#	BB	!B	=CC	C	N)r,   r-   r.   rQ   r  r  r  r  r   r   r   r  r    sk        ( ( ( ( (F ( ( (, , ,& & &" 6  6  6  6  6r   r  c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )AsyncMockAssertc                 ,    t                      | _        d S r   )r   r   r   s    r   setUpzAsyncMockAssert.setUp  s    KK			r   c                 0   K    | j         |i | d {V  d S r   )r   r  s      r   _runnable_testzAsyncMockAssert._runnable_test  s5      di((((((((((((r   c                    K   | d {V S r   r   )r   	coroutines     r   _await_coroutinez AsyncMockAssert._await_coroutine  s      r   c                    t          t                    }t          |           5  |                                 d d d            n# 1 swxY w Y   |                     t          |j                             |j                                         |j                                         |j                                         | 	                    t                    5  |                                 d d d            n# 1 swxY w Y   | 	                    t                    5  |j                                         d d d            d S # 1 swxY w Y   d S r   )r   r   rG   r#   rL   r   assert_calledassert_called_onceassert_called_once_withr   r   r   r   s     r   "test_assert_called_but_not_awaitedz2AsyncMockAssert.test_assert_called_but_not_awaited  s   $$%% 	  	 	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 +D,=>>???''))),,...11333~.. 	" 	"!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"~.. 	/ 	/,,...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s5   AA	A	C==DD"E		EEc                    t          t                    }|                                }|j                                         |j                                         |j                                         |                     t                    5  |j                                         d d d            n# 1 swxY w Y   t          | 
                    |                     |j                                         |j                                         |j                                         |j                                         d S r   )r   r   r#   r  r  r  r   r   r   r   r   r   r   )r   r   mock_coroutines      r   test_assert_called_then_awaitedz/AsyncMockAssert.test_assert_called_then_awaited  sU   $$**,,''))),,...11333~.. 	/ 	/,,...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	D!!.11222,,...((***--///2244444s   B44B8;B8c                    |                      t                    5  | j                                         d d d            n# 1 swxY w Y   |                      t                    5  | j                                         d d d            n# 1 swxY w Y   t          |                                            | j                                         | j                                         d S r   )	r   r   r   r   r  r   r  r  r   r   s    r   +test_assert_called_and_awaited_at_same_timez;AsyncMockAssert.test_assert_called_and_awaited_at_same_time"  sH   ~.. 	' 	'I$$&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' ~.. 	& 	&I##%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	D!!"""	$$&&&	%%'''''s#   AAA&BBBc                 <   t          t                    }|                                }t          |           5  |                                 d d d            n# 1 swxY w Y   |                     t
                    5  |j                                         d d d            n# 1 swxY w Y   |j                                         t          | 	                    |                     |j                                         |j        
                                 d S r   )r   r   r#   rG   r   r   r   r  r   r   r   r   r   r  s      r   )test_assert_called_twice_and_awaited_oncez9AsyncMockAssert.test_assert_called_twice_and_awaited_once-  sv   $$%%''	  %% 	  	 	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 ~.. 	/ 	/,,...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/'')))D!!),,---((***--/////s#   AA A>B$$B(+B(c                    t          t                    }|                                }|j                                         t	          |                     |                     |                     t                    5  t	          |                     |                     d d d            n# 1 swxY w Y   |j                                         d S r   )	r   r   r#   r  r   r   r   r   r   r  s      r   )test_assert_called_once_and_awaited_twicez9AsyncMockAssert.test_assert_called_once_and_awaited_twice;  s    $$%%''	,,...D!!),,---|,, 	2 	2%%i00111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	((*****s   >#B--B14B1c                    |                      t                    5  | j                                         d d d            n# 1 swxY w Y   |                      t                    5  | j                                         d d d            n# 1 swxY w Y   |                      t
                    5  t          |                     | j                             d d d            n# 1 swxY w Y   |                      t                    5  | j                                         d d d            n# 1 swxY w Y   |                      t                    5  | j                                         d d d            d S # 1 swxY w Y   d S r   )r   r   r   r   r  r  r   r   r   s    r   "test_assert_awaited_but_not_calledz2AsyncMockAssert.test_assert_awaited_but_not_calledE  s   ~.. 	' 	'I$$&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'~.. 	& 	&I##%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&y)) 	2 	2%%di00111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 ~.. 	' 	'I$$&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'~.. 	& 	&I##%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&sY   AAA&BBB1(C%%C),C)
D00D47D4E<<F F c                 l   t          d          g}t          |           5  |                     d           d d d            n# 1 swxY w Y   | j                            |           |                     t
                    5  | j                            |           d d d            d S # 1 swxY w Y   d S Nr   )r
   rG   r   assert_has_callsr   r   rq  )r   kallss     r    test_assert_has_calls_not_awaitsz0AsyncMockAssert.test_assert_has_calls_not_awaitsS  s(   e%% 	 	IIe	 	 	 	 	 	 	 	 	 	 	 	 	 	 		""5)))~.. 	/ 	/I''...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s#   AA	AB))B-0B-c                 N   t          |           5  |                                  d d d            n# 1 swxY w Y   ddi fg}|                     | j        j        |           t          |           5  |                     d           d d d            n# 1 swxY w Y   t          |           5  |                     d           d d d            n# 1 swxY w Y   t	                      t	          d          t	          d          g}|                     | j        j        |           d S )N r   r   r  )rG   r   rv   
mock_callsr
   )r   kalls_empty
mock_kallss      r   0test_assert_has_mock_calls_on_async_mock_no_specz@AsyncMockAssert.test_assert_has_mock_calls_on_async_mock_no_spec[  s   %% 	 	IIKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	B|n-{;;;%% 	 	IIe	 	 	 	 	 	 	 	 	 	 	 	 	 	 	%% 	 	IIe	 	 	 	 	 	 	 	 	 	 	 	 	 	 	vvtE{{DKK8
-z:::::s0   1551BBB-CCCc                    t          t                    }t          |           5  |                                 d d d            n# 1 swxY w Y   ddi fg}|                     |j        j        |           |                     |j        t          j                    g           t          |           5  |                    ddddd           d d d            n# 1 swxY w Y   t                      t          ddddd          g}t          j                    t          j        ddddd          g}|                     |j        j        |           |                     |j        |           d S )	Nr  r   rn   rr   rt      r0  )r8   r9   )r   r   rG   r#   rv   r  r
   )r   a_class_mockr  method_kallsr  s        r   2test_assert_has_mock_calls_on_async_mock_with_speczBAsyncMockAssert.test_assert_has_mock_calls_on_async_mock_with_spech  s    ,,%% 	( 	(%%'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(B|n2={KKK043D3F3F2GHHH%% 	9 	9%%aAa%888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9Q1Q 7 7 78'))4+<Q1Q+O+O+OP
2=|LLL0*=====s#   AA	A	2CC Cc                 
   t          |           5  | j                            dd            d d d            n# 1 swxY w Y   t          |           5  | j        j                            dt          j                   d d d            n# 1 swxY w Y   |                     | j        j        dddd ifdd	d
t          j        ifgd           |                     | j        j        j        dd	d
t          j        ifgd           d S )Nrt   )fishrC  )cake	something)rt   r#  zsomething_else.something)rC  r$  z#method calls not recorded correctly)rG   r   r%  something_elser   Cakerv   method_callsr   s    r    test_async_method_calls_recordedz0AsyncMockAssert.test_async_method_calls_recordedw  s   %% 	. 	.I---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.%% 	F 	FI$..qx}.EEE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	/$/'/FG2
 2		3 	3 	3
 	1>&vx}.EFG>	@ 	@ 	@ 	@ 	@s   9= =,BBBc                 F     fd} | j                    t                     5                                     d d d            n# 1 swxY w Y   t                     5                        dd           d d d            n# 1 swxY w Y   t                     5                        d           d d d            n# 1 swxY w Y    j                                           | j                    t          t                    }t                     5  |                                 d d d            n# 1 swxY w Y   t                     5  |                    dd           d d d            n# 1 swxY w Y   |                                  ||           d S )Nc                     d}|D ]^}t          | |          }                    |t                                         |t                                         |g            _d S )N)rr  r(  r  )getattrrc   r   listrv   )r   namesr  attrr   s       r   assert_attrsz:AsyncMockAssert.test_async_arg_lists.<locals>.assert_attrs  su    DE + +tT**%%dI666%%dD111  r****	+ +r   rn   rr   rt   )r8   )r   rG   r   r   r   r#   )r   r0  r  s   `  r   test_async_arg_listsz$AsyncMockAssert.test_async_arg_lists  s   	+ 	+ 	+ 	+ 	+ 	TY%% 	 	IIKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	%% 	 	IIaOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	%% 	 	IIINNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 		TY:&&%% 	" 	"!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"%% 	( 	(Q'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	VsY   AAA!BBBCCCD99D= D=E77E;>E;c                    |                      t                    5  | j                                         d d d            n# 1 swxY w Y   t	          |                                            | j                                         d S r   )r   r   r   r   r   r  r   s    r   test_assert_awaitedz#AsyncMockAssert.test_assert_awaited  s    ~.. 	' 	'I$$&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	D!!"""	  """""s   AAAc                    |                      t                    5  | j                                         d d d            n# 1 swxY w Y   t	          |                                            | j                                         t	          |                                            |                      t                    5  | j                                         d d d            d S # 1 swxY w Y   d S r   )r   r   r   r   r   r  r   s    r   test_assert_awaited_oncez(AsyncMockAssert.test_assert_awaited_once  sU   ~.. 	, 	,I))+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	D!!"""	%%'''D!!"""~.. 	, 	,I))+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s#   AAAC((C,/C,c                    d}|                      t          |          5  | j                            d           d d d            n# 1 swxY w Y   t	          |                                            d}|                      t          |          5  | j                            d           d d d            n# 1 swxY w Y   t	          |                     d                     | j                            d           t	          |                     d                     |                     t                    5  | j                            d           d d d            d S # 1 swxY w Y   d S )NzNot awaitedr   zexpected await not foundSomethingElse)r>  r   r   r   r   r  r   )r   msgs     r   test_assert_awaited_withz(AsyncMockAssert.test_assert_awaited_with  s   ##NC88 	1 	1I))%000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	D!!"""(##NC88 	1 	1I))%000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	D&&'''	%%e,,,D00111~.. 	1 	1I))%000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s5   AA	A	B55B9<B98E  E$'E$c                    |                      t                    5  | j                            d           d d d            n# 1 swxY w Y   t	          |                     d                     | j                            d           t	          |                     d                     |                      t                    5  | j                            d           d d d            d S # 1 swxY w Y   d S r  )r   r   r   r   r   r  r   s    r   test_assert_awaited_once_withz-AsyncMockAssert.test_assert_awaited_once_with  s_   ~.. 	6 	6I..u555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	D&&'''	**5111D&&'''~.. 	6 	6I..u555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s#   AA	AC--C14C1c                 j   |                      t                    5  | j                            d           d d d            n# 1 swxY w Y   t	          |                     d                     |                      t                    5  | j                            d           d d d            n# 1 swxY w Y   t	          |                     d                     | j                            d           t	          |                     d                     | j                            d           d S )Nr   r  r7  )r   r   r   r   r   r  r   s    r   test_assert_any_waitz$AsyncMockAssert.test_assert_any_wait  s   ~.. 	. 	.I&&u---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	D&&'''~.. 	. 	.I&&u---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	D&&'''	""5)))D00111	""5)))))s#   AA	A	B00B47B4c                    t          d          t          d          g}|                     t                    5 }| j                            |           d d d            n# 1 swxY w Y   |                     t          |j        j                  d           t          | 
                    d                     |                     t                    5  | j                            |           d d d            n# 1 swxY w Y   t          | 
                    d                     |                     t                    5  | j                            |           d d d            n# 1 swxY w Y   t          | 
                    d                     | j                            |           t          | 
                    d                     | j                            |           d S )Nr   r  rn   r7  )r
   r   r   r   rq  rv   len	exceptionr  r   r  )r   callsr'  s      r   test_assert_has_awaits_no_orderz/AsyncMockAssert.test_assert_has_awaits_no_order  s[   ed5kk*~.. 	/"I''...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/R\.//333D&&'''~.. 	/ 	/I''...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	D&&'''~.. 	/ 	/I''...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	D&&'''	##E***D00111	##E*****s5   A  A$'A$C;;C?C?E))E-0E-c                 R    G d d          }t          |                      |            d                     | j                            t	          t
          d          g           | j                            t
          d           | j                            t
          d           d S )Nc                       e Zd Zd ZdS )9AsyncMockAssert.test_awaits_asserts_with_any.<locals>.Fooc                     d S r   r   r   others     r   __eq__z@AsyncMockAssert.test_awaits_asserts_with_any.<locals>.Foo.__eq__  r!   r   Nr,   r-   r.   rI  r   r   r   FoorE            )))))r   rK  rn   )r   r  r   rq  r
   r	   r   r   )r   rK  s     r   test_awaits_asserts_with_anyz,AsyncMockAssert.test_awaits_asserts_with_any  s    	* 	* 	* 	* 	* 	* 	* 	* 	Dq))***	##T#q\\N333	%%c1---	""3*****r   c                 L    G d d          }t          |          fd}t           | |            d                                         t          t          d          g                               t          d                               t          d           d S )Nc                       e Zd Zd ZdS )BAsyncMockAssert.test_awaits_asserts_with_spec_and_any.<locals>.Fooc                     d S r   r   rG  s     r   rI  zIAsyncMockAssert.test_awaits_asserts_with_spec_and_any.<locals>.Foo.__eq__   r!   r   NrJ  r   r   r   rK  rP    rL  r   rK  r   c                  "   K    |   d {V  d S r   r   )r  mock_with_specs    r   _custom_mock_runnable_testzYAsyncMockAssert.test_awaits_asserts_with_spec_and_any.<locals>._custom_mock_runnable_test  s,       .$''''''''''r   rn   )r   r   rq  r
   r	   r   r   )r   rK  rT  rS  s      @r   %test_awaits_asserts_with_spec_and_anyz5AsyncMockAssert.test_awaits_asserts_with_spec_and_any  s    	* 	* 	* 	* 	* 	* 	* 	* #,,,	( 	( 	( 	( 	( 	&&ssuua00111(($sA,,888**3222''Q/////r   c                    t          d          t          d          g}|                     t                    5  | j                            |d           d d d            n# 1 swxY w Y   t          |                     d                     |                     t                    5  | j                            |d           d d d            n# 1 swxY w Y   t          |                     d                     |                     t                    5  | j                            |d           d d d            n# 1 swxY w Y   t          |                     d                     | j                            |d           t          |                     d                     | j                            |d           d S )Nr   r  T)	any_orderbamfqux)r
   r   r   r   rq  r   r  )r   rA  s     r   test_assert_has_awaits_orderedz.AsyncMockAssert.test_assert_has_awaits_ordered  sV   ed5kk*~.. 	? 	?I'''>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	D&&'''~.. 	? 	?I'''>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	D''(((~.. 	? 	?I'''>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	D&&'''	##ET#:::D&&'''	##ET#:::::s5   A""A&)A&)CCCEE	Ec                    | j                                          t          |                                            |                     t
                    5  | j                                          d d d            d S # 1 swxY w Y   d S r   )r   r   r   r  r   r   r   s    r   test_assert_not_awaitedz'AsyncMockAssert.test_assert_not_awaited  s    	$$&&&D!!"""~.. 	+ 	+I((***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+s   A<<B B c                    dd}t          |          | _        t          |                     d                     |                     t
          d                    t          j        d                              5 }| j        	                    t                      g           d d d            n# 1 swxY w Y   |                     |j        j                   |                     t
          d                    t          j        d                              5 }| j        	                    t                      t          dd          g           d d d            n# 1 swxY w Y   |                     |j        j        t                     d S )	Nc                 
   K   d S r   r   r"  s    r   fzIAsyncMockAssert.test_assert_has_awaits_not_matching_spec_error.<locals>.f'  r$   r   r   rn   z^{}$z6Awaits not found.
Expected: [call()]
Actual: [call(1)]zError processing expected awaits.
Errors: [None, TypeError('too many positional arguments')]
Expected: [call(), call(1, 2)]
Actual: [call(1)]rr   r   )r   r   r   r  r>  r   formatreescaperq  r
   r   r@  	__cause__rc   r  )r   r_  r'  s      r   .test_assert_has_awaits_not_matching_spec_errorz>AsyncMockAssert.test_assert_has_awaits_not_matching_spec_error&  s   !!!!1%%%	D""#####I 2 3 34 45 5 	2
 9;I''111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	",0111##I,- -. ./ / 		> 35I''a(<===		> 		> 		> 		> 		> 		> 		> 		> 		> 		> 		> 		> 		> 		> 		> 	bl4i@@@@@s$   <(B00B47B47EE!$E!N)r,   r-   r.   r  r  r   r  r  r
  r  r  r  r  r  r!  r)  r1  r3  r5  r9  r;  r=  rB  rM  rU  rZ  r\  rd  r   r   r   r  r    s            ) ) )  / / /5 5 5 	( 	( 	(0 0 0+ + +& & &/ / /; ; ;> > >@ @ @  :# # #	, 	, 	,1 1 1"	6 	6 	6* * *+ + +*+ + +0 0 0; ; ;&+ + +A A A A Ar   r  __main__)1r   rD   rW   ra  r   
contextlibr   rF   r   requires_working_socketr   r   r   unittest.mockr	   r
   r   r   r   r   r   r   r   r   r   r   r2   r6   r;   r=   rQ   r?   r,   r^   r  rG   TestCaserI   r|   r   r   r   r  r*  rw  r  r  r  r   r   r   r   <module>rj     sj    				  				  % % % % % %        t , , , , , , , , , , , , , , , , , ,G G G G G G G G G G G G G G G G G G G G G G G G( ( (	* 	* 	* 	* 	* 	* 	* 	*           + + +       &    )))+++   :A :A :A :A :Ah/ :A :A :Az/ / / / /x( / / /d4 4 4 4 4H% 4 4 4BQ Q Q Q Q) Q Q Qhf+ f+ f+ f+ f+H% f+ f+ f+R1 1 1 1 1x( 1 1 18wH wH wH wH wH, wH wH wHt$? $? $? $? $?) $? $? $?Lo) o) o) o) o)h/ o) o) o)dB6 B6 B6 B6 B6) B6 B6 B6JDA DA DA DA DAh' DA DA DAN
 zHMOOOOO r   