ó
    ×›‘h’  ã                  óv   • S r SSKJr  SSKJr  SSKJr  SSKJr   " S S5      r	 " S S	\R                  5      rg
)z%
Tests for L{twisted.python.monkey}.
é    )Úannotations)ÚNoReturn)ÚMonkeyPatcher)Úunittestc                  ó   • \ rS rSrSS jrSrg)ÚTestObjé   c                ó.   • SU l         SU l        SU l        g )Nz	foo valuez	bar valuez	baz value)ÚfooÚbarÚbaz©Úselfs    Ú\C:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/test/test_monkey.pyÚ__init__ÚTestObj.__init__   s   € ØˆŒØˆŒØˆ�ó    )r   r   r   N©ÚreturnÚNone)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   Ú__static_attributes__© r   r   r   r      s   † ÷r   r   c                  óš   • \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	SS jr
SS	 jrSS
 jrSS jrSS jrSS jrSS jrSS jrSrg)ÚMonkeyPatcherTestsé   z3
Tests for L{MonkeyPatcher} monkey-patching class.
c                ó^   • [        5       U l        [        5       U l        [        5       U l        g ©N)r   Ú
testObjectÚoriginalObjectr   ÚmonkeyPatcherr   s    r   ÚsetUpÚMonkeyPatcherTests.setUp   s   € Ü!›)ˆŒÜ%›iˆÔÜ*›_ˆÕr   c                ó”  • U R                   R                  5         U R                  U R                  R                  U R
                  R                  5        U R                  U R                  R                  U R
                  R                  5        U R                  U R                  R                  U R
                  R                  5        g)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                ó|  • [        U R                  SS4U R                  SS45      nUR                  5         U R                  SU R                  R                  5        U R                  SU R                  R
                  5        U R                  U R                  R                  U R                  R                  5        g)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                óÒ   • U R                   R                  U R                  SS5        U R                   R                  5         U R	                  U R                  R
                  S5        g)zN
Patching an attribute that exists sets it to the value defined in the
patch.
r   r-   N)r$   ÚaddPatchr"   r(   r)   r   r   s    r   Útest_patchExistingÚ%MonkeyPatcherTests.test_patchExisting9   sL   € ð
 	×Ñ×#Ñ# D§O¡O°U¸FÔCØ×Ñ× Ñ Ô"Ø×Ñ˜Ÿ™×,Ñ,¨fÕ5r   c                ó¦   • U R                   R                  U R                  SS5        U R                  [        U R                   R
                  5        g)zD
Patching a non-existing attribute fails with an C{AttributeError}.
Únowherezblow up pleaseN)r$   r3   r"   ÚassertRaisesÚAttributeErrorr(   r   s    r   Útest_patchNonExistingÚ(MonkeyPatcherTests.test_patchNonExistingB   s=   € ð 	×Ñ×#Ñ# D§O¡O°YÐ@PÔQØ×Ñœ.¨$×*<Ñ*<×*BÑ*BÕCr   c                óÈ  • U R                   R                  U R                  SS5        U R                   R                  U R                  SS5        U R                   R                  5         U R	                  U R                  R
                  S5        U R                   R                  5         U R	                  U R                  R
                  U R                  R
                  5        g)zd
Adding a patch for an object and attribute that already have a patch
overrides the existing patch.
r   ÚblahÚBLAHN)r$   r3   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                óÖ  • U R                   R                  U R                  SS5        U R                   R                  5         U R                   R	                  5         U R                  U R                  R                  U R                  R                  5        U R                   R	                  5         U R                  U R                  R                  U R                  R                  5        g)z8
Restoring an already-restored monkey patch is a no-op.
r   r=   N)r$   r3   r"   r(   r?   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                ó    ^• / mS	S
U4S jjjnU R                   R                  USSSS9nU R                  SU5        U R                  S/T5        g)zŒ
runWithPatches should run the given callable, passing in all arguments
and keyword arguments, and return the return value of the callable.
Nc                ó,   >• TR                  XU45        g)Nr   )Úappend)ÚaÚbÚcÚlogs      €r   ÚfÚ;MonkeyPatcherTests.test_runWithPatchesDecoration.<locals>.fg   s   ø€ Ø�J‰J˜˜a�yÔ!Ør   é   é   é
   )rJ   r   )rN   rO   rP   r!   )rH   ÚintrI   rQ   rJ   z
