
    daf                        d dl Z d dlZd dlmZ d dlZd dlZd dlmZ d dlm	Z	m
Z
 d dl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mZ dZej8                  e   Zd	ez  Zdd
Z ejB                  a"ejF                  Z$ G d de%      Z&dez  Z'e&fdZ( G d de%      Z) G d dejT                        Z+edk(  r ejX                          yy)    N)OrderedDict)support)	SomeClassis_instance)DirsOnSysPath)uncache)NonCallableMockCallableMixinsentinel	MagicMockMockNonCallableMagicMockpatch_patchDEFAULTcall_get_targetbuiltinsz%s.PTModulec                 h      G  fddt               }|s fd} fd}||_        ||_         |       S )Nc                       e Zd Z fdZy)_get_proxy.<locals>.Proxyc                     t        |      S N)getattrselfnameobjs     @/root/Python-3.12.4/Lib/test/test_unittest/testmock/testpatch.py__getattr__z%_get_proxy.<locals>.Proxy.__getattr__   s    3%%    N)__name__
__module____qualname__r    )r   s   r   Proxyr      s    	&r!   r%   c                      t        ||       y r   )setattr)r   r   valuer   s      r   __setattr__z_get_proxy.<locals>.__setattr__"   s    Cu%r!   c                     t        |       y r   )delattrr   s     r   __delattr__z_get_proxy.<locals>.__delattr__$   s    Cr!   )objectr)   r,   )r   get_onlyr%   r)   r,   s   `    r   
_get_proxyr/      s5    & & 	&	''7Nr!   c                   X    e Zd Zd Zd Zd ZdZed        Ze	d        Z
 G d de      Zy	)
Fooc                      y r    r   as     r   __init__zFoo.__init__1   s    4r!   c                      y r   r3   r4   s     r   fzFoo.f2   s    Dr!   c                      y r   r3   r   s    r   gzFoo.g3   s    r!   barc                       y r   r3   r3   r!   r   static_methodzFoo.static_method6   s    r!   c                      y r   r3   )clss    r   class_methodzFoo.class_method9   s    r!   c                       e Zd Zd Zy)Foo.Barc                      y r   r3   r:   s    r   r5   z	Foo.Bar.a=   s    Tr!   Nr"   r#   r$   r5   r3   r!   r   BarrC   <   s    r!   rF   N)r"   r#   r$   r6   r8   r;   foostaticmethodr>   classmethodrA   r-   rF   r3   r!   r   r1   r1   0   s8    
C  f r!   r1   z%s.Fooc                      y r   r3   r5   bs     r   functionrM   B   s    r!   c                   *    e Zd Zd Zd Zd Zd Zd Zy)	Containerc                     i | _         y r   valuesr:   s    r   r6   zContainer.__init__F   s	    r!   c                      | j                   |   S r   rQ   r   r   s     r   __getitem__zContainer.__getitem__I   s    {{4  r!   c                 "    || j                   |<   y r   rQ   )r   r   r(   s      r   __setitem__zContainer.__setitem__L   s    !Dr!   c                     | j                   |= y r   rQ   rT   s     r   __delitem__zContainer.__delitem__O   s    KKr!   c                 ,    t        | j                        S r   )iterrR   r:   s    r   __iter__zContainer.__iter__R   s    DKK  r!   N)r"   r#   r$   r6   rU   rW   rY   r\   r3   r!   r   rO   rO   E   s    !"!r!   rO   c                      e Zd Zdvd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 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. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d4 Z6d5 Z7d6 Z8d7 Z9d8 Z:d9 Z;d: Z<d; Z=d< Z>d= Z?d> Z@d? ZAd@ ZBdA ZCdB ZDdC ZEdD ZFdE ZGdF ZHdG ZIdH ZJdI ZKdJ ZLdK ZMdL ZNdM ZOdN ZPdO ZQdP ZRdQ ZSdR ZTdS ZUdT ZVdU ZWdV ZXdW ZYdX ZZ e[dYdZ      d[        Z\ e[dYd\      d]        Z]d^ Z^d_ Z_d` Z`da Zadb Zbdc Zcdd Zdde Zedf Zfdg Zgdh Zhdi Zidj Zjdk Zkdl Zldm Zmdn Zndo Zodp Zpdq Zqdr Zrds Zsdt Ztyu)w	PatchTestc                     t         }|st        }| j                  t        |       | j	                  t        ||             | j                  t        |t                     y r   )r   r	   assertRaises	TypeError
assertTruer   assertFalser
   )r   r   magic	MockClasss       r   assertNotCallablezPatchTest.assertNotCallableY   sG    (	'I)S)C34S-89r!   c                       G d dt               t        j                   dt        j                         fd       } |         j	                  j
                  t        j                  d       y )Nc                   $    e Zd Zej                  Zy)4PatchTest.test_single_patchobject.<locals>.SomethingNr"   r#   r$   r   Original	attributer3   r!   r   	Somethingri   d        ))Ir!   rm   rl   c                  \    j                   j                  t        j                  d       y N	unpatchedassertEqualrl   r   Patchedrm   r   s   r   testz/PatchTest.test_single_patchobject.<locals>.testg   s!    Y00(2B2BKPr!   patch not restoredr-   r   r   rt   rs   rl   rk   r   rv   rm   s   ` @r   test_single_patchobjectz!PatchTest.test_single_patchobjectc   sa    	* 	* 
ih.>.>	?	Q 
@	Q 	,,h.?.?-	/r!   c                     d}| j                  t        |      5  t        j                  dd       d d d        y # 1 sw Y   y xY w)Nz>'Something' must be the actual object to be patched, not a strrm   do_something)assertRaisesRegexra   r   r-   )r   msgs     r   &test_patchobject_with_string_as_targetz0PatchTest.test_patchobject_with_string_as_targeto   s:    N##Is3 	6LLn5	6 	6 	6s	   9Ac                       G d dt               t        j                   dd        fd       } |         j                  j                  t        j
                  d       y )Nc                   $    e Zd Zej                  Zy)7PatchTest.test_patchobject_with_none.<locals>.SomethingNrj   r3   r!   r   rm   r   u   rn   r!   rm   rl   c                  >    j                   j                  d       y rp   )assertIsNonerl   ru   s   r   rv   z2PatchTest.test_patchobject_with_none.<locals>.testx   s    i11;?r!   rw   )r-   r   rs   rl   r   rk   ry   s   ` @r   test_patchobject_with_nonez$PatchTest.test_patchobject_with_nonet   sZ    	* 	* 
id	3	@ 
4	@ 	,,h.?.?-	/r!   c                      G d dt               t        j                   dt        j                        t        j                   dt        j                         fd              } |         j                  j                  t        j                  d        j                  j                  t        j                  d       y )Nc                   <    e Zd Zej                  Zej                  Zy)6PatchTest.test_multiple_patchobject.<locals>.SomethingNr"   r#   r$   r   rk   rl   	Original2next_attributer3   r!   r   rm   r           ))I%//Nr!   rm   rl   r   c                      j                   j                  t        j                  d       j                   j                  t        j
                  d       y rp   )rs   rl   r   rt   r   Patched2ru   s   r   rv   z1PatchTest.test_multiple_patchobject.<locals>.test   sG     Y00(2B2B(*Y55x7H7H(*r!   rw   )
r-   r   r   rt   r   rs   rl   rk   r   r   ry   s   ` @r   test_multiple_patchobjectz#PatchTest.test_multiple_patchobject   s    	0 	0 
ih.>.>	?	i!183D3D	E	* 
F 
@	* 	,,h.?.?-	/1183E3E-	/r!   c                     t         }t        dt        z  t        j                        d        }	 t        j
                  a  |        | j                  t         t        j
                         |a y # |a w xY w)N%s.somethingc                       y r   r3   r3   r!   r   rv   z8PatchTest.test_object_lookup_is_quite_lazy.<locals>.test   s    r!   )	somethingr   r"   r   
Something2replacement_valuers   r   originalrv   s      r    test_object_lookup_is_quite_lazyz*PatchTest.test_object_lookup_is_quite_lazy   sa    	~((*=*=	>	 
?		! 22IFY(B(BC IIs   ;A- -A1c                     t        dt        z  t        j                         fd       } |         j	                  t
        j                  t        j                  d       t        dt        z  t        j                        t        dt        z  t        j                         fd              } j	                  t
        j                  t        j                  d        j	                  t
        j                  t        j                  d        |         j	                  t
        j                  t        j                  d        j	                  t
        j                  t        j                  d       t               }t        j                  |_        t        dt        z  |       fd       } |         |         j                  t        |d       y )Nr   c                  d     j                  t        j                  t        j                  d       y rp   )rs   PTModuler   r   r   r:   s   r   rv   z"PatchTest.test_patch.<locals>.test   s$    X//1D1D(*r!   rw   z%s.something_elsec                       j                  t        j                  t        j                  d        j                  t        j
                  t        j                  d       y rp   )rs   r   r   r   r   something_elseSomethingElser:   s   r   rv   z"PatchTest.test_patch.<locals>.test   sG     X//1D1D(*X44h6L6L(*r!   %s.openc                  \     j                  t        dd      t        j                  d       y )Nfilenamerzopen not patched)rs   openr   Handler:   s   r   rv   z"PatchTest.test_patch.<locals>.test   s#    T*c2HOO/1r!   )r   r"   r   r   rs   r   r   rm   r   r   r   r   return_valuebuiltin_stringassertNotEqualr   )r   rv   mocks   `  r   
test_patchzPatchTest.test_patch   sp   	~((*=*=	>	* 
?	* 	++X-?-?-	/ 
~((*=*=	>	"X-x/E/E	F	* 
G 
?	* 	++X-?-?-	/00(2H2H-	/ 	++X-?-?-	/00(2H2H-	/ v$OO	y>)4	0	1 
1	1 	D$(<=r!   c                      t        dt        z  t        j                         fd       } |         j	                  t
        j                  j                  d       y )Nz%s.SomeClass.class_attributec                  x     j                  t        j                  j                  t        j
                  d       y rp   )rs   r   r   class_attributer   ClassAttributer:   s   r   rv   z2PatchTest.test_patch_class_attribute.<locals>.test   s-     X//??%44kCr!   rw   )r   r"   r   r   r   r   r   r   r   rv   s   ` r   test_patch_class_attributez$PatchTest.test_patch_class_attribute   sS    	-8&&
(	C
(	C 	(,,<<.	0r!   c                      G d dt               t        j                   d       fd       } |        t        j                   d      t        j                   d       fd              }d x |t        j                  t        j                        \   |t        j                  t        j                         y )Nc                   <    e Zd Zej                  Zej                  Zy):PatchTest.test_patchobject_with_default_mock.<locals>.TestN)r"   r#   r$   r   rk   r   r   
something2r3   r!   r   Testr      s     ))I!++Jr!   r   r   c                 n    j                  | j                  d       j                  | t        d       y )N"Mock not passed into test function.patch with two arguments did not create a mock)rs   r   assertIsInstancer   )r   r   r   s    r   rv   z:PatchTest.test_patchobject_with_default_mock.<locals>.test   s3    T4>>AC!!$	LNr!   r   c                    j                  | t        j                  d       j                  |t        j                  d       j                  |j                  d       j                  |j
                  d       j                  |t        d       j                  |t        d       j                  |d       j                  |d       ||fS )Nz0Patched function didn't receive initial argumentz/Patched function didn't receive second argumentr   z)Second Mock not passed into test functionr   zunexpected value for mock1)	rs   r   this1this2r   r   r   r   r   )r   r   mock1mock2r   
