Ë
    oj–V  ã                  óœ  — d Z ddlmZ ddlZddlZddlZddlmZ ddlm	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 ddl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   G d„ de«      Z! G d„ de«      Z" G d„ d«      Z# G d„ d«      Z$ G d„ de«      Z% G d„ de«      Z& G d„ de«      Z' G d„ de«      Z( G d„ d e«      Z) G d!„ d"e«      Z*y)#z!
Tests for L{twisted.trial.util}
é    )ÚannotationsN)ÚStringIO)Ú	Generator)Úimplementer)Úassert_thatÚequal_to)ÚDelayedCall)ÚIProcessTransport)Úfilepath)ÚFailure)Úutil)ÚSynchronousTestCase)ÚDirtyReactorAggregateErrorÚ_JanitorÚacquireAttributeÚexcInfoOrFailureToExcInfoÚopenTestLogc                  ó0   — e Zd ZdZdd„Zdd„Zdd„Zdd„Zy)ÚMktempTestszm
    Tests for L{TestCase.mktemp}, a helper function for creating temporary file
    or directory names.
    c                óÊ   — | j                  «       }t        j                  j                  |«      j	                  t        j
                  «      dd }| j                  |g d¢«       y)z–
        The path name returned by C{mktemp} is directly beneath a directory
        which identifies the test method which created the name.
        Néÿÿÿÿ)ztwisted.trial.test.test_utilr   Ú	test_name)ÚmktempÚosÚpathÚdirnameÚsplitÚsepÚassertEqual)ÚselfÚnameÚdirss      ú>/usr/lib/python3/dist-packages/twisted/trial/test/test_util.pyr   zMktempTests.test_name)   sK   € ð
 �{‰{‹}ˆÜ�w‰w�‰˜tÓ$×*Ñ*¬2¯6©6Ó2°3°BÐ7ˆØ×ÑØÒNõ	
ó    c                ód   — | j                  «       }| j                  || j                  «       «       y)zF
        Repeated calls to C{mktemp} return different values.
        N)r   ÚassertNotEqual)r    r!   s     r#   Útest_uniquezMktempTests.test_unique4   s%   € ð �{‰{‹}ˆØ×Ñ˜D $§+¡+£-Õ0r$   c                ó  — | j                  «       }t        j                  j                  |«      }| j	                  t        j                  j                  |«      «       | j                  t        j                  j                  |«      «       y)zS
        The directory part of the path name returned by C{mktemp} exists.
        N)r   r   r   r   Ú
assertTrueÚexistsÚassertFalse)r    r!   r   s      r#   Útest_createdzMktempTests.test_created;   sU   € ð �{‰{‹}ˆÜ—'‘'—/‘/ $Ó'ˆØ�‰œŸ™Ÿ™ wÓ/Ô0Ø×ÑœŸ™Ÿ™¨Ó-Õ.r$   c                óÂ   — t         j                  j                  | j                  «       «      }| j	                  |j                  t        j                  «       «      «       y)zZ
        The path returned by C{mktemp} is beneath the current working directory.
        N)r   r   Úabspathr   r)   Ú
startswithÚgetcwd)r    r   s     r#   Útest_locationzMktempTests.test_locationD   s7   € ô �w‰w�‰˜tŸ{™{›}Ó-ˆØ�‰˜Ÿ™¬¯	©	«Ó4Õ5r$   N©ÚreturnÚNone)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r'   r,   r1   © r$   r#   r   r   #   s   „ ñó
	
ó1ó/ô6r$   r   c                  ó(   — e Zd ZdZdd„Zdd„Zdd„Zy)ÚDirtyReactorAggregateErrorTestsz6
    Tests for the L{DirtyReactorAggregateError}.
    c                óT   — t        ddg«      }| j                  t        |«      d«       y)z5
        Delayed calls are formatted nicely.
        ÚFooÚbarzhReactor was unclean.
DelayedCalls: (set twisted.internet.base.DelayedCall.debug = True to debug)
Foo
barN©r   r   Ústr©r    Úerrors     r#   Útest_formatDelayedCallz6DirtyReactorAggregateErrorTests.test_formatDelayedCallQ   s,   € ô +¨E°5¨>Ó:ˆØ×ÑÜ�‹Jðõ	
r$   c                óV   — t        g ddg«      }| j                  t        |«      d«       y)z3
        Selectables are formatted nicely.
        zselectable 1zselectable 2z;Reactor was unclean.
Selectables:
selectable 1
selectable 2Nr?   rA   s     r#   Útest_formatSelectablesz6DirtyReactorAggregateErrorTests.test_formatSelectables_   s/   € ô +¨2°ÀÐ/OÓPˆØ×ÑÜ�‹Jðõ	
r$   c                óZ   — t        ddgddg«      }| j                  t        |«      d«       y)zR
        Both delayed calls and selectables can appear in the same error.
        ÚbleckÚBoozoÚSel1ÚSel2zƒReactor was unclean.
