§
    Ètºf’  ã                  óz   — d Z ddlmZ ddlmZ ddlmZ ddlmZ  G d„ d¦  «        Z	 G d„ d	ej
        ¦  «        Zd
S )z%
Tests for L{twisted.python.monkey}.
é    )Úannotations)ÚNoReturn)ÚMonkeyPatcher)Úunittestc                  ó   — e Zd Zdd„ZdS )ÚTestObjÚreturnÚNonec                ó0   — d| _         d| _        d| _        d S )Nz	foo valuez	bar valuez	baz value)ÚfooÚbarÚbaz©Úselfs    úW/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/test/test_monkey.pyÚ__init__zTestObj.__init__   s   € ØˆŒØˆŒØˆŒˆˆó    N©r	   r
   )Ú__name__Ú
__module__Ú__qualname__r   © r   r   r   r      s(   € € € € € ðð ð ð ð ð r   r   c                  óz   — e Zd ZdZdd„Zdd„Zdd„Zdd„Zdd„Zdd	„Z	dd
„Z
dd„Zdd„Zdd„Zdd„Zdd„Zdd„ZdS )ÚMonkeyPatcherTestsz;
    Tests for L{MonkeyPatcher} monkey-patching class.
    r	   r
   c                óx   — t          ¦   «         | _        t          ¦   «         | _        t          ¦   «         | _        d S ©N)r   Ú
testObjectÚoriginalObjectr   ÚmonkeyPatcherr   s    r   ÚsetUpzMonkeyPatcherTests.setUp   s+   € Ý!™)œ)ˆŒÝ%™iœiˆÔÝ*™_œ_ˆÔÐÐr   c                ó4  — | j                              ¦   «          |                      | j        j        | j        j        ¦  «         |                      | j        j        | j        j        ¦  «         |                      | j        j        | j        j        ¦  «         dS )zL
        A monkey patcher without patches shouldn't change a thing.
        N)r   ÚpatchÚassertEqualr   r   r   r   r   r   s    r   Ú
test_emptyzMonkeyPatcherTests.test_empty    s„   € ð 	Ô× Ò Ñ"Ô"Ð"ð 	×Ò˜Ô,Ô0°$´/Ô2EÑFÔFÐFØ×Ò˜Ô,Ô0°$´/Ô2EÑFÔFÐFØ×Ò˜Ô,Ô0°$´/Ô2EÑFÔFÐFÐFÐFr   c                óB  — t          | j        ddf| j        ddf¦  «        }|                     ¦   «          |                      d| j        j        ¦  «         |                      d| j        j        ¦  «         |                      | j        j        | j        j        ¦  «         dS )z}
        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_constructWithPatchesz,MonkeyPatcherTests.test_constructWithPatches,   s–   € õ
  ØŒ_˜e VÐ,¨t¬ÀÀvÐ.Nñ
ô 
ˆð 	�Š‰ŒˆØ×Ò˜ ¤Ô!4Ñ5Ô5Ð5Ø×Ò˜ ¤Ô!4Ñ5Ô5Ð5Ø×Ò˜Ô,Ô0°$´/Ô2EÑFÔFÐFÐFÐFr   c                óº   — | j                              | j        dd¦  «         | j                              ¦   «          |                      | j        j        d¦  «         dS )zf
        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_patchExistingz%MonkeyPatcherTests.test_patchExisting9   sW   € ð
 	Ô×#Ò# D¤O°U¸FÑCÔCÐCØÔ× Ò Ñ"Ô"Ð"Ø×Ò˜œÔ,¨fÑ5Ô5Ð5Ð5Ð5r   c                ó’   — | j                              | j        dd¦  «         |                      t          | j         j        ¦  «         dS )zT
        Patching a non-existing attribute fails with an C{AttributeError}.
        Únowherezblow up pleaseN)r   r+   r   ÚassertRaisesÚAttributeErrorr"   r   s    r   Útest_patchNonExistingz(MonkeyPatcherTests.test_patchNonExistingB   sD   € ð 	Ô×#Ò# D¤O°YÐ@PÑQÔQÐQØ×Ò�.¨$Ô*<Ô*BÑCÔCÐCÐCÐCr   c                ó‚  — | j                              | j        dd¦  «         | j                              | j        dd¦  «         | j                              ¦   «          |                      | j        j        d¦  «         | j                              ¦   «          |                      | j        j        | j        j        ¦  «         dS )z|
        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_patchAlreadyPatchedz+MonkeyPatcherTests.test_patchAlreadyPatchedI   sª   € ð
 	Ô×#Ò# D¤O°U¸FÑCÔCÐCØÔ×#Ò# D¤O°U¸FÑCÔCÐCØÔ× Ò Ñ"Ô"Ð"Ø×Ò˜œÔ,¨fÑ5Ô5Ð5ØÔ×"Ò"Ñ$Ô$Ð$Ø×Ò˜œÔ,¨dÔ.AÔ.EÑFÔFÐFÐFÐFr   c                ó†  — | j                              | j        dd¦  «         | j                              ¦   «          | j                              ¦   «          |                      | j        j        | j        j        ¦  «         | j                              ¦   «          |                      | j        j        | j        j        ¦  «         dS )zH
        Restoring an already-restored monkey patch is a no-op.
        r   r3   N)r   r+   r   r"   r5   r#   r   r   r   s    r   Útest_restoreTwiceIsANoOpz+MonkeyPatcherTests.test_restoreTwiceIsANoOpU   s¨   € ð 	Ô×#Ò# D¤O°U¸FÑCÔCÐCØÔ× Ò Ñ"Ô"Ð"ØÔ×"Ò"Ñ$Ô$Ð$Ø×Ò˜œÔ,¨dÔ.AÔ.EÑFÔFÐFØÔ×"Ò"Ñ$Ô$Ð$Ø×Ò˜œÔ,¨dÔ.AÔ.EÑFÔFÐFÐFÐFr   c                ó°   ‡— g Šddˆfd	„}| j                              |d