outerMock1
outerMock2r   s       r   rv   z:PatchTest.test_patchobject_with_default_mock.<locals>.test   s     UHNNOQUHNNNPUDOOACUDNNHJ!!%LN!!%LN 
E3OP
E3OP%<r!   )r-   r   r   r   r   )r   rv   r   r   r   s   ` @@@r   "test_patchobject_with_default_mockz,PatchTest.test_patchobject_with_default_mock   s    	,6 	, 
dK	(	N 
)	N 		dK	(	dL	)	  
* 
)	 & #'&
Z!%hnnhnn!E
J 	X^^X^^,r!   c                 T     t        dt        z  t               fd       } |        y )N%s.SomeClassspecc                     j                  t        |        j                  t        t        j                  t
                     j                  t        d        y )Nc                  "    t         j                  S r   r   
not_wibbler3   r!   r   <lambda>z>PatchTest.test_patch_with_spec.<locals>.test.<locals>.<lambda>
      i6J6J r!   rs   r   rb   r   wibbler   r`   AttributeErrorMockSomeClassr   s    r   rv   z,PatchTest.test_patch_with_spec.<locals>.test  =    Y6OOK	(8(8)DEn.JKr!   )r   r"   r   r   s   ` r   test_patch_with_speczPatchTest.test_patch_with_spec  s*    	~(y	9	L 
:	L
 	r!   c                 d     t        j                  t        dt               fd       } |        y )Nr   r   c                     j                  t        j                  |        j                  t	        t        j                  j
                  t                     j                  t        d        y )Nc                  6    t         j                  j                  S r   r   r   r   r3   r!   r   r   zDPatchTest.test_patchobject_with_spec.<locals>.test.<locals>.<lambda>      i&?&?&J&J r!   	rs   r   r   rb   r   r   r   r`   r   MockAttributer   s    r   rv   z2PatchTest.test_patchobject_with_spec.<locals>.test  Q    Y66FOOK	(A(A(H(H'02 3nJLr!   r   r-   r   r   s   ` r   test_patchobject_with_specz$PatchTest.test_patchobject_with_spec  s-    	i!2	C	L 
D	L 	r!   c                 N     t        dt        z  dg       fd       } |        y )Nr   r   r   c                     j                  t        |        j                  t        t        j                  t
                     j                  t        d        y )Nc                  "    t         j                  S r   r   r3   r!   r   r   zFPatchTest.test_patch_with_spec_as_list.<locals>.test.<locals>.<lambda>   r   r!   r   r   s    r   rv   z4PatchTest.test_patch_with_spec_as_list.<locals>.test  r   r!   r   r"   r   s   ` r   test_patch_with_spec_as_listz&PatchTest.test_patch_with_spec_as_list  s,    	~(z	:	L 
;	L
 	r!   c                 ^     t        j                  t        ddg       fd       } |        y )Nr   r   r   c                     j                  t        j                  |        j                  t	        t        j                  j
                  t                     j                  t        d        y )Nc                  6    t         j                  j                  S r   r   r3   r!   r   r   zLPatchTest.test_patchobject_with_spec_as_list.<locals>.test.<locals>.<lambda>,  r   r!   r   r   s    r   rv   z:PatchTest.test_patchobject_with_spec_as_list.<locals>.test&  r   r!   r   r   s   ` r   "test_patchobject_with_spec_as_listz,PatchTest.test_patchobject_with_spec_as_list%  s/    	i!2(	D	L 
E	L 	r!   c                 x     t        dt        z        t        dt        z  dg       fd              } |        y )Nr   r   r   r   c                     j                  t        |        j                  t        t        j                  t
                     j                  t        d        y )Nc                  "    t         j                  S r   r   r3   r!   r   r   zMPatchTest.test_nested_patch_with_spec_as_list.<locals>.test.<locals>.<lambda>8  r   r!   r   )r   MockOpenr   s     r   rv   z;PatchTest.test_nested_patch_with_spec_as_list.<locals>.test3  s?     Y6OOK	(8(8)DEn.JKr!   )r   r   r"   r   s   ` r   #test_nested_patch_with_spec_as_listz-PatchTest.test_nested_patch_with_spec_as_list1  s>    	y>)	*	~(z	:	L 
; 
+	L 	r!   c                 L     t        dt        z  d       fd       } |        y )Nr   Tr   c                 ~     j                  t                 j                   j                  t         fd       y )Nc                       j                   S r   r   r   s   r   r   zIPatchTest.test_patch_with_spec_as_boolean.<locals>.test.<locals>.<lambda>C      m6N6N r!   rs   r   r   r`   r   r   s   `r   rv   z7PatchTest.test_patch_with_spec_as_boolean.<locals>.test=  -    Y6  n.NOr!   r   r   s   ` r   test_patch_with_spec_as_booleanz)PatchTest.test_patch_with_spec_as_boolean<  s*    	~(t	4	P 
5	P 	r!   c                 \     t        j                  t        dd       fd       } |        y )Nr   Tr   c                 ~     j                  t                 j                   j                  t         fd       y )Nc                       j                   S r   r   r   s   r   r   zPPatchTest.test_patch_object_with_spec_as_boolean.<locals>.test.<locals>.<lambda>O  r   r!   r   r   s   `r   rv   z>PatchTest.test_patch_object_with_spec_as_boolean.<locals>.testI  r   r!   )r   r-   r   r   s   ` r   &test_patch_object_with_spec_as_booleanz0PatchTest.test_patch_object_with_spec_as_booleanH  s+    	h$	7	P 
8	P 	r!   c                 L     t        dt        z  d       fd       } |        y )Nr   Tr   c                     j                  t        | t                      |        j                         j                   j                  t        fd       y )Nc                       j                   S r   r   )instances   r   r   zVPatchTest.test_patch_class_acts_with_spec_is_inherited.<locals>.test.<locals>.<lambda>]  s    h6I6I r!   )rb   r   r   rf   r   r`   r   )r   r   r   s    @r   rv   zDPatchTest.test_patch_class_acts_with_spec_is_inherited.<locals>.testU  sC    OOKyAB$H""8,OOn.IJr!   r   r   s   ` r   ,test_patch_class_acts_with_spec_is_inheritedz6PatchTest.test_patch_class_acts_with_spec_is_inheritedT  s*    	~(t	4	K 
5	K 	r!   c                      t        dt        z  t        j                  d       fd       } |         j	                  t
        d        y )N
%s.froobleTcreatec                  N     j                  t        t        j                         y r   )rs   froobler   Froobler:   s   r   rv   zLPatchTest.test_patch_with_create_mocks_non_existent_attributes.<locals>.testc  s    Wh&6&67r!   c                      t         S r   r  r3   r!   r   r   zPPatchTest.test_patch_with_create_mocks_non_existent_attributes.<locals>.<lambda>h      W r!   )r   r   r   r  r`   	NameErrorr   s   ` r   4test_patch_with_create_mocks_non_existent_attributesz>PatchTest.test_patch_with_create_mocks_non_existent_attributesb  sA    	|n,h.>.>t	L	8 
M	8 	)_5r!   c                      t        j                  t        dt        j                  d       fd       } |         j                  t        t        d             y )Nr  Tr   c                  b     j                  t        j                  t        j                         y r   )rs   r   r  r   r  r:   s   r   rv   zRPatchTest.test_patchobject_with_create_mocks_non_existent_attributes.<locals>.testl  s    Y..0@0@Ar!   )r   r-   r   r   r  rc   hasattrr   s   ` r   :test_patchobject_with_create_mocks_non_existent_attributeszDPatchTest.test_patchobject_with_create_mocks_non_existent_attributesk  sI    	iH,<,<T	J	B 
K	B 	I67r!   c                     | j                  t              5  t        dt        z  t        j
                        d        } |        d d d        | j                  t        d        y # 1 sw Y   !xY w)Nr   c                       y r   r3   r3   r!   r   rv   z9PatchTest.test_patch_wont_create_by_default.<locals>.testv      r!   c                      t         S r   r  r3   r!   r   r   z=PatchTest.test_patch_wont_create_by_default.<locals>.<lambda>z  r  r!   )r`   r   r   r   r   r  r  r   s     r   !test_patch_wont_create_by_defaultz+PatchTest.test_patch_wont_create_by_defaultt  s]    ~. 	<.0(2B2BC DF		
 	)_5	 	s   /A%%A.c                    | j                  t              5  t        j                  t        dt
        j                        d        } |        d d d        | j                  t        t        d             y # 1 sw Y   )xY w)Nordc                       y r   r3   r3   r!   r   rv   z?PatchTest.test_patchobject_wont_create_by_default.<locals>.test  r  r!   )	r`   r   r   r-   r   r   r  rc   r  r   s     r   'test_patchobject_wont_create_by_defaultz1PatchTest.test_patchobject_wont_create_by_default}  sb    ~. 	\\)UH,<,<= >F	 	E23		 	s   7A55A>c                     t        t        dz         d        }t        t        dz         d        }| j                   |       d       | j                   |       d       y )Nz.ordc                 &    d| _         t        d      S )Ne   c)r   r  )mock_ords    r   test_ordz>PatchTest.test_patch_builtins_without_create.<locals>.test_ord  s    $'H!s8Or!   z.openc                     | j                   }d|j                  _         t        d      }|j                         }|j                          |S )Nabcdzdoesnotexists.txt)r   readr   close)	mock_openmfobjdatas       r   	test_openz?PatchTest.test_patch_builtins_without_create.<locals>.test_open  s=    &&A"(AFF+,D99;DJJLKr!   r  r  r   r"   rs   )r   r  r$  s      r   "test_patch_builtins_without_createz,PatchTest.test_patch_builtins_without_create  sa    	x		 
 	 
x	 	 
!	 	S)f-r!   c                       G d dt               t        j                   dt        d              fd       } |         j                  j	                         t
        j                         y )Nc                       e Zd Zed        Zy)5PatchTest.test_patch_with_static_methods.<locals>.Fooc                  "    t         j                  S r   )r   Staticr3   r!   r   wootz:PatchTest.test_patch_with_static_methods.<locals>.Foo.woot  s    &r!   N)r"   r#   r$   rH   r,  r3   r!   r   r1   r)    s    ' 'r!   r1   r,  c                  "    t         j                  S r   )r   rt   r3   r!   r   r   z:PatchTest.test_patch_with_static_methods.<locals>.<lambda>  s    8H8H r!   c                  b    j                   j                         t        j                         y r   )rs   r,  r   rt   )r1   r   s   r   	anonymousz;PatchTest.test_patch_with_static_methods.<locals>.anonymous  s    SXXZ)9)9:r!   )r-   r   rH   rs   r,  r   r+  )r   r/  r1   s   ` @r   test_patch_with_static_methodsz(PatchTest.test_patch_with_static_methods  sV    	'& 	'
 