DelayedCalls: (set twisted.internet.base.DelayedCall.debug = True to debug)
bleck
Boozo
Selectables:
Sel1
Sel2Nr?   rA   s     r#   Ú%test_formatDelayedCallsAndSelectableszEDirtyReactorAggregateErrorTests.test_formatDelayedCallsAndSelectablesm   s4   € ô +¨G°WÐ+=ÀÈÐ?OÓPˆØ×ÑÜ�‹Jðõ
	
r$   Nr2   )r5   r6   r7   r8   rC   rE   rK   r9   r$   r#   r;   r;   L   s   „ ñó
ó
ô
r$   r;   c                  ó@   — e Zd ZdZ	 d	 	 	 	 	 dd„Zdd	d„Zd
d„Zdd„Zy)ÚStubReactora~  
    A reactor stub which contains enough functionality to be used with the
    L{_Janitor}.

    @ivar iterations: A list of the arguments passed to L{iterate}.
    @ivar removeAllCalled: Number of times that L{removeAll} was called.
    @ivar selectables: The value that will be returned from L{removeAll}.
    @ivar delayedCalls: The value to return from L{getDelayedCalls}.
    Nc                óD   — || _         g | _        d| _        |sg }|| _        y)zƒ
        @param delayedCalls: See L{StubReactor.delayedCalls}.
        @param selectables: See L{StubReactor.selectables}.
        r   N)ÚdelayedCallsÚ
