+
    Dfj                    x    R t ^ RIHt ^ RIHt ^ RIHt ^ RIHt  ! R R4      t	 ! R R]P                  4      tR	# )
z%
Tests for L{twisted.python.monkey}.
)annotations)NoReturn)MonkeyPatcher)unittestc                  "    ] tR t^tR R ltRtR# )TestObjc                   V ^8  d   QhRR/#    returnNone )formats   ":/usr/lib/python3/dist-packages/twisted/test/test_monkey.py__annotate__TestObj.__annotate__   s      $     c                	0    R V n         RV n        RV n        R# )z	foo valuez	bar valuez	baz valueN)foobarbazselfs   &r   __init__TestObj.__init__   s    r   )r   r   r   N)__name__
__module____qualname____firstlineno__r   __static_attributes__r   r   r   r   r      s     r   r   c                      ] tR t^tRtR R ltR R ltR R ltR R	 ltR
 R lt	R R lt
R R ltR R ltR R ltR R ltR R ltR R ltR R ltRtR# )MonkeyPatcherTestsz3
Tests for L{MonkeyPatcher} monkey-patching class.
c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   MonkeyPatcherTests.__annotate__   s     - -t -r   c                	`    \        4       V n        \        4       V n        \        4       V n        R # N)r   
testObjectoriginalObjectr   monkeyPatcherr   s   &r   setUpMonkeyPatcherTests.setUp   s    !)%i*_r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r#       s     
G 
GD 
Gr   c                   V P                   P                  4        V P                  V P                  P                  V P
                  P                  4       V P                  V P                  P                  V P
                  P                  4       V P                  V P                  P                  V P
                  P                  4       R# )z<
A monkey patcher without patches shouldn't change a thing.
N)r(   patchassertEqualr'   r   r&   r   r   r   s   &r   
test_emptyMonkeyPatcherTests.test_empty    s     	  " 	,,00$//2E2EF,,00$//2E2EF,,00$//2E2EFr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r#   ,   s     G G4 Gr   c                ~   \        V P                  RR3V P                  RR34      pVP                  4        V P                  RV P                  P                  4       V P                  RV P                  P
                  4       V P                  V P                  P                  V P                  P                  4       R# )ze
Constructing a L{MonkeyPatcher} with patches should add all of the
given patches to the patch list.
r   hahar   heheN)r   r&   r-   r.   r   r   r'   r   )r   patchers   & r   test_constructWithPatches,MonkeyPatcherTests.test_constructWithPatches,   s    
  __eV,tv.N
 	!4!45!4!45,,00$//2E2EFr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r#   9   s     6 6D 6r   c                    V P                   P                  V P                  RR4       V P                   P                  4        V P	                  V P                  P
                  R4       R# )zN
Patching an attribute that exists sets it to the value defined in the
patch.
r   r3   N)r(   addPatchr&   r-   r.   r   r   s   &r   test_patchExisting%MonkeyPatcherTests.test_patchExisting9   sL    
 	##DOOUFC  ",,f5r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r#   B   s     D Dt Dr   c                    V P                   P                  V P                  RR4       V P                  \        V P                   P
                  4       R# )zD
Patching a non-existing attribute fails with an C{AttributeError}.
nowherezblow up pleaseN)r(   r:   r&   assertRaisesAttributeErrorr-   r   s   &r   test_patchNonExisting(MonkeyPatcherTests.test_patchNonExistingB   s=     	##DOOY@PQ.$*<*<*B*BCr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r#   I   s     
G 
G$ 
Gr   c                   V P                   P                  V P                  RR4       V P                   P                  V P                  RR4       V P                   P                  4        V P	                  V P                  P
                  R4       V P                   P                  4        V P	                  V P                  P
                  V P                  P
                  4       R# )zd
Adding a patch for an object and attribute that already have a patch
overrides the existing patch.
r   blahBLAHN)r(   r:   r&   r-   r.   r   restorer'   r   s   &r   test_patchAlreadyPatched+MonkeyPatcherTests.test_patchAlreadyPatchedI   s    
 	##DOOUFC##DOOUFC  ",,f5""$,,d.A.A.E.EFr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r#   U   s     	G 	G$ 	Gr   c                   V P                   P                  V P                  RR4       V P                   P                  4        V P                   P	                  4        V P                  V P                  P                  V P                  P                  4       V P                   P	                  4        V P                  V P                  P                  V P                  P                  4       R# )z8
Restoring an already-restored monkey patch is a no-op.
r   rF   N)r(   r:   r&   r-   rH   r.   r   r'   r   s   &r   test_restoreTwiceIsANoOp+MonkeyPatcherTests.test_restoreTwiceIsANoOpU   s     	##DOOUFC  """$,,d.A.A.E.EF""$,,d.A.A.E.EFr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r#   `   s     , ,t ,r   c                   a . oRR V3R lllpV P                   P                  V^^^
R7      pV P                  RV4       V P                  R.S4       R# )z
runWithPatches should run the given callable, passing in all arguments
and keyword arguments, and return the return value of the callable.
Nc               (    V ^8  d   QhRRRRRRRR/# )r
   aintbcz
int | Noner   strr   )r   s   "r   r   FMonkeyPatcherTests.test_runWithPatchesDecoration.<locals>.__annotate__g   s(     	 	 	 	 	s 	r   c                .   < SP                  WV34       R # )r   )append)rR   rT   rU   logs   &&&r   f;MonkeyPatcherTests.test_runWithPatchesDecoration.<locals>.fg   s    JJay!r   )rU   r   r%   )   r
   
   )r(   runWithPatchesr.   )r   r[   resultrZ   s   &  @r   test_runWithPatchesDecoration0MonkeyPatcherTests.test_runWithPatchesDecoration`   sW    
 24	 	 ##221ab2A'*s+r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r#   o   s     
 
T 
r   c                  a  R V 3R llpS P                   P                  S P                  RR4       S P                   P                  V4      pS P	                  RS P
                  P                  S P
                  P                  3V4       S P                   P                  V4      pS P	                  RS P
                  P                  S P
                  P                  3V4       R# )zy
We should be able to call the same function with runWithPatches more
than once. All patches should apply for each call.
c                   V ^8  d   QhRR/# )r
   r   ztuple[str, str, str]r   )r   s   "r   r   DMonkeyPatcherTests.test_repeatedRunWithPatches.<locals>.__annotate__u   s     	S 	S' 	Sr   c                    < S P                   P                  S P                   P                  S P                   P                  3# r%   )r&   r   r   r   r   s   r   r[   9MonkeyPatcherTests.test_repeatedRunWithPatches.<locals>.fu   s.    OO'')<)<doo>Q>QRRr   r   r3   N)r(   r:   r&   r_   r.   r'   r   r   )r   r[   r`   s   f  r   test_repeatedRunWithPatches.MonkeyPatcherTests.test_repeatedRunWithPatcheso   s    	S 	S 	##DOOUFC##2215T((,,d.A.A.E.EF	
 ##2215T((,,d.A.A.E.EF	
r   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r#      s     G GT Gr   c                t   V P                   P                  V P                  RR4       V P                  V P                  P
                  V P                  P
                  4       V P                   P                  R 4       V P                  V P                  P
                  V P                  P
                  4       R# )zW
C{runWithPatches} should restore the original values after the function
has executed.
r   r3   c                     R # r%   r   r   r   r   <lambda>@MonkeyPatcherTests.test_runWithPatchesRestores.<locals>.<lambda>   s    $r   N)r(   r:   r&   r.   r'   r   r_   r   s   &r   test_runWithPatchesRestores.MonkeyPatcherTests.test_runWithPatchesRestores   s    
 	##DOOUFC,,00$//2E2EF)),7,,00$//2E2EFr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r#      s     G G Gr   c                  a  R V 3R llpS P                   P                  S P                  RR4       S P                   P                  S P                  RR4       S P                  \        S P                   P
                  V4       S P                  S P                  P                  S P                  P                  4       S P                  S P                  P                  S P                  P                  4       R# )z^
Test runWithPatches restores the original values even when the function
raises an exception.
c                   V ^8  d   QhRR/# )r
   r   r   r   )r   s   "r   r   OMonkeyPatcherTests.test_runWithPatchesRestoresOnException.<locals>.__annotate__   s     	8 	88 	8r   c                    < S P                  S P                  P                  R 4       S P                  S P                  P                  R4       \	        R4      h)r3   blahblahzSomething went wrong!)r.   r&   r   r   RuntimeErrorr   s   r   _DMonkeyPatcherTests.test_runWithPatchesRestoresOnException.<locals>._   sC    T__00&9T__00*=677r   r   r3   r   rw   N)