c6<0H#I	J	; 
K	;X__5r!   c                      t         j                  }t        j                  t         dd       fd       } |         j	                  t         j                  |       y )Nr1   c                  F     j                  t        j                  d       y Nr1   )rs   r   r1   r:   s   r   r/  z-PatchTest.test_patch_local.<locals>.anonymous  s    X\\51r!   )r   r1   r   r-   rs   )r   rG   r/  s   `  r   test_patch_localzPatchTest.test_patch_local  sD    ll	hu	-	2 
.	2s+r!   c                       G d dt               } |       t        j                  _        t        j                   dd       fd       } |         j	                  j                  t        j                         y )Nc                       e Zd ZdZy)'PatchTest.test_patch_slots.<locals>.Foo)r1   N)r"   r#   r$   	__slots__r3   r!   r   r1   r7    s     Ir!   r1   c                  >    j                   j                  d       y r3  )rs   r1   rG   r   s   r   r/  z-PatchTest.test_patch_slots.<locals>.anonymous  s    SWWe,r!   )r-   r   r1   r   rs   )r   r1   r/  rG   s   `  @r   test_patch_slotszPatchTest.test_patch_slots  s_    	!& 	! e,,	c5%	(	- 
)	-(,,/r!   c                 D     G d dt                G  fddt               } t        j                   dt        j                        |      } |       }|j	                          |j                           j                  j                  t        j                  d       y )Nc                   $    e Zd Zej                  Zy)=PatchTest.test_patchobject_class_decorator.<locals>.SomethingNrj   r3   r!   r   rm   r>    rn   r!   rm   c                   &    e Zd Z fdZ fdZy)7PatchTest.test_patchobject_class_decorator.<locals>.Fooc                 \    j                  j                  t        j                  d       y rp   rr   
other_selfrm   r   s    r   test_methodzCPatchTest.test_patchobject_class_decorator.<locals>.Foo.test_method  s$      !4!4h6F6F!,.r!   c                 \    j                  j                  t        j                  d       y Nznon-test method patched)rs   rl   r   rk   rB  s    r   not_test_methodzGPatchTest.test_patchobject_class_decorator.<locals>.Foo.not_test_method  s$      !4!4h6G6G!:<r!   N)r"   r#   r$   rD  rG  ru   s   r   r1   r@    s    .<r!   r1   rl   rw   )	r-   r   r   rt   rD  rG  rs   rl   rk   )r   r1   r8   rm   s   `  @r    test_patchobject_class_decoratorz*PatchTest.test_patchobject_class_decorator  sz    	* 	*	<& 	< Eell9k83C3CDSIE		,,h.?.?-	/r!   c                 x     G d dt               } G  fddt               } t        dt        z        |      } |       }|j                          |j	                           j                  |j                  t        j                  d        j                  t        j                  t        j                  d       y )Nc                   $    e Zd Zej                  Zy)7PatchTest.test_patch_class_decorator.<locals>.SomethingNrj   r3   r!   r   rm   rK    rn   r!   rm   c                   &    e Zd ZdZ fdZ fdZy)1PatchTest.test_patch_class_decorator.<locals>.Foowhateverc                 H    j                  t        j                  |d       y rp   )rs   r   r   )rC  mock_somethingr   s     r   rD  z=PatchTest.test_patch_class_decorator.<locals>.Foo.test_method  s      !3!3^!,.r!   c                 d    j                  t        j                  t        j                  d       y rF  )rs   r   r   r   rm   )rC  r   s    r   rG  zAPatchTest.test_patch_class_decorator.<locals>.Foo.not_test_method  s$      !3!3X5G5G!:<r!   N)r"   r#   r$   test_class_attrrD  rG  r:   s   r   r1   rM    s    (O.<r!   r1   r   rw   )r-   r   r"   rD  rG  rs   rl   r   rk   r   r   rm   )r   rm   r1   r8   s   `   r   test_patch_class_decoratorz$PatchTest.test_patch_class_decorator  s    	* 	*		<& 		< /eNX-.s3E		,,h.?.?-	/++X-?-?-	/r!   c                 6     G d dt               t        j                   dt        j                        t        j                   dt        j                         fd              } |         j	                  j
                  t        j                  d       y )Nc                   <    e Zd Zej                  Zej                  Zy)3PatchTest.test_patchobject_twice.<locals>.SomethingNr   r3   r!   r   rm   rV    r   r!   rm   rl   c                  \    j                   j                  t        j                  d       y rp   rr   ru   s   r   rv   z.PatchTest.test_patchobject_twice.<locals>.test  s#     Y00(2B2BKPr!   rw   rx   ry   s   ` @r   test_patchobject_twicez PatchTest.test_patchobject_twice  s}    	0 	0 
ih.>.>	?	ih.>.>	?	Q 
@ 
@	Q 	,,h.?.?-	/r!   c                     t               ddj                         }t        j                        fd       } |         j	                  |       t        j                  ddi       fd       } |         j	                  |       t        j                  dg       fd       } |         j	                  |       y )	Nr   initialotherc                       d d<    d= d d<   y N   r5   r[  something elser\  r3   rG   s   r   rv   z'PatchTest.test_patch_dict.<locals>.test      CHI+CLr!   r5   rL   c                  f    j                  t               d       j                   d   d       y Nr_  r5   rL   rs   lenr:  s   r   rv   z'PatchTest.test_patch_dict.<locals>.test  +    SXq)SXs+r!   rK   c                  f    j                  t               d       j                   d   d       y rd  re  r:  s   r   rv   z'PatchTest.test_patch_dict.<locals>.test  rg  r!   r-   copyr   dictrs   r   r   rv   rG   s   `  @r   test_patch_dictzPatchTest.test_patch_dict   s     ([988:	C	, 
	,
 	h'	C#s	$	, 
%	, 	h'	C*	&	, 
'	, 	h'r!   c                 |    t               t               d<   dd<   j                  j                         }t	        j
                        fd       } |         j                  j                  |       t	        j
                  ddi       fd       } |         j                  j                  |       y )Nr[  r   r\  c                       d d<    d= d d<   y r^  r3   ra  s   r   rv   z=PatchTest.test_patch_dict_with_container_object.<locals>.test(  rb  r!   r5   rL   c                  z    j                  t         j                        d       j                   d   d       y rd  )rs   rf  rR   r:  s   r   rv   z=PatchTest.test_patch_dict_with_container_object.<locals>.test2  s/    S_a0SXs+r!   rO   r-   rR   rj  r   rk  rs   rl  s   `  @r   %test_patch_dict_with_container_objectz/PatchTest.test_patch_dict_with_container_object!  s    kI#G::??$	C	, 
	,
 	X.	C#s	$	, 
%	, 	X.r!   c                     t               ddj                         }t        j                  d       fd       } |         j	                  |       t        j                  ddid       fd       } |         j	                  |       t        j                  d	gd       fd
       } |         j	                  |       y )Nr   rZ  Tclearc                  >    j                   i        d d<   d d<   y Nr_  r5   r`  r\  rs   r:  s   r   rv   z2PatchTest.test_patch_dict_with_clear.<locals>.test@  s%    S"%CH+CLr!   r5   rL   c                  .    j                   ddi       y Nr5   rL   rx  r:  s   r   rv   z2PatchTest.test_patch_dict_with_clear.<locals>.testJ      S3*-r!   rK   c                  .    j                   ddi       y rz  rx  r:  s   r   rv   z2PatchTest.test_patch_dict_with_clear.<locals>.testR  r{  r!   ri  rl  s   `  @r   test_patch_dict_with_clearz$PatchTest.test_patch_dict_with_clear<  s     ([988:	Ct	$	, 
%	,
 	h'	C#s4	0	. 
1	. 	h'	C*T	2	. 
3	. 	h'r!   c                     t               t               d<   dd<   j                  j                         }t	        j
                  d       fd       } |         j                  j                  |       t	        j
                  ddid       fd	       } |         j                  j                  |       y )
Nr[  r   r\  Trt  c                  R    j                   j                  i        d d<   d d<   y rw  rs   rR   r:  s   r   rv   zGPatchTest.test_patch_dict_with_container_object_and_clear.<locals>.testb  s)    SZZ,CH+CLr!   r5   rL   c                  B    j                   j                  ddi       y rz  r  r:  s   r   rv   zGPatchTest.test_patch_dict_with_container_object_and_clear.<locals>.testl  s    SZZ#s4r!   rq  rl  s   `  @r   /test_patch_dict_with_container_object_and_clearz9PatchTest.test_patch_dict_with_container_object_and_clear[  s    kI#G::??$	Ct	$	, 
%	,
 	X.	C#s4	0	5 
1	5 	X.r!   c                     ddi}t        j                  |d      5 }| j                  |ddi       d d d        | j                  |ddi       y # 1 sw Y   xY w)Nr5   rL   r  )r5   )r   rk  rs   )r   rG   patcheds      r   "test_patch_dict_as_context_managerz,PatchTest.test_patch_dict_as_context_manageru  sX    CjZZs# 	2wWsCj1	2sCj)	2 	2s   AAc                 <   i }t        dt        z  t                     t        dt        z  t               d      t        j                  t        t                     t        j                  |      d                             }| j                  |j                  d       y )Nr   Tautospecc                       y r   r3   r3   r!   r   	some_namez0PatchTest.test_name_preserved.<locals>.some_name  s     r!   r  )r   r"   r-   r   rk  rs   )r   rG   r  s      r   test_name_preservedzPatchTest.test_name_preserved|  sy    	~(&(	3	~(&(T	B	i	*	C 
 
+ 
C 
4 	++[9r!   c                     i }t        j                  |ddi      d        }| j                  t              5   |        d d d        | j	                  |i        y # 1 sw Y   xY w)Nr5   rL   c                      t        d      )NKonradr  r3   r!   r   rv   z1PatchTest.test_patch_with_exception.<locals>.test  s    H%%r!   )r   rk  r`   r  rs   )r   rG   rv   s      r   test_patch_with_exceptionz#PatchTest.test_patch_with_exception  sd    	C#s	$	& 
%	& y) 	F	 	b!	 	s   AA"c                 T     t        j                  dddi       fd       } |        y )Nz
os.environkonrad_delongz
some valuec                  F     j                  dt        j                         y )Nr  )assertInosenvironr:   s   r   rv   z3PatchTest.test_patch_dict_with_string.<locals>.test  s    MM/2::6r!   )r   rk  r   s   ` r   test_patch_dict_with_stringz%PatchTest.test_patch_dict_with_string  s-    	L?L"A	B	7 
C	7 	r!   c                 &    t         j                  j                         }t        j                  dddi       fd       }	 ddit         _         |         j                  t         j                  ddi       |t         _        y # |t         _        w xY w)Nz*test.test_unittest.testmock.support.targetr<   BARc                  L     j                  t        j                  ddd       y )NBAZr  rG   r<   )rs   r   targetr:   s   r   rv   z<PatchTest.test_patch_dict_decorator_resolution.<locals>.test  s    W^^U5-IJr!   rG   r  )r   r  rj  r   rk  rs   r   s   `  r   $test_patch_dict_decorator_resolutionz.PatchTest.test_patch_dict_decorator_resolution  sx     >>&&(	@5%.	Q	K 
R	K	&#U^GNFW^^eU^<%GNXGNs   6B Bc                    t        dt        z  t        d      d        }| j                  t        |       t        j
                  t        dt        d      d        }| j                  t        |       t        dt        z  d      d        }| j                  t        |       t        j
                  t        dd      d	        }| j                  t        |       y )