iterationsÚremoveAllCalledÚselectables)r    rO   rR   s      r#   Ú__init__zStubReactor.__init__Š   s+   € ð )ˆÔØ.0ˆŒØ ˆÔÙØˆKØ&ˆÕr$   c                ó:   — | j                   j                  |«       y)z/
        Increment C{self.iterations}.
        N)rP   Úappend)r    Útimeouts     r#   ÚiteratezStubReactor.iterate˜   s   € ð 	�‰×Ñ˜wÕ'r$   c                ó   — | j                   S )z.
        Return C{self.delayedCalls}.
        )rO   ©r    s    r#   ÚgetDelayedCallszStubReactor.getDelayedCallsž   s   € ð × Ñ Ð r$   c                óD   — | xj                   dz  c_         | j                  S )zS
        Increment C{self.removeAllCalled} and return C{self.selectables}.
        é   )rQ   rR   rY   s    r#   Ú	removeAllzStubReactor.removeAll¤   s!   € ð 	×Ò Ñ!ÕØ×ÑÐr$   ©N)rO   úlist[DelayedCall]rR   zlist[object] | Noner3   r4   )rV   zfloat | Noner3   r4   )r3   r_   )r3   zlist[object])r5   r6   r7   r8   rS   rW   rZ   r]   r9   r$   r#   rM   rM      s:   „ ñð SWð'Ø-ð'Ø<Oð'à	ó'ô(ó!ô r$   rM   c                  ó    — e Zd ZdZdd„Zdd„Zy)ÚStubErrorReporterz½
    A subset of L{twisted.trial.itrial.IReporter} which records L{addError}
    calls.

    @ivar errors: List of two-tuples of (test, error) which were passed to
        L{addError}.
    c                ó   — g | _         y r^   )ÚerrorsrY   s    r#   rS   zStubErrorReporter.__init__µ   s	   € Ø46ˆ�r$   c                ó>   — | j                   j                  ||f«       y)z6
        Record parameters in C{self.errors}.
        N)rc   rU   )r    ÚtestrB   s      r#   ÚaddErrorzStubErrorReporter.addError¸   s   € ð 	�‰×Ñ˜D %˜=Õ)r$   Nr2   )re   ÚobjectrB   r   r3   r4   )r5   r6   r7   r8   rS   rf   r9   r$   r#   ra   ra   ¬   s   „ ñó7ô*r$   ra   c                  óh   — 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y)ÚJanitorTestsz 
    Tests for L{_Janitor}!
    c                ó’   — t        g «      }t        dd|¬«      }|j                  «        | j                  |j                  ddg«       y)a  
        During pending-call cleanup, the reactor will be spun twice with an
        instant timeout. This is not a requirement, it is only a test for
        current behavior. Hopefully Trial will eventually not do this kind of
        reactor stuff.
        N©Úreactorr   )rM   r   Ú_cleanPendingr   rP   ©r    rl   Újans      r#   Útest_cleanPendingSpinsReactorz*JanitorTests.test_cleanPendingSpinsReactorÄ   sA   € ô ˜b“/ˆÜ�t˜T¨7Ô3ˆØ×ÑÔØ×Ñ˜×+Ñ+¨a°¨VÕ4r$   c                óÀ   — dd„}g }t        d|di |j                  d„ «      }t        |g«      }t        dd|¬«      }|j	                  «        | j                  ||g«       y)zW
        During pending-call cleanup, the janitor cancels pending timed calls.
        c                  ó   — y)NÚLulzr9   r9   r$   r#   Úfuncz8JanitorTests.test_cleanPendingCancelsCalls.<locals>.funcÕ   s   € Ør$   é,  r9   c                 ó   — y r^   r9   ©Úxs    r#   ú<lambda>z<JanitorTests.test_cleanPendingCancelsCalls.<locals>.<lambda>Ù   ó   � r$   Nrk   ©r3   r@   )r	   rU   rM   r   rm   r   )r    rt   Ú	cancelledÚdelayedCallrl   ro   s         r#   Útest_cleanPendingCancelsCallsz*JanitorTests.test_cleanPendingCancelsCallsÐ   s`   € ó
	ð (*ˆ	Ü! # t¨R°°Y×5EÑ5EÁ~ÓVˆÜ˜{˜mÓ,ˆÜ�t˜T¨7Ô3ˆØ×ÑÔØ×Ñ˜ [ MÕ2r$   c           	     óÀ   — t        dd„ di d„ d„ d„ ¬«      }t        |«      }t        |g«      }t        dd|¬«      }|j	                  «       }| j                  ||g«       y)	aK  
        The Janitor produces string representations of delayed calls from the
        delayed call cleanup method. It gets the string representations
        *before* cancelling the calls; this is important because cancelling the
        call removes critical debugging information from the string
        representation.
        ru   c                  ó   — y r^   r9   r9   r$   r#   ry   zIJanitorTests.test_cleanPendingReturnsDelayedCallStrings.<locals>.<lambda>è   rz   r$   r9   c                 ó   — y r^   r9   rw   s    r#   ry   zIJanitorTests.test_cleanPendingReturnsDelayedCallStrings.<locals>.<lambda>è   rz   r$   c                  ó   — y©Nr   r9   r9   r$   r#   ry   zIJanitorTests.test_cleanPendingReturnsDelayedCallStrings.<locals>.<lambda>è   rz   r$   ©ÚsecondsNrk   )r	   r@   rM   r   rm   r   )r    r}   ÚdelayedCallStringrl   ro   Ústringss         r#   Ú*test_cleanPendingReturnsDelayedCallStringsz7JanitorTests.test_cleanPendingReturnsDelayedCallStringsß   sf   € ô "Ø‘˜r 2¡~±~Éyô
ˆô   Ó,ÐÜ˜{˜mÓ,ˆÜ�t˜T¨7Ô3ˆØ×#Ñ#Ó%ˆØ×Ñ˜Ð#4Ð"5Õ6r$   c                óŽ   — t        g «      }t        dd|¬«      }|j                  «        | j                  |j                  d«       y)zM
        The Janitor will remove selectables during reactor cleanup.
        Nrk   r\   )rM   r   Ú_cleanReactorr   rQ   rn   s      r#   Ú#test_cleanReactorRemovesSelectablesz0JanitorTests.test_cleanReactorRemovesSelectablesð   s=   € ô ˜b“/ˆÜ�t˜T¨7Ô3ˆØ×ÑÔØ×Ñ˜×0Ñ0°!Õ4r$   c                óÚ   — t        t        «       G d„ d«      «       } |«       }t        g |g«      }t        dd|¬«      }|j	                  «        | j                  |j                  dg«       y)zI
        The Janitor will kill processes during reactor cleanup.
        c                  ó    — e Zd ZdZdd„Zdd„Zy)úJJanitorTests.test_cleanReactorKillsProcesses.<locals>.StubProcessTransportz˜
            A stub L{IProcessTransport} provider which records signals.
            @ivar signals: The signals passed to L{signalProcess}.
            c                ó   — g | _         y r^   )ÚsignalsrY   s    r#   rS   zSJanitorTests.test_cleanReactorKillsProcesses.<locals>.StubProcessTransport.__init__  s	   € Ø02�•r$   c                ó:   — | j                   j                  |«       y)zF
                Append C{signal} to C{self.signals}.
                N)r�   rU   )r    Úsignals     r#   ÚsignalProcesszXJanitorTests.test_cleanReactorKillsProcesses.<locals>.StubProcessTransport.signalProcess  s   € ð —‘×#Ñ# FÕ+r$   Nr2   )r’   z	str | intr3   r4   )r5   r6   r7   r8   rS   r“   r9   r$   r#   ÚStubProcessTransportrŽ   þ   s   „ ñó
3ô,r$   r”   Nrk   ÚKILL)r   r
   rM   r   rŠ   r   r�   )r    r”   Úptrl   ro   s        r#   Útest_cleanReactorKillsProcessesz,JanitorTests.test_cleanReactorKillsProcessesù   si   € ô
 
Ô&Ó	'÷	,ð 	,ó 
(ð	,ñ "Ó#ˆÜ˜b 2 $Ó'ˆÜ�t˜T¨7Ô3ˆØ×ÑÔØ×Ñ˜Ÿ™ f XÕ.r$   c                óš   —  G d„ d«      }t        g  |«       g«      }t        dd|¬«      }| j                  |j                  «       dg«       y)z‹
        The Janitor returns string representations of the selectables that it
        cleaned up from the reactor cleanup method.
        c                  ó   — e Zd ZdZdd„Zy)úJJanitorTests.test_cleanReactorReturnsSelectableStrings.<locals>.Selectablezl
            A stub Selectable which only has an interesting string
            representation.
            c                 ó   — y)Nú(SELECTABLE!)r9   rY   s    r#   Ú__repr__zSJanitorTests.test_cleanReactorReturnsSelectableStrings.<locals>.Selectable.__repr__   s   € Ø&r$   Nr{   )r5   r6   r7   r8   r�   r9   r$   r#   Ú