int | Noner   Ústr)r$   ÚrunWithPatchesr)   )r   rL   ÚresultrK   s      @r   Útest_runWithPatchesDecorationÚ0MonkeyPatcherTests.test_runWithPatchesDecoration`   sW   ø€ ð
 24ˆ÷	ñ 	ð ×#Ñ#×2Ñ2°1°a¸¸bÐ2ÐAˆØ×Ñ˜ Ô'Ø×Ñ˜*˜ sÕ+r   c                óÄ  ^ • SU 4S jjnT R                   R                  T R                  SS5        T R                   R                  U5      nT R	                  ST R
                  R                  T R
                  R                  4U5        T R                   R                  U5      nT R	                  ST R
                  R                  T R
                  R                  4U5        g)zy
We should be able to call the same function with runWithPatches more
than once. All patches should apply for each call.
c                 ó†   >• T R                   R                  T R                   R                  T R                   R                  4$ r!   )r"   r   r   r   r   s   €r   rL   Ú9MonkeyPatcherTests.test_repeatedRunWithPatches.<locals>.fu   s.   ø€ Ø—O‘O×'Ñ'¨¯©×)<Ñ)<¸d¿o¹o×>QÑ>QÐRÐRr   r   r-   N)r   ztuple[str, str, str])r$   r3   r"   rS   r)   r#   r   r   )r   rL   rT   s   `  r   Útest_repeatedRunWithPatchesÚ.MonkeyPatcherTests.test_repeatedRunWithPatcheso   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                ór  • U R                   R                  U R                  SS5        U R                  U R                  R
                  U R                  R
                  5        U R                   R                  S 5        U R                  U R                  R
                  U R                  R
                  5        g)zW
C{runWithPatches} should restore the original values after the function
has executed.
r   r-   c                 ó   • g r!   r   r   r   r   Ú<lambda>Ú@MonkeyPatcherTests.test_runWithPatchesRestores.<locals>.<lambda>‰   s   € °$r   N)r$   r3   r"   r)   r#   r   rS   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                óð  ^ • SU 4S jjnT R                   R                  T R                  SS5        T R                   R                  T R                  SS5        T R                  [        T R                   R
                  U5        T R                  T R                  R                  T R                  R                  5        T R                  T R                  R                  T R                  R                  5        g)z^
Test runWithPatches restores the original values even when the function
raises an exception.
c                 ó²   >• T R                  T R                  R                  S5        T R                  T R                  R                  S5        [	        S5      e)Nr-   Ú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   r-   r   rd   N)r   r   )
r$   r3   r"   r8   re   rS   r)   r   r#   r   )r   rf   s   ` r   Ú&test_runWithPatchesRestoresOnExceptionÚ9MonkeyPatcherTests.test_runWithPatchesRestoresOnExceptionŒ   s¬   ø€ ÷	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                ó^  • U R                   R                  U R                  SS5        U R                      U R                  U R                  R                  S5        SSS5        U R                  U R                  R                  U R
                  R                  5        g! , (       d  f       NI= f)zn
L{MonkeyPatcher} is a context manager that applies its patches on
entry and restore original values on exit.
r   zpatched valueN)r$   r3   r"   r)   r   r#   r   s    r   Útest_contextManagerÚ&MonkeyPatcherTests.test_contextManagerž   sw   € ð
 	×Ñ×#Ñ# D§O¡O°U¸OÔLØ×ÓØ×Ñ˜TŸ_™_×0Ñ0°/ÔB÷  à×Ñ˜Ÿ™×,Ñ,¨d×.AÑ.A×.EÑ.EÕF÷  Õús   ´'BÂ
B,c                ó¶   • U R                  [        5         U R                     [        S5      e! , (       d  f       O= f SSS5        g! , (       d  f       g= f)zP
Exceptions propagate through the L{MonkeyPatcher} context-manager
exit method.
Ú	somethingN)r8   re   r$   r   s    r   Ú'test_contextManagerPropagatesExceptionsÚ:MonkeyPatcherTests.test_contextManagerPropagatesExceptions¨   s>   € ð
 ×Ñœ|Õ,Ø×#Ó#Ü" ;Ó/Ð/÷ $Õ#úÐ#÷ -×,Ö,ús   –A
£/¯
=	¹A
Á

A)r$   r#   r"   Nr   )r   r   r   r   Ú__doc__r%   r*   r0   r4   r:   r@   rC   rU   rZ   r`   rh   rk   ro   r   r   r   r   r   r      sP   † ñô-ô

GôGô6ôDô
Gô	Gô,ô
ô&GôGô$G÷0r   r   N)rq   Ú
__future__r   Útyping_extensionsr   Útwisted.python.monkeyr   Útwisted.trialr   r   ÚSynchronousTestCaser   r   r   r   Ú<module>rw      s6   ðñõ #å &å /Ý "÷ñ ôY0˜×5Ñ5õ Y0r   