Nr   Tr   spec_setc                     d| _         y NrG   zre   s    r   rv   z+PatchTest.test_patch_spec_set.<locals>.test  	    IKr!   r   c                     d| _         y r  r  r  s    r   rv   z+PatchTest.test_patch_spec_set.<locals>.test  r  r!   r  c                     d| _         y r  r  r  s    r   rv   z+PatchTest.test_patch_spec_set.<locals>.test  r  r!   c                     d| _         y r  r  r  s    r   rv   z+PatchTest.test_patch_spec_set.<locals>.test  r  r!   )r   r"   r   r`   r   r-   r   r   s     r   test_patch_spec_setzPatchTest.test_patch_spec_set  s    	~(y4	H	  
I	  	.$/	g{T	J	  
K	  	.$/	~(4	8	  
9	  	.$/	g{T	:	  
;	  	.$/r!   c                 d    t        dt        z  d      d        }| j                  t        |       y )Nr   Tr  c                       |        }d|_         y r  r  )re   r   s     r   rv   z-PatchTest.test_spec_set_inherit.<locals>.test  s     {HHJr!   )r   r"   r`   r   r   s     r   test_spec_set_inheritzPatchTest.test_spec_set_inherit  s2    	~(4	8	 
9	 	.$/r!   c                 H   t         }t        dt        z        }| j                  t         |       |j	                         }	 | j                  ||       | j                  t         |       |j                          | j                  t         |       y # |j                          w xY w)Nr   )r   r   r"   assertIsstartassertIsNotstop)r   r   patcherr   s       r   test_patch_start_stopzPatchTest.test_patch_start_stop  sv    12i*}}	T8,MM)T*LLNi* LLNs    (B B!c                 d    t        t        dd      }| j                  |j                                y Nr<   r_  )r   foo_namer   r  r   r  s     r   test_stop_without_startz!PatchTest.test_stop_without_start  s$    %+',,.)r!   c                     t        t        dd      }|j                          |j                          | j	                  |j                                y r  )r   r  r  r  r   r  s     r   test_stop_idempotentzPatchTest.test_stop_idempotent  s6    %+',,.)r!   c                 Z   t         }t        j                  t        dd      }| j	                  t         |       |j                         }	 | j                  |d       | j	                  t         |       |j                          | j	                  t         |       y # |j                          w xY w)Nr   rG   )r   r   r-   r   r  r  rs   r  )r   r   r  replaceds       r   test_patchobject_start_stopz%PatchTest.test_patchobject_start_stop  sy    ,,xe<i*==?	Xu-MM)X.LLNi* LLNs   	(B B*c                 :   ddi}|j                         }t        j                  |dgd      }| j                  ||       |j	                          	 | j                  |ddi       |j                          | j                  ||       y # |j                          w xY w)NrG   r<   spameggsTrt  r  r  )rj  r   rk  rs   r  r  r   dr   r  s       r   test_patch_dict_start_stopz$PatchTest.test_patch_dict_start_stop  s    EN668**Q!1 2$?H%	Q 01LLNH% LLNs   B Bc                     ddi}|j                         }t        j                  |dgd      }| j                  |j	                                | j                  ||       y )NrG   r<   r  Trt  )rj  r   rk  rc   r  rs   r  s       r   "test_patch_dict_stop_without_startz,PatchTest.test_patch_dict_stop_without_start  sP    EN668**Q!1 2$?(H%r!   c                    | ddij                         } G fddt              } t        j                  ddid      |      }| j	                  |        |       } |j
                          | j	                  |        |j                          | j	                  |        |       } |j
                          | j	                  |        |j                          | j	                  |       y )	Nr  r  c                   &    e Zd Z fdZ fdZy)7PatchTest.test_patch_dict_class_decorator.<locals>.Testc                 .    j                  ddi       y NrG   r<   rx  r   r  thiss    r   
test_firstzBPatchTest.test_patch_dict_class_decorator.<locals>.Test.test_first        UEN3r!   c                 .    j                  ddi       y r  rx  r  s    r   test_secondzCPatchTest.test_patch_dict_class_decorator.<locals>.Test.test_second  r  r!   N)r"   r#   r$   r  r  )r  r  s   r   r   r    s    44r!   r   rG   r<   Trt  )rj  r-   r   rk  rs   r  r  )r   r   r   rv   r  r  s       @@r   test_patch_dict_class_decoratorz)PatchTest.test_patch_dict_class_decorator  s    V668	46 	4 9uzz!eU^48>H%vH%H%vH%H%r!   c                 f     G d dt               } G d d      }|| |       |fD ]  }t        |      t        j                   dd       fd       } |         j                  j                  d        j                  |j                  d        j                  dj                          y )Nc                       e Zd ZdZy)0PatchTest.test_get_only_proxy.<locals>.SomethingrG   Nr"   r#   r$   rG   r3   r!   r   rm   r  /      Cr!   rm   c                       e Zd ZdZy)4PatchTest.test_get_only_proxy.<locals>.SomethingElserG   Nr  r3   r!   r   r   r  1  r  r!   r   rG   r<   c                  >    j                   j                  d       y Nr<   rs   rG   proxyr   s   r   rv   z+PatchTest.test_get_only_proxy.<locals>.test7        E2r!   r-   r/   r   rs   rG   assertNotIn__dict__r   rm   r   thingrv   r  s   `    @r   test_get_only_proxyzPatchTest.test_get_only_proxy.  s    	 		 	 y{MI 		4Eu%E\\%.3 /3FUYY.UYY.UENN3		4r!   c                 j     G d dt               } G d d      }|| |       |fD ]  }t        |d      t        j                   dd       fd	       } |         j                  j                  d        j                  |j                  d        j                  dj                          y )
Nc                       e Zd ZdZy)6PatchTest.test_get_set_delete_proxy.<locals>.SomethingrG   Nr  r3   r!   r   rm   r  A  r  r!   rm   c                       e Zd ZdZy):PatchTest.test_get_set_delete_proxy.<locals>.SomethingElserG   Nr  r3   r!   r   r   r  C  r  r!   r   F)r.   rG   r<   c                  >    j                   j                  d       y r  r  r  s   r   rv   z1PatchTest.test_get_set_delete_proxy.<locals>.testI  r  r!   r  r  s   `    @r   test_get_set_delete_proxyz#PatchTest.test_get_set_delete_proxy@  s    	 		 	 y{MI 		4Ey59E\\%.3 /3FUYY.UYY.UENN3		4r!   c                 H   t         dt               d}t        t        fi |}|j	                         }|j                          | j                  t         |       | j                  |j                  j                         d       | j                  |j                  t               y )N!   side_effectzfoo.bar.return_valuerG   )KeyErrorr   r   r  r  r  r`   rs   rG   r<   r   r   kwargsr  r   s       r   test_patch_keyword_argsz!PatchTest.test_patch_keyword_argsR  sv    !)2"& +F+}}(D),dhh	2r!   c                 ^   t         dt               d}t        j                  t        dfi |}|j                         }|j                          | j                  t         |       | j                  |j                  j                         d       | j                  |j                  t               y )Nr  r  r8   )r  r   r   r-   r1   r  r  r`   rs   rG   r<   r   r  s       r   test_patch_object_keyword_argsz(PatchTest.test_patch_object_keyword_args_  s|    !)2"& ,,sC262}}(D),dhh	2r!   c                 *   ddi}|j                         }t        j                  |ddd      }|j                          	 | j	                  |t        ddd             |j                          | j	                  ||       y # |j                          w xY w)NrG   r<   r_        )rG   r<   baz)rj  r   rk  r  rs   r  )r   r   rj  r  s       r   test_patch_dict_keyword_argsz&PatchTest.test_patch_dict_keyword_argsl  sw    5>}}**X1!;	Xtqa'@ALLN4( LLNs   B   Bc                 r     G d dt               } fd fd fd} t        t        d      |      } |       } j                  t        |        |        t
        j                  t           } t        j                   |dd      |      } |       } j                  t        |        |        y )	Nc                   8    e Zd Zd Zd Zd ZdZ G d de      Zy)$PatchTest.test_autospec.<locals>.Booc                      y r   r3   r4   s     r   r6   z-PatchTest.test_autospec.<locals>.Boo.__init__}  s    4r!   c                      y r   r3   r4   s     r   r8   z&PatchTest.test_autospec.<locals>.Boo.f~  s    Dr!   c                      y r   r3   r:   s    r   r;   z&PatchTest.test_autospec.<locals>.Boo.g  s    r!   r<   c                       e Zd Zd Zy)(PatchTest.test_autospec.<locals>.Boo.Barc                      y r   r3   r:   s    r   r5   z*PatchTest.test_autospec.<locals>.Boo.Bar.a  s    Tr!   NrE   r3   r!   r   rF   r    s    !r!   rF   N)	r"   r#   r$   r6   r8   r;   rG   r-   rF   r3   r!   r   Boor  |  s    ' C"f "r!   r  c                 d     | d       | j                  d       j                  t        |        y N   )assert_called_withr`   ra   r   r   s    r   _testz&PatchTest.test_autospec.<locals>._test  s(    G##A&i.r!   c                    | j                  d       | j                   j                  d       j                  t        | j                          | j	                          | j                  j                          j                  t        | j                  d       j                  t
        t        | d       | j                  j                          | j                  j                  j                          j                  t
        t        | j                  d       | j                          | j                  j                          | j                  j                          | j                  j                  j                          j                  t        | j                  j                  d       | j                         j                          | j                         j                  j                          j                  t        | j                         j                  d       j                  t
        t        | j                  d       j                  t
        t        | j                         d       y )Nr  hr<   rL   )r8   r  r`   ra   r;   r   r   rG   lowerrF   r5   r  s    r   _test2z'PatchTest.test_autospec.<locals>._test2  sx   FF1IFF%%a(i0FFHFF%%'i3ngtSAHHNNHHNN--/ngtxxGHHJHH'')HHJJLHHJJ))+iQ7HHJLLNHHJLL++-iq9ngtxxEngtxxz3Gr!   c                 p     |         |          | d             j                  | t               | S r
  )r  r1   )r   r  r  r   s    r   rM   z)PatchTest.test_autospec.<locals>.function  s/    $K4L47OMM$$Kr!   Tr  r1   )r-   r   r  r  r1   sysmodulesr"   )r   r  rM   rv   r   moduler  r  s   `     @@r   test_autospeczPatchTest.test_autospec{  s    	"& 	"	/
	H:	 .uX-h7vd#X&9u||FED9(Cvd#r!   c                 L     t        dt        z  d       fd       } |        y )N%s.functionTr  c                 N   t         j                          j                  t        t         j                         j                  t        t         j
                         t        d       j                  t        t         j                         t         j                  d       t         j	                          t         j                          t        dd       t         j                  dd       j                  t        t                j                  t        t        t         d       y )Nr     r_  rG   )
rM   assert_not_calledr`   AssertionErrorassert_calledassert_called_oncer  ra   r   r   r  s    r   rv   z.PatchTest.test_autospec_function.<locals>.test  s    &&(nh.D.DEnh.I.IJQKnh.H.HI''*""$'')QN''1-i2ngxGr!   r   r   s   ` r   test_autospec_functionz PatchTest.test_autospec_function  s*    	}x'$	7	H 
8	H 	r!   c                 l    t        dt        z  dd      d        } |       }| j                  |d       y )Nr  Tr_  )r  r   c                     t        dd      S )Nr  r  )rM   )mock_functions    r   rv   z.PatchTest.test_autospec_keywords.<locals>.test  s     Aq>!r!   r%  )r   rv   results      r   test_autospec_keywordsz PatchTest.test_autospec_keywords  s>    	}x'$
	"
	" #r!   c                     t        dt        z  d      5 }t        j                          |j	                          d d d        y # 1 sw Y   y xY w)Nz%s.Foo.static_methodTr  )r   r"   r1   r>   assert_called_once_withr   methods     r   test_autospec_staticmethodz$PatchTest.test_autospec_staticmethod  sA    )H4tD 	-**,	- 	- 	-   %AAc                     t        dt        z  d      5 }t        j                          |j	                          d d d        y # 1 sw Y   y xY w)Nz%s.Foo.class_methodTr  )r   r"   r1   rA   r'  r(  s     r   test_autospec_classmethodz#PatchTest.test_autospec_classmethod  sA    (83dC 	-v**,	- 	- 	-r+  c           	      @    G d d      }|j                  ddd       t        j                  |dd	      5 } |ddd       | j                  t        |       | j                  t        |d       | j                  t        |dddd
       d d d        y # 1 sw Y   y xY w)Nc                       e Zd Zedd       Zy);PatchTest.test_autospec_staticmethod_signature.<locals>.Fooc                     y r   r3   )r5   rL   r  s      r   r>   zIPatchTest.test_autospec_staticmethod_signature.<locals>.Foo.static_method  s    .2r!   N
   )r"   r#   r$   rH   r>   r3   r!   r   r1   r0    s    2 2r!   r1   r  r  r_  r  r>   Tr  r  )r>   r   r-   r`   ra   r   r1   r)  s      r   $test_autospec_staticmethod_signaturez.PatchTest.test_autospec_staticmethod_signature  s    	3 	3 	!Q!$\\#> 	?&1a1i0i3iAqA>		? 	? 	?   ABBc           	      @    G d d      }|j                  ddd       t        j                  |dd	      5 } |ddd       | j                  t        |       | j                  t        |d       | j                  t        |dddd
       d d d        y # 1 sw Y   y xY w)Nc                       e Zd Zedd       Zy):PatchTest.test_autospec_classmethod_signature.<locals>.Fooc                     y r   r3   )r@   r5   rL   r  s       r   rA   zGPatchTest.test_autospec_classmethod_signature.<locals>.Foo.class_method  s    26r!   Nr2  )r"   r#   r$   rI   rA   r3   r!   r   r1   r:    s    6 6r!   r1   r  r  r_  r4  rA   Tr  r  )rA   r   r-   r`   ra   r5  s      r   #test_autospec_classmethod_signaturez-PatchTest.test_autospec_classmethod_signature  s    	7 	7 	A#\\#~= 	?1a1i0i3iAqA>		? 	? 	?r7  c                    t        dt        z  dd      }| j                  t        |j                         t
        j                  t           }t        j                  |ddd      }| j                  t        |j                         y )Nr  r_  T)newr  rM   )r   r"   r`   ra   r  r  r  r-   )r   r  r  s      r   test_autospec_with_newz PatchTest.test_autospec_with_new  s_    0a$G)W]]3X&,,vzq4H)W]]3r!   c                     G d dt               }t        t        |      }|j                         }	 | j	                  ||       | j	                  |j
                  t               |j                          y # |j                          w xY w)Nc                       e Zd Zg Zy)0PatchTest.test_autospec_with_object.<locals>.BarN)r"   r#   r$   extrar3   r!   r   rF   rB    s    Er!   rF   r  )r1   r   r  r  r   rC  listr  )r   rF   r  r   s       r   test_autospec_with_objectz#PatchTest.test_autospec_with_object  sc    	# 	 3/}}	!!$,!!$**d3LLNGLLNs   2A5 5Bc                     t         }t        t        d      }|j                         }	 | j	                  ||       | j	                   |d      |       |j                          y # |j                          w xY w)NTr  r_  )r1   r   r  r  r   r  )r   FooClassr  r   s       r   test_autospec_inheritsz PatchTest.test_autospec_inherits  sZ    40}}	!!$1!!$q'84LLNGLLNs   *A$ $A6c                    t        t        d      }|j                         }	 | j                  dt	        |             | j                  dt	        |j
                               | j                  dt	         |d                    | j                  dt	         |d       j
                               |j                          y # |j                          w xY w)NTr  z name='Foo'z name='Foo.f'z name='Foo()'z name='Foo().f')r   r  r  r  reprr8   r  )r   r  r   s      r   test_autospec_namezPatchTest.test_autospec_name(  s    40}}	MM-d4MM/4<8MM/4T