r(   r:   r&   r@   rx   r_   r.   r   r'   r   )r   ry   s   f r   &test_runWithPatchesRestoresOnException9MonkeyPatcherTests.test_runWithPatchesRestoresOnException   s    	8 	8
 	##DOOUFC##DOOUJG,(:(:(I(I1M,,d.A.A.E.EF,,d.A.A.E.EFr   c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r#      s     G GT Gr   c                t   V P                   P                  V P                  RR4       V P                   ;_uu_ 4        V P                  V P                  P                  R4       RRR4       V P                  V P                  P                  V P
                  P                  4       R#   + '       g   i     LL; i)zn
L{MonkeyPatcher} is a context manager that applies its patches on
entry and restore original values on exit.
r   zpatched valueN)r(   r:   r&   r.   r   r'   r   s   &r   test_contextManager&MonkeyPatcherTests.test_contextManager   sz    
 	##DOOUOLT__00/B  ,,d.A.A.E.EF  s   'B''B7	c                   V ^8  d   QhRR/# r	   r   )r   s   "r   r   r#      s     0 0 0r   c           	         V P                  \        4      ;_uu_ 4        V P                  ;_uu_ 4        \        R4      h  + '       g   i     M; i RRR4       R#   + '       g   i     R# ; i)zP
Exceptions propagate through the L{MonkeyPatcher} context-manager
exit method.
	somethingN)r@   rx   r(   r   s   &r   'test_contextManagerPropagatesExceptions:MonkeyPatcherTests.test_contextManagerPropagatesExceptions   sG    
 |,,###";// $## -,,,s   A?	A
AA.	)r(   r'   r&   N)r   r   r   r   __doc__r)   r/   r6   r;   rB   rI   rM   ra   ri   rp   r{   r   r   r   r   r   r   r!   r!      sU    -

GG6D
G	G,
&GG$G0 0r   r!   N)r   
__future__r   typingr   twisted.python.monkeyr   twisted.trialr   r   SynchronousTestCaser!   r   r   r   <module>r      s6    #  / " Y055 Y0r   