dd¬¦  «        }|                      d|¦  «         |                      dg‰¦  «         dS )z¤
        runWithPatches should run the given callable, passing in all arguments
        and keyword arguments, and return the return value of the callable.
        NÚaÚintÚbÚcú
int | Noner	   Ústrc                ó8   •— ‰                      | ||f¦  «         dS )Nr   )Úappend)r:   r<   r=   Úlogs      €r   Úfz;MonkeyPatcherTests.test_runWithPatchesDecoration.<locals>.fg   s    ø€ Ø�JŠJ˜˜1˜a�yÑ!Ô!Ð!Ø�5r   é   é   é
   )r=   r   )rD   rE   rF   r   )r:   r;   r<   r;   r=   r>   r	   r?   )r   ÚrunWithPatchesr#   )r   rC   ÚresultrB   s      @r   Útest_runWithPatchesDecorationz0MonkeyPatcherTests.test_runWithPatchesDecoration`   s‚   ø€ ð
 24ˆð	ð 	ð 	ð 	ð 	ð 	ð 	ð Ô#×2Ò2°1°a¸¸bÐ2ÑAÔAˆØ×Ò˜ Ñ'Ô'Ð'Ø×Ò˜*˜ sÑ+Ô+Ð+Ð+Ð+r   c                ór  ‡ — dˆ fd„}‰ j                              ‰ j        dd¦  «         ‰ j                              |¦  «        }‰                      d‰ j        j        ‰ j        j        f|¦  «         ‰ j                              |¦  «        }‰                      d‰ j        j        ‰ j        j        f|¦  «         dS )z‘
        We should be able to call the same function with runWithPatches more
        than once. All patches should apply for each call.
        r	   útuple[str, str, str]c                 óJ   •— ‰ j         j        ‰ j         j        ‰ j         j        fS r   )r   r   r   r   r   s   €r   rC   z9MonkeyPatcherTests.test_repeatedRunWithPatches.<locals>.fu   s   ø€ Ø”OÔ'¨¬Ô)<¸d¼oÔ>QÐRÐRr   r   r&   N)r	   rK   )r   r+   r   rG   r#   r   r   r   )r   rC   rH   s   `  r   Útest_repeatedRunWithPatchesz.MonkeyPatcherTests.test_repeatedRunWithPatcheso   sÞ   ø€ ð	Sð 	Sð 	Sð 	Sð 	Sð 	Sð 	Ô×#Ò# D¤O°U¸FÑCÔCÐCØÔ#×2Ò2°1Ñ5Ô5ˆØ×ÒØ�TÔ(Ô,¨dÔ.AÔ.EÐFÈñ	
ô 	
ð 	
ð Ô#×2Ò2°1Ñ5Ô5ˆØ×ÒØ�TÔ(Ô,¨dÔ.AÔ.EÐFÈñ	
ô 	
ð 	
ð 	
ð 	
r   c                ó&  — | j                              | j        dd¦  «         |                      | j        j        | j        j        ¦  «         | j                              d„ ¦  «         |                      | j        j        | j        j        ¦  «         dS )zo
        C{runWithPatches} should restore the original values after the function
        has executed.
        r   r&   c                 ó   — d S r   r   r   r   r   ú<lambda>z@MonkeyPatcherTests.test_runWithPatchesRestores.<locals>.<lambda>‰   s   € °$€ r   N)r   r+   r   r#   r   r   rG   r   s    r   Útest_runWithPatchesRestoresz.MonkeyPatcherTests.test_runWithPatchesRestores‚   s‚   € ð
 	Ô×#Ò# D¤O°U¸FÑCÔCÐCØ×Ò˜Ô,Ô0°$´/Ô2EÑFÔFÐFØÔ×)Ò)¨,¨,Ñ7Ô7Ð7Ø×Ò˜Ô,Ô0°$´/Ô2EÑFÔFÐFÐFÐFr   c                óŒ  ‡ — d	ˆ fd„}‰ j                              ‰ j        dd¦  «         ‰ j                              ‰ j        dd¦  «         ‰                      t          ‰ j         j        |¦  «         ‰                      ‰ j        j        ‰ j        j        ¦  «         ‰                      ‰ j        j	        ‰ j        j	        ¦  «         dS )