+;<MM+T$t*,,-?@LLNGLLNs   BC   Cc                    t        j                  t        dt                     d        }	  |        t        j                  d d d      }|j                  |       }| j                  d|       y #  t        j                         }Y TxY w)Nr8   c                      t         r   )r  r3   r!   r   rv   z'PatchTest.test_tracebacks.<locals>.test6  s      r!   r   zraise AssertionError)	r   r-   r1   r  exc_infounittestTextTestResult_exc_info_to_stringr  )r   rv   errr$  	tracebacks        r   test_tracebackszPatchTest.test_tracebacks5  sv    	c3	)	! 
*	!	!F ((tQ7..sD9	,i8	!,,.Cs   A. .Bc                    t        t        t              }|j                         }|j	                          |j                         }|j	                          | j                  ||       ||fD ]  }| j                  |        y )Nnew_callable)r   r  r   r  r  r  rf   r   r  m1m2r   s        r   test_new_callable_patchz!PatchTest.test_new_callable_patchC  sh    /CD]]_]]_R F 	'D""2&	'r!   c                    t        j                  t        dt              }|j	                         }|j                          |j	                         }|j                          | j                  ||       ||fD ]  }| j                  |        y )Nr8   rV  )r   r-   r1   r   r  r  r  rf   rX  s        r   test_new_callable_patch_objectz(PatchTest.test_new_callable_patch_objectP  sn    ,,sC6JK]]_]]_R F 	'D""2&	'r!   c                 >    G fddt               t        t        dd      }|j                         }	 | j	                  t        |             | j                  j                  t        dd             |j                          y # |j                          w xY w)Nc                       e Zd ZdZ fdZy):PatchTest.test_new_callable_keyword_arguments.<locals>.BarNc                     |_         y r   r  r   r  rF   s     r   r6   zCPatchTest.test_new_callable_keyword_arguments.<locals>.Bar.__init__`  
    #
r!   r"   r#   r$   r  r6   rF   s   r   rF   r`  ^      F$r!   rF   r  r  )rW  arg1arg2)rh  ri  )
r-   r   r  r  r  typers   r  rk  r  )r   r  r!  rF   s      @r   #test_new_callable_keyword_argumentsz-PatchTest.test_new_callable_keyword_arguments]  sq    	$& 	$
 sCMMO	MM$q'3'SZZ11)=>LLNGLLNs   AB
 
Bc                     G fddt               t        t              }|j                          	 | j	                  j
                  t                     |j                          t        t              }|j                          	 | j	                  j
                  t                     |j                          y # |j                          w xY w# |j                          w xY w)Nc                       e Zd ZdZ fdZy)-PatchTest.test_new_callable_spec.<locals>.BarNc                     |_         y r   rb  rc  s     r   r6   z6PatchTest.test_new_callable_spec.<locals>.Bar.__init__o  rd  r!   re  rf  s   r   rF   rn  m  rg  r!   rF   rW  r   r   )rW  r  r  )r-   r   r  r  rs   r  rk  r  )r   r  rF   s     @r   test_new_callable_specz PatchTest.test_new_callable_specl  s    	$& 	$
 s=	SZZ38LLNsSA	SZZs);<LLN LLN LLNs   &C &C CC-c                 .   dt         z  }t        |t              }| j                  t        |j
                         t        |t        d      }|j                         }	 | j                  |d       |j                          y # |j                          w xY w)Nz	%s.weeeeerV  T)rW  r   F)rd   )r  r   r	   r`   r   r  rf   r  )r   non_existent_attrpr!  s       r   test_new_callable_createz"PatchTest.test_new_callable_create  sv    '(2#/B.!''2#/GGI	""1E"2FFHAFFHs   B Bc                     | j                  t        t        t        t	               t
               | j                  t        t        j                  t        dt	               t
               y )N)r>  rW  r8   )r`   
ValueErrorr   r  r-   r   r1   r:   s    r   'test_new_callable_incompatible_with_newz1PatchTest.test_new_callable_incompatible_with_new  sK    xVXI 	 	
 	c3FH" 	 	
r!   c                     | j                  t        t        t        t        d       | j                  t        t        j
                  t        dt        d       y )NT)rW  r  r8   )r`   rw  r   r  r   r-   r1   r:   s    r   ,test_new_callable_incompatible_with_autospecz6PatchTest.test_new_callable_incompatible_with_autospec  sH    xi 	 	
 	c3Y 	 	
r!   c                 T    G d dt               }t        t        t        t         |f}|D ]h  }dD ]a  }|di}t	        t
        fd|i|}|j                         }	 |j                  }| j                  t        t        |d       |j                          c j y # |j                          w xY w)Nc                       e Zd Zy)>PatchTest.test_new_callable_inherit_for_mocks.<locals>.MockSubNr"   r#   r$   r3   r!   r   MockSubr}        r!   r  r  TrW  x)r   r	   r   r   r   r  r  r   r`   r   r   r  )	r   r  MockClassesKlassargr  rt  r!  r   s	            r   #test_new_callable_inherit_for_mocksz-PatchTest.test_new_callable_inherit_for_mocks  s    	d 	 19dG
 ! 		E) t(AA&AGGI ~~H%%ngxMFFH		 FFHs   (BB'c                 `    G d dt               }t        t        |d      }|j                         }	 | j	                  t        ||             | j                  t        t        |d       |j                          | j                  |j                  t               y # |j                          w xY w)Nc                       e Zd Zd Zy)>PatchTest.test_new_callable_inherit_non_mock.<locals>.NotAMockc                     || _         y r   r   )r   r   s     r   r6   zGPatchTest.test_new_callable_inherit_non_mock.<locals>.NotAMock.__init__  s	     	r!   N)r"   r#   r$   r6   r3   r!   r   NotAMockr    s    !r!   r  Trp  r   )r-   r   r  r  rb   r   r`   r   r   r  rs   r   r1   )r   r  rt  r!  s       r   "test_new_callable_inherit_non_mockz,PatchTest.test_new_callable_inherit_non_mock  s    	!v 	! (=GGI	OOK845ngq.IFFH% FFHs   7B B-c                     | t          G fddt              } t        t        t              |      } |       j                           |       j                          | j                  t                y )Nc                   &    e Zd Z fdZd Zd Zy)>PatchTest.test_new_callable_class_decorating.<locals>.SomeTestc                      j                   t                j                  t        |        j                  t        t               y r   )r  r1   r  r   r   )r   mock_foor   rv   s     r   r  zDPatchTest.test_new_callable_class_decorating.<locals>.SomeTest._test  s7       h/c8,%%%c95r!   c                 &    | j                  |       y r   r  r   r  s     r   test_twozGPatchTest.test_new_callable_class_decorating.<locals>.SomeTest.test_two      

8$r!   c                 &    | j                  |       y r   r  r  s     r   test_onezGPatchTest.test_new_callable_class_decorating.<locals>.SomeTest.test_one  r  r!   Nr"   r#   r$   r  r  r  )r   rv   s   r   SomeTestr    s    6
%%r!   r  rV  )r1   r-   r   r  r   r  r  r  )r   r  r   rv   s     @@r   "test_new_callable_class_decoratingz,PatchTest.test_new_callable_class_decorating  sX    
	%v 
	% ;5	:8D

c8$r!   c                     t         t         j                  }t         j                  }t        j                  t
        dd      }t        j                  t         dd      }||fD ]  }|j                          	  j                  t                 j                  t         j                  d        j                  t         j                  d       |j                           j                  t                 j                  t         j                  |        j                  t         j                  |        t        j                  t
        dd       fd       } |        y # |j                          w xY w)Nr  r  )r8   r;   r_  r  c                      j                  t                j                  t        j                  d       j                  t        j                  d       y )Nr_  r  )r  r1   rs   r8   r;   )original_foor   s   r   rv   z+PatchTest.test_patch_multiple.<locals>.test  s9    MM#|,SUUA&SUUA&r!   )
r1   r8   r;   r   multipler  r  r  rs   r  )r   
original_f
original_gpatcher1patcher2r  rv   r  s   `      @r   test_patch_multiplezPatchTest.test_patch_multiple  s
   UU
UU
>>(a15>>#a0) 	0GMMOc<0  *  *MM#|,SUUJ/SUUJ/	0 
A	+	' 
,	'
 	 s   9AE$$E6c                     | j                  t        t        j                  t               | j                  t        t        j                  t
               y r   )r`   rw  r   r  r  r1   r:   s    r   test_patch_multiple_no_kwargsz'PatchTest.test_patch_multiple_no_kwargs  s.    *ennh?*ennc:r!   c                 >    t         t         j                  }t         j                  }t        j                  t
        t        dt               fd       } |         j                  t         j                  |        j                  t         j                  |       y )Nr_  r8   r;   rG   c                 n   j                  t               j                  t        j                  |        j                  t        j                  d       j                  t        j
                  |       j                  t        | t                     j                  t        |t                     y Nr_  	r  r1   r8   rs   r;   rG   rb   r   r   )r8   rG   r  r   s     r   rv   z8PatchTest.test_patch_multiple_create_mocks.<locals>.test  so    MM#|,MM#%%#SUUA&MM#''3'OOK956OOKY78r!   r1   r8   r;   r   r  r  r   rs   )r   r  r  rv   r  s   `   @r    test_patch_multiple_create_mocksz*PatchTest.test_patch_multiple_create_mocks   sj    UU
