+
    üÐ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°$·/±/×2EÑ2EÔFØ×Ñ˜×,Ñ,×0Ñ0°$·/±/×2EÑ2EÔFØ×Ñ˜×,Ñ,×0Ñ0°$·/±/×2EÑ2EÖ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Ž   € ô
  Ø�_‰_˜e VÐ,¨t¯©ÀÀvÐ.Nó
ˆð 	�‰ŒØ×Ñ˜ §¡×!4Ñ!4Ô5Ø×Ñ˜ §¡×!4Ñ!4Ô5Ø×Ñ˜×,Ñ,×0Ñ0°$·/±/×2EÑ2EÖFr   c               ó   € V ^8„  d   QhRR/# r	   r   )r   s   "r   r   r#   9   s   € ÷ 6ñ 6 Dñ 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   € ð
 	×Ñ×#Ñ# D§O¡O°U¸FÔ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=   € ð 	×Ñ×#Ñ# D§O¡O°YÐ@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    € ð
 	×Ñ×#Ñ# D§O¡O°U¸FÔCØ×Ñ×#Ñ# D§O¡O°U¸FÔ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¢   € ð 	×Ñ×#Ñ# D§O¡O°U¸FÔ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   ø€ Ø�J‰J˜˜a�yÔ!Ùr   )rU   r   r%   )é   r
   é
   )r(   ÚrunWithPatchesr.   )r   r[   ÚresultrZ   s   &  @r   Útest_runWithPatchesDecorationÚ0MonkeyPatcherTests.test_runWithPatchesDecoration`   sW   ø€ ð
 24ˆ÷	ò 	ð ×#Ñ#×2Ñ2°1°a¸¸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.   ø€ Ø—O‘O×'Ñ'¨¯©×)<Ñ)<¸d¿o¹o×>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ð 	×Ñ×#Ñ# D§O¡O°U¸FÔCØ×#Ñ#×2Ñ2°1Ó5ˆØ×ÑØ�T×(Ñ(×,Ñ,¨d×.AÑ.A×.EÑ.EÐFÈô	
ð ×#Ñ#×2Ñ2°1Ó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€   € ð
 	×Ñ×#Ñ# D§O¡O°U¸FÔCØ×Ñ˜×,Ñ,×0Ñ0°$·/±/×2EÑ2EÔFØ×Ñ×)Ñ)©,Ô7Ø×Ñ˜×,Ñ,×0Ñ0°$·/±/×2EÑ2EÖ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ñ 	8�8ñ 	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_runWithPatchesRestoresOnExceptionÚ9MonkeyPatcherTests.test_runWithPatchesRestoresOnExceptionŒ   s±   ø€ ÷	8ð 	8ð
 	×Ñ×#Ñ# D§O¡O°U¸FÔCØ×Ñ×#Ñ# D§O¡O°U¸JÔGà×Ñœ,¨×(:Ñ(:×(IÑ(IÈ1Ô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   € ð
 	×Ñ×#Ñ# D§O¡O°U¸OÔ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   