Selectablerš     s   „ ñô
'r$   rž   Nrk   rœ   )rM   r   r   rŠ   )r    rž   rl   ro   s       r#   Ú)test_cleanReactorReturnsSelectableStringsz6JanitorTests.test_cleanReactorReturnsSelectableStrings  sH   € ÷	'ñ 	'ô ˜b¡:£< .Ó1ˆÜ�t˜T¨7Ô3ˆØ×Ñ˜×*Ñ*Ó,¨Ð.?Õ@r$   c                óÔ   — t        g «      }t        «       }t        «       }t        |||¬«      }| j	                  |j                  «       «       | j                  |j                  g «       y)z�
        The post-case cleanup method will return True and not call C{addError}
        on the result if there are no pending calls.
        rk   N)rM   rg   ra   r   r)   ÚpostCaseCleanupr   rc   ©r    rl   re   Úreporterro   s        r#   Útest_postCaseCleanupNoErrorsz)JanitorTests.test_postCaseCleanupNoErrors'  sS   € ô
 ˜b“/ˆÜ‹xˆÜ$Ó&ˆÜ�t˜X¨wÔ7ˆØ�‰˜×+Ñ+Ó-Ô.Ø×Ñ˜Ÿ™¨"Õ-r$   c           	     óš  — t        dd„ di d„ d„ d„ ¬«      }t        |«      }t        |gg «      }t        «       }t	        «       }t        |||¬«      }| j                  |j                  «       «       | j                  t        |j                  «      d«       | j                  |j                  d	   d   j                  j                  |g«       y
)z¼
        The post-case cleanup method will return False and call C{addError} on
        the result with a L{DirtyReactorAggregateError} Failure if there are
        pending calls.
        ru   c                  ó   — y r^   r9   r9   r$   r#   ry   z=JanitorTests.test_postCaseCleanupWithErrors.<locals>.<lambda>:  rz   r$   r9   c                 ó   — y r^   r9   rw   s    r#   ry   z=JanitorTests.test_postCaseCleanupWithErrors.<locals>.<lambda>:  rz   r$   c                  ó   — yrƒ   r9   r9   r$   r#   ry   z=JanitorTests.test_postCaseCleanupWithErrors.<locals>.<lambda>:  rz   r$   r„   rk   r\   r   N)r	   r@   rM   rg   ra   r   r+   r¡   r   Úlenrc   ÚvaluerO   ©r    r}   r†   rl   re   r£   ro   s          r#   Útest_postCaseCleanupWithErrorsz+JanitorTests.test_postCaseCleanupWithErrors3  s³   € ô "Ø‘˜r 2¡~±~Éyô
ˆô   Ó,ÐÜ˜{˜m¨RÓ0ˆÜ‹xˆÜ$Ó&ˆÜ�t˜X¨wÔ7ˆØ×Ñ˜×,Ñ,Ó.Ô/Ø×Ñœ˜XŸ_™_Ó-¨qÔ1Ø×Ñ˜Ÿ™¨Ñ+¨AÑ.×4Ñ4×AÑAÐDUÐCVÕWr$   c                ó¶   — t        g «      }t        «       }t        «       }t        |||¬«      }|j	                  «        | j                  |j                  g «       y)z�
        The post-class cleanup method will not call C{addError} on the result
        if there are no pending calls or selectables.
        rk   N)rM   rg   ra   r   ÚpostClassCleanupr   rc   r¢   s        r#   Útest_postClassCleanupNoErrorsz*JanitorTests.test_postClassCleanupNoErrorsE  sJ   € ô
 ˜b“/ˆÜ‹xˆÜ$Ó&ˆÜ�t˜X¨wÔ7ˆØ×ÑÔØ×Ñ˜Ÿ™¨"Õ-r$   c           	     ó|  — t        dd„ di d„ d„ d„ ¬«      }t        |«      }t        |gg «      }t        «       }t	        «       }t        |||¬«      }|j                  «        | j                  t        |j                  «      d«       | j                  |j                  d	   d   j                  j                  |g«       y
)zŸ
        The post-class cleanup method call C{addError} on the result with a
        L{DirtyReactorAggregateError} Failure if there are pending calls.
        ru   c                  ó   — y r^   r9   r9   r$   r#   ry   zIJanitorTests.test_postClassCleanupWithPendingCallErrors.<locals>.<lambda>W  rz   r$   r9   c                 ó   — y r^   r9   rw   s    r#   ry   zIJanitorTests.test_postClassCleanupWithPendingCallErrors.<locals>.<lambda>W  rz   r$   c                  ó   — yrƒ   r9   r9   r$   r#   ry   zIJanitorTests.test_postClassCleanupWithPendingCallErrors.<locals>.<lambda>W  rz   r$   r„   rk   r\   r   N)r	   r@   rM   rg   ra   r   r®   r   r©   rc   rª   rO   r«   s          r#   Ú*test_postClassCleanupWithPendingCallErrorsz7JanitorTests.test_postClassCleanupWithPendingCallErrorsQ  s¨   € ô
 "Ø‘˜r 2¡~±~Éyô