UU
	Gqg	>	9 
?	9 	
+
+r!   c                     t         j                  }t         j                  }t        j                  t         dd      }d|_        t        j                  t         dt              }d|_        |g|_        | fd       } |         j                  t         j                  |        j                  t         j                  |       y )Nr8   r_  r;   c                     j                  t        j                  |        j                  t        j                  d       y r  )r  r1   r;   rs   r8   )r;   r   s    r   rv   zHPatchTest.test_patch_multiple_create_mocks_different_order.<locals>.test  s)    MM#%%#SUUA&r!   )	r1   r8   r;   r   r-   attribute_namer   additional_patchersrs   )r   r  r  r  r\  rv   s   `     r   0test_patch_multiple_create_mocks_different_orderz:PatchTest.test_patch_multiple_create_mocks_different_order  s    UU
UU
,,sC+!$S#w/"',g#		' 
	' 	
+
+r!   c                 @    t         t         j                  }t         j                  }t        j                  t
        t              t        j                  t
        t              t        t
        dz         fd                     }t        j                  t
        t              t        t
        dz         t        j                  t
        t              fd                     }t        t
        dz         t        j                  t
        t              t        j                  t
        t              fd                     } fd |         |         |         j                  t         j                  |        j                  t         j                  |       y )N)r8   ra  z.gc                      | fi | y r   r3   r;   r  r  s     r   test1z?PatchTest.test_patch_multiple_stacked_decorators.<locals>.test1-       !vr!   c                      | fi | y r   r3   r  s     r   test2z?PatchTest.test_patch_multiple_stacked_decorators.<locals>.test23  r  r!   c                      | fi | y r   r3   r  s     r   test3z?PatchTest.test_patch_multiple_stacked_decorators.<locals>.test39  r  r!   c                    |j                  d      }|j                  d      }j                  |       j                  t               j                  t        j                  |       j                  t        j
                  |        j                  t        j                  |       j                  t        |t                     j                  t        | t                     j                  t        |t                     y )Nr8   rG   )
poprc   r  r1   r8   r;   rG   rb   r   r   )r;   r  r8   rG   r  r   s       r   r  z?PatchTest.test_patch_multiple_stacked_decorators.<locals>._test?  s    

3A**U#CV$MM#|,MM#%%#MM#%%#MM#''3'OOK956OOK956OOKY78r!   r  )r   r  r  r  r  r  r  r  s   `     @@r   &test_patch_multiple_stacked_decoratorsz0PatchTest.test_patch_multiple_stacked_decorators(  s   UU
UU
	G	,	g	.	x$		 
  
/ 
-	 
G	,	x$		g	.	 
/ 
  
-	 
x$		G	,	g	.	 
/ 
- 
 		9 	
+
+r!   c                    t         }t         j                  }t         j                  }t        j                  t
        t        dt              }|j                         }	 |d   }|d   }| j                  t        |      t        ddg             | j                  t         |       | j                  t         j                  |       | j                  t         j                  |       | j                  t        |t                     | j                  t        |t                     |j                          | j                  t         j                  |       | j                  t         j                  |       y # |j                          w xY w)Nr_  r  r8   rG   )r1   r8   r;   r   r  r  r   r  rs   setr  rG   rb   r   r   r  )r   r  r  r  r  r$  r8   rG   s           r   (test_patch_multiple_create_mocks_patcherz2PatchTest.test_patch_multiple_create_mocks_patcherS  s   UU
UU
..WwG	sA-CS[#sEl*;<MM#|,MM#%%#MM#''3'OOK956OOKY78LLN
+
+ LLNs   CE2 2Fc                    | t         t         j                  }t         j                  } G fddt              } t	        j
                  t        t        dt              |      } |       }|j                          |j                          | j                  t         j                  |       | j                  t         j                  |       y )Nc                   &    e Zd Z fdZd Zd Zy)@PatchTest.test_patch_multiple_decorating_class.<locals>.SomeTestc                 z    j                   t                j                   t        j                  |        j                  t        j                  d        j                   t        j
                  |        j                  t        |t                      j                  t        |t                     y r  r  )r   r8   rG   r  rv   s      r   r  zFPatchTest.test_patch_multiple_decorating_class.<locals>.SomeTest._testt  s{    c<0ceeQ'   *cggs+Ay 9:C ;<r!   c                 (    | j                  ||       y r   r  r   r8   rG   s      r   r  zIPatchTest.test_patch_multiple_decorating_class.<locals>.SomeTest.test_two|      

1c"r!   c                 (    | j                  ||       y r   r  r  s      r   r  zIPatchTest.test_patch_multiple_decorating_class.<locals>.SomeTest.test_one~  r  r!   Nr  )r  rv   s   r   r  r  r  s    =##r!   r  r_  r  )r1   r8   r;   r-   r   r  r  r   r  r  rs   )r   r  r  r  r  r  rv   s        @@r   $test_patch_multiple_decorating_classz.PatchTest.test_patch_multiple_decorating_classl  s    UU
UU
	#v 	#
5>>1'

 

+
+r!   c                    t        j                  t        d      }| j                  t        |j
                         t        j                  t        dd      }|j                          	 | j                  t        j                  d       |j                          | j                  t        t        d             y # |j                          w xY w)Nblam)r  T)r  r   )r   r  r1   r`   r   r  rs   r  r  rc   r  r  s     r   test_patch_multiple_createz$PatchTest.test_patch_multiple_create  s    ..62.'--8..6$?	SXXv.LLNf-. LLNs   ) B9 9Cc                 p   t        j                  t        t        ddg      }|j	                         }	 | j                  t        j                  |d          t        j                  j                  d       t        j                  j                  d       t        j                  j                  j                  d       t        j                  j                  j                  d       | j                  t        t        t        j                  dd        |j                          y # |j                          w xY w)Nr5   rL   )rG   r  rG   r  r  r  )r   r  r1   r   r  rs   rG   r5   rL   r  r`   r   r'   r  )r   r  r$  s      r   test_patch_multiple_spec_setz&PatchTest.test_patch_multiple_spec_set  s     ..'S#JG	SWWfUm4GGIIaLGGIIaLGGII((+GGII((+ngswwTJLLNGLLNs   CD# #D5c                 @    G d dt               }t        j                  t        t        t        |      }|j                         }	 | j                  t        j                  |d          | j                  t        j                  |d          | j                  t        j                  |       | j                  t        j                  |       | j                  t        j                  t        j                         |j                          y # |j                          w xY w)Nc                       e Zd Zy)9PatchTest.test_patch_multiple_new_callable.<locals>.ThingNr~  r3   r!   r   Thingr    r  r!   r  )r8   r;   rW  r8   r;   )r-   r   r  r1   r   r  r  r8   r;   r   r  r  )r   r  r  r$  s       r    test_patch_multiple_new_callablez*PatchTest.test_patch_multiple_new_callable  s    	F 	 ..7gE
 	MM#%%-MM#%%-!!#%%/!!#%%/SUUCEE*LLNGLLNs   B4D Dc                 2   t         j                  }t         j                  }t        j                  t         dd      t        j                  t         dd      t        j                  t         dd      d                      }t        j                  t         dd      t        j                  t         dd      t        j                  t         dd      d                      }t        j                  t         dd      t        j                  t         dd      t        j                  t         dd      d                      }|||fD ]X  }| j                  t        |       | j                  t         j                  |       | j                  t         j                  |       Z y )Nr;   r  missingr8   c                       y r   r3   r3   r!   r   thing1z3PatchTest.test_nested_patch_failure.<locals>.thing1       r!   c                       y r   r3   r3   r!   r   thing2z3PatchTest.test_nested_patch_failure.<locals>.thing2  r  r!   c                       y r   r3   r3   r!   r   thing3z3PatchTest.test_nested_patch_failure.<locals>.thing3  r  r!   )r1   r8   r;   r   r-   r`   r   rs   )r   r  r  r  r  r  funcs          r   test_nested_patch_failurez#PatchTest.test_nested_patch_failure  s7   UU
UU
	c3	"	c9a	(	c3	" 
# 
) 
# 		c9a	(	c3	"	c3	" 
# 
# 
) 		c3	"	c3	"	c9a	( 
) 
# 
# 	FF* 	0Dnd3SUUJ/SUUJ/	0r!   c                    t         j                  }t         j                  }t         j                  }d }t	        j
                  t         dd      t	        j
                  t         d|      t	        j
                  t         dd      d                      }t	        j
                  t         d|      t	        j
                  t         dd      t	        j
                  t         dd      d                      }t	        j
                  t         dd      t	        j
                  t         dd      t	        j
                  t         d|      d	                      }|||fD ]x  }| j                  t        |       | j                  t         j                  |       | j                  t         j                  |       | j                  t         j                  |       z y )
Nc                      t        d      Ncrasherr  r3   r!   r   r  z4PatchTest.test_new_callable_failure.<locals>.crasher      I&&r!   r;   r  rG   rV  r8   c                       y r   r3   r3   r!   r   r  z3PatchTest.test_new_callable_failure.<locals>.thing1  r  r!   c                       y r   r3   r3   r!   r   r  z3PatchTest.test_new_callable_failure.<locals>.thing2  r  r!   c                       y r   r3   r3   r!   r   r  z3PatchTest.test_new_callable_failure.<locals>.thing3  r  r!   )	r1   r8   r;   rG   r   r-   r`   r  rs   )	r   r  r  r  r  r  r  r  r  s	            r   test_new_callable_failurez#PatchTest.test_new_callable_failure  s[   UU
UU
ww	' 
c3	"	c5w	7	c3	" 
# 
8 
# 		c5w	7	c3	"	c3	" 
# 
# 
8 		c3	"	c3	"	c5w	7 
8 
# 
# 	FF* 	4Di.SUUJ/SUUJ/SWWl3		4r!   c                    t         j                  }t         j                  }t        j                  t         dd      }d|_        t        j                  t         dd      }d|_        t        j                  t         dd      }d|_        ||g||gfD ]g  }||_        |d        }| j                  t        |       | j                  t         j                  |       | j                  t         j                  |       i y )Nr8   r  r;   r  c                       y r   r3   r3   r!   r   r  z3PatchTest.test_patch_multiple_failure.<locals>.func  r  r!   )
r1   r8   r;   r   r-   r  r  r`   r   rs   )r   r  r  r  goodbadadditionalsr  s           r   test_patch_multiple_failurez%PatchTest.test_patch_multiple_failure  s    UU
UU
,,sC+!$||Ca(!ll3	1-& #;d3 	0K*5G' nd3SUUJ/SUUJ/	0r!   c                 \   t         j                  }t         j                  }t         j                  }d }t	        j
                  t         dd      }d|_        t	        j
                  t         dd      }d|_        t	        j
                  t         d|      }d|_        ||g||gfD ]  }||_        |d        }	| j                  t        |	       | j                  t         j                  |       | j                  t         j                  |       | j                  t         j                  |        y )Nc                      t        d      r  r  r3   r!   r   r  zCPatchTest.test_patch_multiple_new_callable_failure.<locals>.crasher  r  r!   r8   r  r;   rG   rV  c                       y r   r3   r3   r!   r   r  z@PatchTest.test_patch_multiple_new_callable_failure.<locals>.func   r  r!   )r1   r8   r;   rG   r   r-   r  r  r`   r  rs   )
r   r  r  r  r  r  r  r  r  r  s
             r   (test_patch_multiple_new_callable_failurez2PatchTest.test_patch_multiple_new_callable_failure  s    UU
UU
ww	' ,,sC+!$||Ca(!ll3G<" #;d3 		4K*5G' i.SUUJ/SUUJ/SWWl3		4r!   c                      t        dt        fddi      } |       t        j                  d       fd       } |         j	                  j
                  d       y )Nr1   fishtastynearly gone)r  c                  >    j                   j                  d       y )Nr  )rs   r  r:  s   r   rv   z=PatchTest.test_patch_multiple_string_subclasses.<locals>.test,  s    SXX}5r!   )rj  strr   r  rs   r  )r   r1   rv   rG   s   `  @r   %test_patch_multiple_string_subclassesz/PatchTest.test_patch_multiple_string_subclasses)  sW    53&67"34e	-	0	6 