zv
        Test runWithPatches restores the original values even when the function
        raises an exception.
        r	   r   c                 ó¢   •— ‰                       ‰ j        j        d¦  «         ‰                       ‰ j        j        d¦  «         t	          d¦  «        ‚)Nr&   ÚblahblahzSomething went wrong!)r#   r   r   r   ÚRuntimeErrorr   s   €r   Ú_zDMonkeyPatcherTests.test_runWithPatchesRestoresOnException.<locals>._’   sH   ø€ Ø×Ò˜Tœ_Ô0°&Ñ9Ô9Ð9Ø×Ò˜Tœ_Ô0°*Ñ=Ô=Ð=ÝÐ6Ñ7Ô7Ð7r   r   r&   r   rT   N)r	   r   )
r   r+   r   r/   rU   rG   r#   r   r   r   )r   rV   s   ` r   Ú&test_runWithPatchesRestoresOnExceptionz9MonkeyPatcherTests.test_runWithPatchesRestoresOnExceptionŒ   sÃ   ø€ ð	8ð 	8ð 	8ð 	8ð 	8ð 	8ð
 	Ô×#Ò# D¤O°U¸FÑCÔCÐCØÔ×#Ò# D¤O°U¸JÑGÔGÐGà×Ò�,¨Ô(:Ô(IÈ1ÑMÔMÐMØ×Ò˜œÔ,¨dÔ.AÔ.EÑFÔFÐFØ×Ò˜œÔ,¨dÔ.AÔ.EÑFÔFÐFÐFÐFr   c                ó  — | j                              | j        dd¦  «         | j         5  |                      | j        j        d¦  «         ddd¦  «         n# 1 swxY w Y   |                      | j        j        | j        j        ¦  «         dS )z†
        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_contextManagerz&MonkeyPatcherTests.test_contextManagerž   sÒ   € ð
 	Ô×#Ò# D¤O°U¸OÑLÔLÐLØÔð 	Cð 	CØ×Ò˜Tœ_Ô0°/ÑBÔBÐBð	Cð 	Cð 	Cñ 	Cô 	Cð 	Cð 	Cð 	Cð 	Cð 	Cð 	Cøøøð 	Cð 	Cð 	Cð 	Cà×Ò˜œÔ,¨dÔ.AÔ.EÑFÔFÐFÐFÐFs   ©!AÁAÁAc                ó²   — |                       t          ¦  «        5  | j        5  t          d¦  «        ‚# 1 swxY w Y   	 ddd¦  «         dS # 1 swxY w Y   dS )zh
        Exceptions propagate through the L{MonkeyPatcher} context-manager
        exit method.
        Ú	somethingN)r/   rU   r   r   s    r   Ú'test_contextManagerPropagatesExceptionsz:MonkeyPatcherTests.test_contextManagerPropagatesExceptions¨   sÊ   € ð
 ×Ò�|Ñ,Ô,ð 	0ð 	0ØÔ#ð 0ð 0Ý" ;Ñ/Ô/Ð/ð0ð 0ð 0ð 0øøøð 0ð 0ð 0ð 0ð 0ð	0ð 	0ð 	0ñ 	0ô 	0ð 	0ð 	0ð 	0ð 	0ð 	0ð 	0ð 	0øøøð 	0ð 	0ð 	0ð 	0ð 	0ð 	0s'   ›A£3³7	·Aº7	»AÁAÁANr   )r   r   r   Ú__doc__r    r$   r)   r,   r1   r6   r8   rI   rM   rQ   rW   rY   r\   r   r   r   r   r      sB  € € € € € ðð ð-ð -ð -ð -ð

Gð 
Gð 
Gð 
GðGð Gð Gð Gð6ð 6ð 6ð 6ðDð Dð Dð Dð
Gð 
Gð 
Gð 
Gð	Gð 	Gð 	Gð 	Gð,ð ,ð ,ð ,ð
ð 
ð 
ð 
ð&Gð Gð Gð GðGð Gð Gð Gð$Gð Gð Gð Gð0ð 0ð 0ð 0ð 0ð 0r   r   N)r]   Ú
__future__r   Útyping_extensionsr   Útwisted.python.monkeyr   Útwisted.trialr   r   ÚSynchronousTestCaser   r   r   r   ú<module>rc      sÂ   ððð ð #Ð "Ð "Ð "Ð "Ð "à &Ð &Ð &Ð &Ð &Ð &à /Ð /Ð /Ð /Ð /Ð /Ø "Ð "Ð "Ð "Ð "Ð "ðð ð ð ð ñ ô ð ðY0ð Y0ð Y0ð Y0ð Y0˜Ô5ñ Y0ô Y0ð Y0ð Y0ð Y0r   