ˆô   Ó,ÐÜ˜{˜m¨RÓ0ˆÜ‹xˆÜ$Ó&ˆÜ�t˜X¨wÔ7ˆØ×ÑÔØ×Ñœ˜XŸ_™_Ó-¨qÔ1Ø×Ñ˜Ÿ™¨Ñ+¨AÑ.×4Ñ4×AÑAÐDUÐCVÕWr$   c                óP  — d}t        g |g«      }t        «       }t        «       }t        |||¬«      }|j	                  «        | j                  t        |j                  «      d«       | j                  |j                  d   d   j                  j                  t        |«      g«       y)z�
        The post-class cleanup method call C{addError} on the result with a
        L{DirtyReactorAggregateError} Failure if there are selectables.
        zSELECTABLE HERErk   r\   r   N)rM   rg   ra   r   r®   r   r©   rc   rª   rR   Úrepr)r    Ú
selectablerl   re   r£   ro   s         r#   Ú)test_postClassCleanupWithSelectableErrorsz6JanitorTests.test_postClassCleanupWithSelectableErrorsb  s‹   € ð
 'ˆ
Ü˜b : ,Ó/ˆÜ‹xˆÜ$Ó&ˆÜ�t˜X¨wÔ7ˆØ×ÑÔØ×Ñœ˜XŸ_™_Ó-¨qÔ1Ø×Ñ˜Ÿ™¨Ñ+¨AÑ.×4Ñ4×@Ñ@Ä4È
ÓCSÐBTÕUr$   Nr2   )r5   r6   r7   r8   rp   r~   rˆ   r‹   r—   rŸ   r¤   r¬   r¯   r´   r¸   r9   r$   r#   ri   ri   ¿   sB   „ ñó
5ó3ó7ó"5ó/ó6Aó&
.óXó$
.óXô"Vr$   ri   c                  ó(   — e Zd ZdZdd„Zdd„Zdd„Zy)ÚRemoveSafelyTestsz*
    Tests for L{util._removeSafely}.
    c                óô   — | j                  «       j                  d«      }t        j                  |«       t	        j
                  |«      }| j                  t        j                  t        j                  |«       y)zÈ
        If a path doesn't contain a node named C{"_trial_marker"}, that path is
        not removed by L{util._removeSafely} and a L{util._NoTrialMarker}
        exception is raised instead.
        úutf-8N)
r   Úencoder   Úmkdirr   ÚFilePathÚassertRaisesr   Ú_NoTrialMarkerÚ_removeSafely)r    Ú	directoryÚdirPaths      r#   Útest_removeSafelyNoTrialMarkerz0RemoveSafelyTests.test_removeSafelyNoTrialMarkerv  sT   € ð —K‘K“M×(Ñ(¨Ó1ˆ	Ü
�‰�ÔÜ×#Ñ# IÓ.ˆØ×Ñœ$×-Ñ-¬t×/AÑ/AÀ7ÕKr$   c                ó–  — dd„}t        «       }| j                  t        d|«       | j                  «       j	                  d«      }t        j                  |«       t        j                  |«      }|j                  d«      j                  «        ||_        t        j                  |«       | j                  d|j                  «       «       y)zŸ
        If an L{OSError} is raised while removing a path in
        L{util._removeSafely}, an attempt is made to move the path to a new
        name.
        c                 ó   — t        «       ‚)ú…
            Raise an C{OSError} to emulate the branch of L{util._removeSafely}
            in which path removal fails.
            ©ÚOSErrorr9   r$   r#   ÚdummyRemovezORemoveSafelyTests.test_removeSafelyRemoveFailsMoveSucceeds.<locals>.dummyRemoveˆ  s   € ô
 “)ˆOr$   Ústdoutr¼   ó   _trial_markerúcould not remove FilePathNr2   )r   ÚpatchÚsysr   r½   r   r¾   r   r¿   ÚchildÚtouchÚremover   rÂ   ÚassertInÚgetvalue)r    rË   ÚoutrÃ   rÄ   s        r#   Ú(test_removeSafelyRemoveFailsMoveSucceedsz:RemoveSafelyTests.test_removeSafelyRemoveFailsMoveSucceeds�  s”   € ó	ô ‹jˆØ�
‰
”3˜ #Ô&ð —K‘K“M×(Ñ(¨Ó1ˆ	Ü
�‰�ÔÜ×#Ñ# IÓ.ˆØ�‰Ð&Ó'×-Ñ-Ô/à$ˆŒä×Ñ˜7Ô#Ø�‰Ð1°3·<±<³>ÕBr$   c                ó  — d	d„}d
dd„}t        «       }| j                  t        d|«       | j                  «       j	                  d«      }t        j                  |«       t        j                  |«      }|j                  d«      j                  «        ||_        ||_        | j                  t        t        j                   |«      }| j#                  t%        |«      d«       | j'                  d|j)                  «       «       y)zÓ
        If an L{OSError} is raised while removing a path in
        L{util._removeSafely}, an attempt is made to move the path to a new
        name. If that attempt fails, the L{OSError} is re-raised.
        c                 ó   — t        d«      ‚)rÈ   zpath removal failedrÉ   r9   r$   r#   rË   zLRemoveSafelyTests.test_removeSafelyRemoveFailsMoveFails.<locals>.dummyRemove¥  s   € ô
 Ð/Ó0Ð0r$   c                ó   — t        d«      ‚)z†
            Raise an C{OSError} to emulate the branch of L{util._removeSafely}
            in which path movement fails.
            úpath movement failedrÉ   )ÚdestinationÚfollowLinkss     r#   ÚdummyMoveTozLRemoveSafelyTests.test_removeSafelyRemoveFailsMoveFails.<locals>.dummyMoveTo¬  s   € ô
 Ð0Ó1Ð1r$   rÌ   r¼   rÍ   rÛ   rÎ   Nr2   )T)rÜ   rg   rÝ   Úboolr3   r4   )r   rÏ   rÐ   r   r½   r   r¾   r   r¿   rÑ   rÒ   rÓ   ÚmoveTorÀ   rÊ   r   rÂ   r   r@   rÔ   rÕ   )r    rË   rÞ   rÖ   rÃ   rÄ   rB   s          r#   Ú%test_removeSafelyRemoveFailsMoveFailsz7RemoveSafelyTests.test_removeSafelyRemoveFailsMoveFailsž  sÃ   € ó	1ô	2ô ‹jˆØ�
‰
”3˜ #Ô&ð —K‘K“M×(Ñ(¨Ó1ˆ	Ü
�‰�ÔÜ×#Ñ# IÓ.ˆØ�‰Ð&Ó'×-Ñ-Ô/ð %ˆŒØ$ˆŒà×!Ñ!¤'¬4×+=Ñ+=¸wÓGˆØ×Ñœ˜U›Ð%;Ô<Ø�‰Ð1°3·<±<³>ÕBr$   Nr2   )r5   r6   r7   r8   rÅ   r×   rá   r9   r$   r#   rº   rº   q  s   „ ñó	LóCô:%Cr$   rº   c                  ó    — e Zd ZdZdd„Zdd„Zy)ÚExcInfoTestsz1
    Tests for L{excInfoOrFailureToExcInfo}.
    c                ó`   — t         t        d«      df}| j                  |t        |«      u «       y)z›
        L{excInfoOrFailureToExcInfo} returns exactly what it is passed, if it is
        passed a tuple like the one returned by L{sys.exc_info}.
        ÚfooN)Ú
ValueErrorr)   r   )r    Úinfos     r#   Útest_excInfozExcInfoTests.test_excInfoË  s,   € ô
 œJ uÓ-¨tÐ4ˆØ�‰˜Ô 9¸$Ó ?Ð?Õ@r$   c                óº   — 	 ddz   | j                  j                  |j                  |j
                  ft        |«      «       y# t         $ r t        «       }Y ŒRw xY w)zì
        When called with a L{Failure} instance, L{excInfoOrFailureToExcInfo}
        returns a tuple like the one returned by L{sys.exc_info}, with the
        elements taken from the type, value, and traceback of the failure.
        r\   r   N)ÚBaseExceptionr   r   Útyperª   Útbr   )r    Úfs     r#   Útest_failurezExcInfoTests.test_failureÓ  sQ   € ð	Ø�ŠEð 	×Ñ˜!Ÿ&™& !§'¡'¨1¯4©4Ð0Ô2KÈAÓ2NÕOøô ò 	Ü“	ŠAð	ús   ‚A ÁAÁANr2   )r5   r6   r7   r8   rè   rî   r9   r$   r#   rã   rã   Æ  s   „ ñóAô
Pr$   rã   c                  ó0   — e Zd ZdZdd„Zdd„Zdd„Zdd„Zy)ÚAcquireAttributeTestsz(
    Tests for L{acquireAttribute}.
    c                ót   — t        «       x| _        }| j                  |t        | t        «       gd«      u «       y)z·
        The value returned by L{acquireAttribute} is the value of the requested
        attribute on the first object in the list passed in which has that
        attribute.
        rª   N©rg   rª   r)   r   ©r    rª   s     r#   Útest_foundOnEarlierObjectz/AcquireAttributeTests.test_foundOnEarlierObjectå  s2   € ô $›XÐ%ˆŒ
�UØ�‰˜Ô!1°4¼»Ð2BÀGÓ!LÐLÕMr$   c                ót   — t        «       x| _        }| j                  |t        t        «       | gd«      u «       y)z§
        The same as L{test_foundOnEarlierObject}, but for the case where the 2nd
        element in the object list has the attribute and the first does not.
        rª   Nrò   ró   s     r#   Útest_foundOnLaterObjectz-AcquireAttributeTests.test_foundOnLaterObjectî  s2   € ô
 $›XÐ%ˆŒ
�UØ�‰˜Ô!1´6³8¸TÐ2BÀGÓ!LÐLÕMr$   c                óN   — | j                  t        t        t        «       gd«       y)z•
        If none of the objects passed in the list to L{acquireAttribute} have
        the requested attribute, L{AttributeError} is raised.
        rå   N)rÀ   ÚAttributeErrorr   rg   rY   s    r#   Útest_notFoundExceptionz,AcquireAttributeTests.test_notFoundExceptionö  s   € ð
 	×Ñœ.Ô*:¼V»X¸JÈÕNr$   c                óf   — t        «       }| j                  |t        t        «       gd|«      u «       y)z¼
        If none of the objects passed in the list to L{acquireAttribute} have
        the requested attribute and a default value is given, the default value
        is returned.
        rå   N)rg   r)   r   )r    Údefaults     r#   Útest_notFoundDefaultz*AcquireAttributeTests.test_notFoundDefaultý  s*   € ô “(ˆØ�‰˜Ô#3´V³X°JÀÀwÓ#OÐOÕPr$   Nr2   )r5   r6   r7   r8   rô   rö   rù   rü   r9   r$   r#   rð   rð   à  s   „ ñóNóNóOôQr$   rð   c                  óX   — 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y)ÚListToPhraseTestszÆ
    Input is transformed into a string representation of the list,
    with each item separated by delimiter (defaulting to a comma) and the final
    two being separated by a final delimiter.
    c                ó\   — g }d}t        j                  |d«      }| j                  ||«       y)zB
        If things is empty, an empty string is returned.
        Ú ÚandN©r   Ú_listToPhraser   ©r    ÚsampleÚexpectedÚresults       r#   Ú
test_emptyzListToPhraseTests.test_empty  s0   € ð  ˆØˆÜ×#Ñ# F¨EÓ2ˆØ×Ñ˜ 6Õ*r$   c                ó^   — dg}d}t        j                  |d«      }| j                  ||«       y)z;
        With a single item, the item is returned.
        ÚOner  Nr  r  s       r#   Útest_oneWordzListToPhraseTests.test_oneWord  s2   € ð �ˆØˆÜ×#Ñ# F¨EÓ2ˆØ×Ñ˜ 6Õ*r$   c                ó`   — ddg}d}t        j                  |d«      }| j                  ||«       y)zA
        Two words are separated by the final delimiter.
        r
  ÚTwozOne and Twor  Nr  r  s       r#   Útest_twoWordszListToPhraseTests.test_twoWords   s4   € ð ˜�ˆØ ˆÜ×#Ñ# F¨EÓ2ˆØ×Ñ˜ 6Õ*r$   c                ó`   — g d¢}d}t        j                  |d«      }| j                  ||«       y)zY
        With more than two words, the first two are separated by the delimiter.
        )r
  r  ÚThreezOne, Two, and Threer  Nr  r  s       r#   Útest_threeWordsz!ListToPhraseTests.test_threeWords)  s0   € ò )ˆØ(ˆÜ×#Ñ# F¨EÓ2ˆØ×Ñ˜ 6Õ*r$   c                ód   — g d¢}d}t        j                  |dd¬«      }| j                  ||«       y)zW
        If a delimiter is specified, it is used instead of the default comma.
        )r
  r  r  ÚFourzOne; Two; Three; or FourÚorz; )Ú	delimiterNr  r  s       r#   Útest_fourWordsz ListToPhraseTests.test_fourWords2  s2   € ò 1ˆØ-ˆÜ×#Ñ# F¨D¸DÔAˆØ×Ñ˜ 6Õ*r$   c                ó`   — g d¢}d}t        j                  |d«      }| j                  ||«       y)zS
        If something in things is not a string, it is converted into one.
        )r\   é   Úthreez1, 2, and threer  Nr  r  s       r#   Útest_notStringz ListToPhraseTests.test_notString;  s0   € ò !ˆØ$ˆÜ×#Ñ# F¨EÓ2ˆØ×Ñ˜ 6Õ*r$   c                óŠ   — d}| j                  t        t        j                  |d«      }| j	                  t        |«      d«       y)z?
        If things is a string, a TypeError is raised.
        zOne, two, threer  ú Things must be a list or a tupleN©rÀ   Ú	TypeErrorr   r  r   r@   ©r    r  rB   s      r#   Útest_stringTypeErrorz&ListToPhraseTests.test_stringTypeErrorD  s:   € ð #ˆØ×!Ñ!¤)¬T×-?Ñ-?ÀÈÓOˆØ×Ñœ˜U›Ð%GÕHr$   c                ó    — t        g d¢«      }| j                  t        t        j                  |d«      }| j                  t        |«      d«       y)zB
        If things is an iterator, a TypeError is raised.
        )r\   r  é   r  r  N)ÚiterrÀ   r  r   r  r   r@   r  s      r#   Útest_iteratorTypeErrorz(ListToPhraseTests.test_iteratorTypeErrorL  s>   € ô ’i“ˆØ×!Ñ!¤)¬T×-?Ñ-?ÀÈÓOˆØ×Ñœ˜U›Ð%GÕHr$   c                óŽ   — dd„}| j                  t        t        j                  |d«      }| j	                  t        |«      d«       y)zB
        If things is a generator, a TypeError is raised.
        c               3  ó6   K  — t        d«      E d {  –—†  y 7 Œ­w)Nr  )Úranger9   r$   r#   r  z9ListToPhraseTests.test_generatorTypeError.<locals>.sampleY  s   è ø€ Ü˜Q“x×Òús   ‚‘’r  r  N)r3   zGenerator[int, None, None]r  r  s      r#   Útest_generatorTypeErrorz)ListToPhraseTests.test_generatorTypeErrorT  s:   € ó
	 ð ×!Ñ!¤)¬T×-?Ñ-?ÀÈÓOˆØ×Ñœ˜U›Ð%GÕHr$   Nr2   )r5   r6   r7   r8   r  r  r  r  r  r  r   r$  r(  r9   r$   r#   rþ   rþ     s7   „ ñó+ó+ó+ó+ó+ó+óIóIô	Ir$   rþ   c                  ó    — e Zd ZdZdd„Zdd„Zy)ÚOpenTestLogTestsz#
    Tests for C{openTestLog}.
    c                ó<  — t        j                  «       }| j                  t         j                  t         j                  |«       t        j                  t         j                  d«       d}t        j                  | j                  «       «      }t        |«      5 }|j                  |«       ddd«       t        |j                  d«      5 }|j                  «       }ddd«       t        |j                  d«      t        «      «       y# 1 sw Y   Œ]xY w# 1 sw Y   Œ:xY w)zR
        The log file is opened in text mode and uses UTF-8 for encoding.
        )ÚCÚasciiu   Here comes the â˜‰NÚrbr¼   )ÚlocaleÚ	getlocaleÚ