1	6 	7+r!   zunittest.mock.patch.TEST_PREFIXrG   c                 j    G d dt               } t        j                   |dd      |      } |       }| j                  |j                         d       | j                  |j	                         d       | j                  |j                         d       | j                  |j                         d       y )Nc                   (    e Zd ZdZd Zd Zd Zd Zy)-PatchTest.test_patch_test_prefix.<locals>.Foor   c                     | j                   S r   r  r:   s    r   foo_onez5PatchTest.test_patch_test_prefix.<locals>.Foo.foo_one9      zz!r!   c                     | j                   S r   r  r:   s    r   foo_twoz5PatchTest.test_patch_test_prefix.<locals>.Foo.foo_two;  r  r!   c                     | j                   S r   r  r:   s    r   r  z6PatchTest.test_patch_test_prefix.<locals>.Foo.test_one=  r  r!   c                     | j                   S r   r  r:   s    r   r  z6PatchTest.test_patch_test_prefix.<locals>.Foo.test_two?  r  r!   N)r"   r#   r$   r  r  r  r  r  r3   r!   r   r1   r  6  s    E""""r!   r1   r  changedr   )r-   r   rs   r  r  r  r  )r   r1   rG   s      r   test_patch_test_prefixz PatchTest.test_patch_test_prefix4  s    
	"& 
	" 4ell33C8e	2	244r!   r<   c                     G fddt               }ddi t        j                  d      |      } |       }| j                  |j	                         ddi       | j                  |j                         ddi       | j                  |j                         ddi       | j                  |j                         ddi       y )Nc                   6    e Zd Z fdZ fdZ fdZ fdZy)2PatchTest.test_patch_dict_test_prefix.<locals>.Fooc                     t              S r   rk  r   the_dicts    r   bar_onez:PatchTest.test_patch_dict_test_prefix.<locals>.Foo.bar_oneN      H~%r!   c                     t              S r   r
  r  s    r   bar_twoz:PatchTest.test_patch_dict_test_prefix.<locals>.Foo.bar_twoP  r  r!   c                     t              S r   r
  r  s    r   r  z;PatchTest.test_patch_dict_test_prefix.<locals>.Foo.test_oneR  r  r!   c                     t              S r   r
  r  s    r   r  z;PatchTest.test_patch_dict_test_prefix.<locals>.Foo.test_twoT  r  r!   N)r"   r#   r$   r  r  r  r  )r  s   r   r1   r  M  s    &&&&r!   r1   keyr   r  )r  )r-   r   rk  rs   r  r  r  r  )r   r1   rG   r  s      @r   test_patch_dict_test_prefixz%PatchTest.test_patch_dict_test_prefixK  s    	&& 	& :&1ejjy1#6U	(:;	(:;%)<=%)<=r!   c                    dD ]  }t        dt        z  fi |di}|j                         }	 | j                  dt	        |             | j                  dt	        |j
                               | j                  dt	         |                    | j                  dt	         |       j
                               |j                           y # |j                          w xY w)Nr   r  r  r   Tz name='SomeClass'z! name='SomeClass.class_attribute'z name='SomeClass()'z# name='SomeClass().class_attribute')r   r"   r  r  rJ  r   r  )r   r  rt  r!  s       r   test_patch_with_spec_mock_reprz(PatchTest.test_patch_with_spec_mock_repra  s    3 	Cnx/?C;?A	A147;A"1#4#4573T!#Y?C"13#6#679 	 s   B
C		Cc                    t        dd      5 }| j                  dt        |j                  j	                                      | j                  dt        |j                         j	                                      d d d        y # 1 sw Y   y xY w)N#test.test_unittest.testmock.supportTr  z" name='support.SomeClass.wibble()'z$ name='support.SomeClass().wibble()')r   r  rJ  r   r   )r   r!  s     r   test_patch_nested_autospec_reprz)PatchTest.test_patch_nested_autospec_reprp  sn    84H 	8AMM>q{{11346MM@q{{}33568	8 	8 	8s   A+BBc                    dD ]  }t        dt        z  fi |di}|j                         }	 |j                          t	        j                         g}| j                  |j                  |       | j                  |j                  |       | j                  |j                  j                  t	               g        |       }|j                  t	                      | j                  |j                  |       |j                          |j                  t	               j                                | j                  |j                  |       | j                  |j                  t	        j                         g       | j                  |j                  j                  t	               g       | j                  |j                  t	        j                         g       |j                           y # |j                          w xY w)Nr  r   T)
r   r"   r  r   r   rs   
mock_callsmethod_callsappendr  )r   r  rt  r!  kallsr$  s         r   test_mock_calls_with_patchz$PatchTest.test_mock_calls_with_patchy  s_   3 	Cnx/?C;?A	A
  u5  7  !4!4tvh?TV$  u5TV]]_-  u5  !2!2T[[]OD  !9!9DF8D  !4!4t{{}oF/	. s   F(G))G;c                 ~   t        d      }| j                  t        |j                         t	        d      5  t               }|t        j                  d<   d|_        t        d      }d|_        |j                          |j                          d d d        | j                  j                  d       y # 1 sw Y   &xY w)Nsquizz.squozzsquizz   r_  )r   r`   ImportErrorr  r   r   r  r  squozzr  rs   )r   p1r#  s      r   test_patch_imports_lazilyz#PatchTest.test_patch_imports_lazily  s    ?#+rxx0X 	VF$*CKK!FM'BFMHHJGGI	 	*	 	s   AB33B<c                     G d d       G fddt               fd} |d      d        }t        d      5  t               }|t        j                  d<   | j                  t        |       d d d        | j                  j                  d	   t               | j                  j                  d
   d       | j                  j                  d   d       y # 1 sw Y   kxY w)Nc                       e Zd ZdZy);PatchTest.test_patch_propagates_exc_on_exit.<locals>.holderNNNN)r"   r#   r$   rN  r3   r!   r   holderr+    s    'Hr!   r-  c                       e Zd Zd fd	ZeZy)APatchTest.test_patch_propagates_exc_on_exit.<locals>.custom_patchNc                 J    t        j                  | |||       |||f_        y r   )r   __exit__rN  )r   etypevaltbr-  s       r   r1  zJPatchTest.test_patch_propagates_exc_on_exit.<locals>.custom_patch.__exit__  s"    eS"5"'b.r!   r,  )r"   r#   r$   r1  r  )r-  s   r   custom_patchr/    s    1 Dr!   r5  c                 H    t        |       \  }} ||t        d dd d d i 	      S )NF)r   r   )r  getterrl   r5  s      r   with_custom_patchzFPatchTest.test_patch_propagates_exc_on_exit.<locals>.with_custom_patch  s3     +F 3FI	7D%dB r!   r"  c                     t         r   )RuntimeErrorr   s    r   rv   z9PatchTest.test_patch_propagates_exc_on_exit.<locals>.test  s    r!   r#  r   r  zexception value not propagatedr  z"exception traceback not propagated)
r   r   r   r  r  r`   r:  r  rN  assertIsNotNone)r   r8  rv   r#  r5  r-  s       @@r   !test_patch_propagates_exc_on_exitz+PatchTest.test_patch_propagates_exc_on_exit  s    	( 	(	6 		 
?	+	 
,	 X 	2VF$*CKK!lD1		2 	fooa(,7V__Q/<	>V__Q/@	B	2 	2s   4CC#c                     t         j                  j                  t         j                  j                  t        j
                        dd      }d } fd}t        dd      5  t        |      5   |d        |d       d d d        d d d        t        dd      5  t        |      5   |d	        |d
       d d d        d d d        t        dd      5  t        |      5   |d        |d        |d        |d        |d        |d       d d d        d d d        t        dd      5  t        |      5   |d        |d        |d	        |d
        |d        |d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   [xY w# 1 sw Y   y xY w)Ntest_importr#  c                 Z    t        |       }|j                          |j                          y r   r   r  r  r   rt  s     r   checkz>PatchTest.test_name_resolution_import_rebinding.<locals>.check      dAGGIFFHr!   c                 \    t        |       }j                  t        |j                         y r   r   r`   r   r  r   rt  r   s     r   check_errorzDPatchTest.test_name_resolution_import_rebinding.<locals>.check_error       dAnagg6r!   package3zpackage3.submodulezpackage3.submodule.A.attrzpackage3.submodule.B.attrzpackage3.submodule:A.attrzpackage3.submodule:B.attrzpackage3:submodule.B.attrzpackage3:submodule.A.attrr  pathjoindirnamerv   __file__r   r   r   rL  rC  rH  s   `   r   %test_name_resolution_import_rebindingz/PatchTest.test_name_resolution_import_rebinding  s   
 ww||BGGOODMM:M6R		7 Z!56 	5d8K 	5-.34	5 	5 Z!56 	5d8K 	5-.34	5 	5 Z!56 	5d8K 	5-.34-.34-.34	5 	5 Z!56 	5d8K 	5-.34-.34-.34	5 	5 	5	5 	5 	5 	5	5 	5 	5 	5	5 	5 	5 	5	5 	5 	5 	5   "F.E;?FF 'F8F F8 1F,F8-G91G*G;F	 FFF	F  F),F5	1F88GG		GGc                     t         j                  j                  t         j                  j                  t        j
                        dd      }d } fd}t        dd      5  t        |      5   |d        |d       d d d        d d d        t        dd      5  t        |      5   |d	        |d
       d d d        d d d        t        dd      5  t        |      5   |d        |d        |d        |d        |d        |d       d d d        d d d        t        dd      5  t        |      5   |d        |d        |d	        |d
        |d        |d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   [xY w# 1 sw Y   y xY w)Nr?  r#  c                 Z    t        |       }|j                          |j                          y r   rA  rB  s     r   rC  z?PatchTest.test_name_resolution_import_rebinding2.<locals>.check  rD  r!   c                 \    t        |       }j                  t        |j                         y r   rF  rG  s     r   rH  zEPatchTest.test_name_resolution_import_rebinding2.<locals>.check_error  rI  r!   package4zpackage4.submodulezpackage4.submodule.A.attrzpackage4.submodule.B.attrzpackage4.submodule:A.attrzpackage4.submodule:B.attrzpackage4:submodule.B.attrzpackage4:submodule.A.attrrK  rP  s   `   r   &test_name_resolution_import_rebinding2z0PatchTest.test_name_resolution_import_rebinding2  s   ww||BGGOODMM:M6R		7 Z!56 	5d8K 	5-.34	5 	5 Z!56 	5d8K 	5-.34	5 	5 Z!56 	5d8K 	5-.34-.34-.34	5 	5 Z!56 	5d8K 	5-.34-.34-.34	5 	5 	5	5 	5 	5 	5	5 	5 	5 	5	5 	5 	5 	5	5 	5 	5 	5rR  c                    dD ]  }t        dt        z  fddi|di}| j                  t        |j                         | j                  t
        d        t        t        fddi|di}|j	                          |j                           y )Nr   r  r  z%s.doesnotexistr   Tc                      t         S r   )doesnotexistr3   r!   r   r   z1PatchTest.test_create_and_specs.<locals>.<lambda>  s     r!   )r   r"   r`   ra   r  r  MODNAMEr  )r   kwargrt  s      r   test_create_and_specszPatchTest.test_create_and_specs  s    5 		E'(2 '4 ''Ai1i)=> g<d<udm<AGGIFFH		r!   c                    t         }dD ]L  }t        t        fddi|di}| j                  t        |j
                         | j                  t         |       N dD ]L  }t        t        fddi|di}| j                  t        |j
                         | j                  t         |       N dD ]L  }t        t        fddi|di}| j                  t        |j
                         | j                  t         |       N y )Nr  r  r   r   r  r  )r  r  r   )r   r   r\  r`   ra   r  r  )r   r   r]  rt  s       r   test_multiple_specszPatchTest.test_multiple_specs  s    ) 	.Eg88eQZ8Ai1MM(H-	.
 * 	.Eg88eQZ8Ai1MM(H-	.
 . 	.Eg4A4%4Ai1MM(H-	.r!   c                     t        t        ddd      }|j                         }	 |j                   d|_        |j	                          y # |j	                          w xY w)NFrY  r_  )r   r\  r  does_not_existr  )r   rt  r   s      r    test_specs_false_instead_of_nonez*PatchTest.test_specs_false_instead_of_none%  sF    'Fwwy	"#DFFHAFFHs   A	 	Ac                     dD ]Q  }t        t        fi |di}|j                         }	 | j                  t        t
        |d       |j                          S y # |j                          w xY w)Nr  r   doesnotexit)r   r\  r  r`   r   r   r  r   r]  rt  r!  s       r   test_falsey_speczPatchTest.test_falsey_spec0  s^    5 	Eg,%,A	A!!.'1mL	 s   AA*c                    dD ]p  }t        t        fddi|di}|j                         }	 | j                  t        t
        |dd       | j                  t        t        |d       |j                          r y # |j                          w xY w)Nr`  r  Tr[  r   )r   r\  r  r`   r   r'   r   r  rg  s       r   test_spec_set_truezPatchTest.test_spec_set_true:  s|    ) 	Eg>>>A	A!!.'1"0+?!!.'1nM	 s   9A77B	c                     d}t        t        |      }|j                         }	 | j                  t	        |             |j                          y # |j                          w xY w)N)__call__r   )r   r\  r  rb   callabler  r   r   rt  r!  s       r   test_callable_spec_as_listz$PatchTest.test_callable_spec_as_listF  sF    '%GGI	OOHQK(FFHAFFH   A A"c                     d}t        t        |      }|j                         }	 | j                  t	        |             |j                          y # |j                          w xY w)Nr  r   )r   r\  r  rc   rm  r  rn  s       r   test_not_callable_spec_as_listz(PatchTest.test_not_callable_spec_as_listP  sH    '%GGI	Xa[)FFHAFFHrp  c                 Z    t         j                  t         j                  t         j                  }t	        dt
              j                          t	        dt              j                          t	        d       fd       } |         j                  t         j                  |       y )N	os.unlinkos.chdirzos.pathc                     t        j                          j                  t        j                  |        j                  t        j
                         j                  t        j                         y r   )r   stopallr  r  rL  unlinkchdir)	mock_pathry  r   rx  s    r   r  z-PatchTest.test_patch_stopall.<locals>.patcheda  sB    MMOMM"''9-MM"))V,MM"((E*r!   )	r  rx  ry  rL  r   r   r  r   r  )r   rL  r  ry  rx  s   `  @@r   test_patch_stopallzPatchTest.test_patch_stopallZ  st    wwk9%++-j.)//1	y		+ 
	+ 		bggt$r!   c                     g  G d dt               fd}dD cg c]  } ||      j                          c} t        j                          | j	                  g d       y c c}w )Nc                       e Zd ZdxZxZZy)*PatchTest.test_stopall_lifo.<locals>.thingN)r"   r#   r$   onetwothreer3   r!   r   r  r~  m  s     $$C$#r!   r  c                 T      G  fddt                fd d d dd d d i 	      S )Nc                   &     e Zd Z fdZ xZS )?PatchTest.test_stopall_lifo.<locals>.get_patch.<locals>.mypatchc                 B    j                         t        |          S r   )r  superr  )r   	__class__rl   mypatchstoppeds    r   r  zDPatchTest.test_stopall_lifo.<locals>.get_patch.<locals>.mypatch.stopr  s    NN9- $466r!   )r"   r#   r$   r  __classcell__)r  rl   r  r  s   @r   r  r  q  s    7 7r!   r  c                       S r   r3   r  s   r   r   z@PatchTest.test_stopall_lifo.<locals>.get_patch.<locals>.<lambda>u  s    5 r!   F)r   )rl   r  r  r  s   `@r   	get_patchz.PatchTest.test_stopall_lifo.<locals>.get_patchp  s6    7 7& 7 =)T4 $dB8 8r!   )r  r  r  )r  r  r  )r-   r  r   rw  rs   )r   r  r3  r  r  s      @@r   test_stopall_lifozPatchTest.test_stopall_lifok  sW    	%F 	%	8 ,CCC3			C"9: 	Ds   A'c                 ^   i }ddi}ddd|j                         }|j                         }j                         }t        j                  |ddd      j                          t        j                  |dd	i      j                          t        j                        fd
       } |        | j	                  ||       | j	                  ||       | j                  |       t        j                          | j                  ||       | j                  ||       | j                  |       y )Nr  r5   ABr  r  IIIr  rL   c                       d= y r
  r3   )dic3s   r   r  z2PatchTest.test_patch_dict_stopall.<locals>.patched  s
    Qr!   )rj  r   rk  r  r   rs   rw  )r   dic1dic2origdic1origdic2origdic3r  r  s          @r   test_patch_dict_stopallz!PatchTest.test_patch_dict_stopall|  s    3x399;99;99;

4ST*+113

4!S"((*	D		 
	 		D(+D(+x(x(x(x(r!   c                 \   t         j                  }t         j                  }i }ddd}|j                         }|j                         }t	        dt
              j                          t	        dt              j                          t	        j                  |ddd      j                          t	        j                  |      j                          |d= | j                  t         j                  |       | j                  t         j                  |       | j                  ||       | j                  ||       t	        j                          | j                  t         j                  |       | j                  t         j                  |       | j                  ||       | j                  ||       y )	Nr  r  r  rt  ru  r  r  r  )r  rx  ry  rj  r   r   r  r   rk  r  r   rw  r  rs   )r   original_unlinkoriginal_chdirr  r  r  r  s          r   !test_patch_and_patch_dict_stopallz+PatchTest.test_patch_and_patch_dict_stopall  s,   ))399;99;k9%++-j.)//1

4ST*+113

4 GO4>2D(+D(+bii1bhh/x(x(r!   c                 J   dd}t        j                  |dd      5  | j                   |       d       d d d        | j                   |       d       |j                  }t        j                  |dd      5  | j                  |j                  d       d d d        | j                  |j                  |       t        j                  |dd	      5  | j                  |j                  d	       d d d        | j                  |j                  t
               t        j                  |d
t        dg            5  | j                  |j                  t        dg             d d d        | j                  |j                  t                      ddd}t        j                  |dt        dg            5  | j                   |       d       d d d        | j                   |       d       y # 1 sw Y   xY w# 1 sw Y   bxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   TxY w)Nr   c                     | S )TESTr3   r  s    r   rG   z)PatchTest.test_special_attrs.<locals>.foo  s    Hr!   __defaults__)r  r  __doc__FUNr#   
testpatch2__annotations__)sr  r  c                     | S r   r3   )r  r5   s     r   rG   z)PatchTest.test_special_attrs.<locals>.foo  s    Hr!   __kwdefaults__)r  r  )r   )r   r-   rs   r  r#   r"   rk  r  )r   rG   orig_docs      r   test_special_attrszPatchTest.test_special_attrs  s   	 \\#~u5 	'SUA&	'";;\\#y%0 	1S[[%0	1h/\\#|\: 	;S^^\:	;2\\#0$
|2DE 	FS00$
|2DE	F,,df5 	\\#/zl1CD 	'SUA&	'"+	' 	'
	1 	1	; 	;	F 	F	' 	's;   G&6G3H 4'H.H&G03G= H
HH"c                 z   t               }t               |d<   d|d<   |j                         }t        t	        dt        d                  }t        |j                               |z   }t        j                  |t        |            5  | j                  t        |j                               |       d d d        | j                  ||       t        j                  ||      5  | j                  t        |j                               |       d d d        | j                  ||       y # 1 sw Y   vxY w# 1 sw Y   (xY w)Nr5   pythonrL   cdefghijklmnopqrstuvwxyz   )
r   r-   rj  rD  ziprangeitemsr   rk  rs   )r   rG   r   update_valuespatched_valuess        r   test_patch_orderdictzPatchTest.test_patch_orderdict  s    m8CC88:S!;U2YGHciik*]:ZZ[78 	@T#))+.?	@ 	h'ZZ]+ 	@T#))+.?	@ 	h'	@ 	@
	@ 	@s   *D% *D1%D.1D:c                    dd l }t        j                  d      5  t        j                  d= t        j                  d= t        j                  d= t        j                  d= t        d      d        } |        d d d        y # 1 sw Y   y xY w)	Nr   zsys.modulesr  ztest.test_unittest.testmockztest.test_unittestrv   %test.test_unittest.testmock.support.Xc                      y r   r3   r;  s    r   rv   z9PatchTest.test_dotted_but_module_not_loaded.<locals>.test  s    r!   )#test.test_unittest.testmock.supportr   rk  r  r  r   s     r   !test_dotted_but_module_not_loadedz+PatchTest.test_dotted_but_module_not_loaded  sz     	3ZZ& 
	AB9:01F# :; <F
	 
	 
	s   AB  B	c                      G d d      }dd |       fD ]F  }| j                  |      5  | j                  t              5  t        |       d d d        d d d        H y # 1 sw Y   xY w# 1 sw Y   _xY w)Nc                       e Zd Zy)*PatchTest.test_invalid_target.<locals>.FooNr~  r3   r!   r   r1   r    r  r!   r1       )r  )subTestr`   ra   r   )r   r1   r  s      r   test_invalid_targetzPatchTest.test_invalid_target  sw    	 	 2suo 	"FV, "&&y1 "&M"" "	"" "" "s#   A+ AA+A($A++A4	c                     t        dt               d      d        }| j                  t              5   |        d d d        y # 1 sw Y   y xY w)Nr  r  )r>  r  c                       y r   r3   r3   r!   r   rv   z@PatchTest.test_cant_set_kwargs_when_passing_a_mock.<locals>.test  s    r!   )r   r-   r`   ra   r   s     r   (test_cant_set_kwargs_when_passing_a_mockz2PatchTest.test_cant_set_kwargs_when_passing_a_mock  sE    	6FH	J 
Ky) 	F	 	 	s   AANT)ur"   r#   r$   rf   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r&  r0  r4  r;  rH  rS  rX  rm  rr  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r%  r*  r-  r6  r<  r?  rE  rH  rK  rT  r[  r]  rk  rq  ru  rx  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r   r(  r=  rQ  rW  r^  ra  rd  rh  rj  ro  rr  r{  r  r  r  r  r  r  r  r  r3   r!   r   r^   r^   W   so   :
/6

//(!(>V	0'-T				6864.(6,0/,/4/ (B/6(>/4*	:
"&"020
+**
+&&&>4$4$
3
3)@F($--??4

9
'
'*

&& %*>;
,&,*(,V,2,B/ $024<004:, ,e45 55, ,e4> 5>*86+BD 5D5>
.$	%";")4)2#6(&&"r!   r^   __main__r  )-r  r  collectionsr   rO  rv   test.test_unittest.testmockr   r  r   r   test.support.import_helperr   test.test_importlib.utilr   unittest.mockr	   r
   r   r   r   r   r   r   r   r   r   r   r  r"   r   r\  r/   rm   r   r   r   r-   r1   r  rM   rO   TestCaser^   mainr3   r!   r   <module>r     s   
 
 
 #   / F 4 ,    ;;x 
(
" 	((&  h  ! !$g!! gT= zHMMO r!   