addCleanupÚ	setlocaleÚLC_ALLr   r¿   r   r   ÚwriteÚopenr   Úreadr   r½   r   )r    ÚcurrentLocaleÚtextÚprí   Úwrittens         r#   Ú	test_utf8zOpenTestLogTests.test_utf8e  sÐ   € ô ×(Ñ(Ó*ˆØ�‰œ×(Ñ(¬&¯-©-¸ÔGÜ×ÑœŸ™¨Ô7à'ˆÜ×Ñ˜dŸk™k›mÓ,ˆÜ˜‹^ð 	˜qØ�G‰G�DŒM÷	ô �!—&‘&˜$Óð 	 1Ø—f‘f“hˆG÷	ô 	�D—K‘K Ó(¬(°7Ó*;Õ<÷	ð 	ú÷	ð 	ús   ÂDÃDÄDÄDc                óÂ  — d}d}dt         j                  › dt         j                  › �}t        j                  | j	                  «       «      }t        |«      5 }|j                  |«       ddd«       t        |«      5 }|j                  |«       ddd«       t        |j                  «       j                  d«      t        |«      «       y# 1 sw Y   ŒaxY w# 1 sw Y   ŒHxY w)z™
        The log file is opened in append mode so if runner configuration specifies
        an existing log file its contents are not wiped out.
        zHello, world.
 zGoodbye, world.
zHello, world.z Goodbye, world.Nr¼   )r   Úlinesepr   r¿   r   r   r4  r   Ú
getContentÚdecoder   )r    ÚexistingTextÚnewTextr  r9  rí   s         r#   Útest_appendzOpenTestLogTests.test_append{  s¹   € ð
 *ˆØ%ˆØ"¤2§:¡: ,Ð.>¼r¿z¹z¸lÐKˆÜ×Ñ˜dŸk™k›mÓ,ˆÜ˜‹^ð 	"˜qØ�G‰G�LÔ!÷	"ä˜‹^ð 	˜qØ�G‰G�GÔ÷	ô 	Ø�L‰L‹N×!Ñ! 'Ó*Ü�XÓõ	
÷	"ð 	"ú÷	ð 	ús   ÁC	Á<CÃ	CÃCNr2   )r5   r6   r7   r8   r;  rB  r9   r$   r#   r*  r*  `  s   „ ñó=ô,
r$   r*  )+r8   Ú
__future__r   r/  r   rÐ   Úior   Útypingr   Úzope.interfacer   Úhamcrestr   r   Útwisted.internet.baser	   Útwisted.internet.interfacesr
   Útwisted.pythonr   Útwisted.python.failurer   Útwisted.trialr   Útwisted.trial.unittestr   Útwisted.trial.utilr   r   r   r   r   r   r;   rM   ra   ri   rº   rã   rð   rþ   r*  r9   r$   r#   ú<module>rO     sÓ   ðñ
õ #ã Û 	Û 
Ý Ý å &ç *å -Ý 9Ý #Ý *Ý Ý 6÷õ ô&6Ð%ô &6ôR0
Ð&9ô 0
÷f* ñ * ÷Z*ñ *ô&oVÐ&ô oVôdRCÐ+ô RCôjPÐ&ô Pô4$QÐ/ô $QôNVIÐ+ô VIôr,
Ð*õ ,
r$   