U
    T‚g–V  ã                   @  s`  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„ deƒZ!G dd„ deƒZ"G dd„ dƒZ#G dd„ dƒZ$G dd„ deƒZ%G dd„ deƒZ&G dd„ deƒZ'G dd„ deƒZ(G dd „ d eƒZ)G d!d"„ d"eƒZ*dS )#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                   @  sH   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zddœd
d„ZdS )ÚMktempTestszm
    Tests for L{TestCase.mktemp}, a helper function for creating temporary file
    or directory names.
    ÚNone©Úreturnc                 C  s:   |   ¡ }tj |¡ tj¡dd… }|  |dddg¡ dS )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Údirs© r#   ú@/tmp/pip-unpacked-wheel-1_7di8ic/twisted/trial/test/test_util.pyr   )   s     ÿzMktempTests.test_namec                 C  s   |   ¡ }|  ||   ¡ ¡ dS )zF
        Repeated calls to C{mktemp} return different values.
        N)r   ZassertNotEqual)r    r!   r#   r#   r$   Útest_unique4   s    zMktempTests.test_uniquec                 C  s<   |   ¡ }tj |¡}|  tj |¡¡ |  tj |¡¡ dS )zS
        The directory part of the path name returned by C{mktemp} exists.
        N)r   r   r   r   Ú
assertTrueÚexistsÚassertFalse)r    r!   r   r#   r#   r$   Útest_created;   s    zMktempTests.test_createdc                 C  s(   t j |  ¡ ¡}|  | t  ¡ ¡¡ dS )zZ
        The path returned by C{mktemp} is beneath the current working directory.
        N)r   r   Úabspathr   r&   Ú
startswithÚgetcwd)r    r   r#   r#   r$   Útest_locationD   s    zMktempTests.test_locationN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r%   r)   r-   r#   r#   r#   r$   r   #   s
   	r   c                   @  s:   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zd
S )ÚDirtyReactorAggregateErrorTestsz6
    Tests for the L{DirtyReactorAggregateError}.
    r   r   c                 C  s    t ddgƒ}|  t|ƒd¡ dS )z5
        Delayed calls are formatted nicely.
        ZFooÚbarzhReactor was unclean.
DelayedCalls: (set twisted.internet.base.DelayedCall.debug = True to debug)
Foo
barN©r   r   Ústr©r    Úerrorr#   r#   r$   Útest_formatDelayedCallQ   s
    þz6DirtyReactorAggregateErrorTests.test_formatDelayedCallc                 C  s"   t g ddgƒ}|  t|ƒd¡ dS )z3
        Selectables are formatted nicely.
        zselectable 1zselectable 2z;Reactor was unclean.
Selectables:
selectable 1
selectable 2Nr4   r6   r#   r#   r$   Útest_formatSelectables_   s
    þz6DirtyReactorAggregateErrorTests.test_formatSelectablesc                 C  s&   t ddgddgƒ}|  t|ƒd¡ dS )zR
        Both delayed calls and selectables can appear in the same error.
        ZbleckZBoozoZSel1ZSel2zƒReactor was unclean.
DelayedCalls: (set twisted.internet.base.DelayedCall.debug = True to debug)
bleck
Boozo
Selectables:
Sel1
Sel2Nr4   r6   r#   r#   r$   Ú%test_formatDelayedCallsAndSelectablesm   s
    þzEDirtyReactorAggregateErrorTests.test_formatDelayedCallsAndSelectablesN)r.   r/   r0   r1   r8   r9   r:   r#   r#   r#   r$   r2   L   s   r2   c                   @  sR   e Zd ZdZdddddœdd„Zdd	dd
œdd„Zddœdd„Zddœdd„ZdS )Ú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}.
    Nzlist[DelayedCall]zlist[object] | Noner   )ÚdelayedCallsÚselectablesr   c                 C  s$   || _ g | _d| _|sg }|| _dS )zƒ
        @param delayedCalls: See L{StubReactor.delayedCalls}.
        @param selectables: See L{StubReactor.selectables}.
        r   N)r<   Ú
iterationsÚremoveAllCalledr=   )r    r<   r=   r#   r#   r$   Ú__init__Š   s    zStubReactor.__init__zfloat | None)Útimeoutr   c                 C  s   | j  |¡ dS )z/
        Increment C{self.iterations}.
        N)r>   Úappend)r    rA   r#   r#   r$   Úiterate˜   s    zStubReactor.iterater   c                 C  s   | j S )z.
        Return C{self.delayedCalls}.
        )r<   ©r    r#   r#   r$   ÚgetDelayedCallsž   s    zStubReactor.getDelayedCallszlist[object]c                 C  s   |  j d7  _ | jS )zS
        Increment C{self.removeAllCalled} and return C{self.selectables}.
        é   )r?   r=   rD   r#   r#   r$   Ú	removeAll¤   s    zStubReactor.removeAll)N)N)r.   r/   r0   r1   r@   rC   rE   rG   r#   r#   r#   r$   r;      s    ÿr;   c                   @  s0   e Zd ZdZddœdd„Zddddœd	d
„ZdS )Ú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}.
    r   r   c                 C  s
   g | _ d S ©N)ÚerrorsrD   r#   r#   r$   r@   µ   s    zStubErrorReporter.__init__Úobjectr   )Útestr7   r   c                 C  s   | j  ||f¡ dS )z6
        Record parameters in C{self.errors}.
        N)rJ   rB   )r    rL   r7   r#   r#   r$   ÚaddError¸   s    zStubErrorReporter.addErrorN)r.   r/   r0   r1   r@   rM   r#   r#   r#   r$   rH   ¬   s   rH   c                   @  sª   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zddœd
d„Zddœdd„Zddœdd„Z	ddœdd„Z
ddœdd„Zddœdd„Zddœdd„Zddœdd„ZdS )ÚJanitorTestsz 
    Tests for L{_Janitor}!
    r   r   c                 C  s4   t g ƒ}tdd|d�}| ¡  |  |jddg¡ dS )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   )r;   r   Ú_cleanPendingr   r>   ©r    rP   Újanr#   r#   r$   Útest_cleanPendingSpinsReactorÄ   s    z*JanitorTests.test_cleanPendingSpinsReactorc                 C  s\   ddœdd„}g }t d|di |jdd„ ƒ}t|gƒ}td	d	|d
�}| ¡  |  ||g¡ d	S )zW
        During pending-call cleanup, the janitor cancels pending timed calls.
        r5   r   c                   S  s   dS )NZLulzr#   r#   r#   r#   r$   ÚfuncÕ   s    z8JanitorTests.test_cleanPendingCancelsCalls.<locals>.funcé,  r#   c                 S  s   d S rI   r#   ©Úxr#   r#   r$   Ú<lambda>Ù   ó    z<JanitorTests.test_cleanPendingCancelsCalls.<locals>.<lambda>NrO   )r   rB   r;   r   rQ   r   )r    rU   Z	cancelledÚdelayedCallrP   rS   r#   r#   r$   Útest_cleanPendingCancelsCallsÐ   s    
z*JanitorTests.test_cleanPendingCancelsCallsc              	   C  s`   t ddd„ di dd„ dd„ dd„ d�}t|ƒ}t|gƒ}tdd|d	�}| ¡ }|  ||g¡ dS )
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.
        rV   c                   S  s   d S rI   r#   r#   r#   r#   r$   rY   è   rZ   zIJanitorTests.test_cleanPendingReturnsDelayedCallStrings.<locals>.<lambda>r#   c                 S  s   d S rI   r#   rW   r#   r#   r$   rY   è   rZ   c                   S  s   dS ©Nr   r#   r#   r#   r#   r$   rY   è   rZ   ©ÚsecondsNrO   )r   r5   r;   r   rQ   r   )r    r[   ÚdelayedCallStringrP   rS   Ústringsr#   r#   r$   Ú*test_cleanPendingReturnsDelayedCallStringsß   s          ÿ
z7JanitorTests.test_cleanPendingReturnsDelayedCallStringsc                 C  s0   t g ƒ}tdd|d�}| ¡  |  |jd¡ dS )zM
        The Janitor will remove selectables during reactor cleanup.
        NrO   rF   )r;   r   Ú_cleanReactorr   r?   rR   r#   r#   r$   Ú#test_cleanReactorRemovesSelectablesð   s    z0JanitorTests.test_cleanReactorRemovesSelectablesc                 C  sR   t tƒG dd„ dƒƒ}|ƒ }tg |gƒ}tdd|d�}| ¡  |  |jdg¡ dS )zI
        The Janitor will kill processes during reactor cleanup.
        c                   @  s.   e Zd ZdZddœdd„Zdddœdd	„Zd
S )zJJanitorTests.test_cleanReactorKillsProcesses.<locals>.StubProcessTransportz˜
            A stub L{IProcessTransport} provider which records signals.
            @ivar signals: The signals passed to L{signalProcess}.
            r   r   c                 S  s
   g | _ d S rI   )ÚsignalsrD   r#   r#   r$   r@     s    zSJanitorTests.test_cleanReactorKillsProcesses.<locals>.StubProcessTransport.__init__z	str | int)Úsignalr   c                 S  s   | j  |¡ dS )zF
                Append C{signal} to C{self.signals}.
                N)re   rB   )r    rf   r#   r#   r$   ÚsignalProcess  s    zXJanitorTests.test_cleanReactorKillsProcesses.<locals>.StubProcessTransport.signalProcessN)r.   r/   r0   r1   r@   rg   r#   r#   r#   r$   ÚStubProcessTransportþ   s   rh   NrO   ZKILL)r   r	   r;   r   rc   r   re   )r    rh   ÚptrP   rS   r#   r#   r$   Útest_cleanReactorKillsProcessesù   s    z,JanitorTests.test_cleanReactorKillsProcessesc                 C  s@   G dd„ dƒ}t g |ƒ gƒ}tdd|d�}|  | ¡ dg¡ dS )z‹
        The Janitor returns string representations of the selectables that it
        cleaned up from the reactor cleanup method.
        c                   @  s   e Zd ZdZddœdd„ZdS )zJJanitorTests.test_cleanReactorReturnsSelectableStrings.<locals>.Selectablezl
            A stub Selectable which only has an interesting string
            representation.
            r5   r   c                 S  s   dS )Nú(SELECTABLE!)r#   rD   r#   r#   r$   Ú__repr__   s    zSJanitorTests.test_cleanReactorReturnsSelectableStrings.<locals>.Selectable.__repr__N)r.   r/   r0   r1   rl   r#   r#   r#   r$   Ú
Selectable  s   rm   NrO   rk   )r;   r   r   rc   )r    rm   rP   rS   r#   r#   r$   Ú)test_cleanReactorReturnsSelectableStrings  s    	z6JanitorTests.test_cleanReactorReturnsSelectableStringsc                 C  sB   t g ƒ}tƒ }tƒ }t|||d�}|  | ¡ ¡ |  |jg ¡ dS )z�
        The post-case cleanup method will return True and not call C{addError}
        on the result if there are no pending calls.
        rO   N)r;   rK   rH   r   r&   ÚpostCaseCleanupr   rJ   ©r    rP   rL   ÚreporterrS   r#   r#   r$   Útest_postCaseCleanupNoErrors'  s    z)JanitorTests.test_postCaseCleanupNoErrorsc              	   C  s”   t ddd„ di dd„ dd„ dd„ d�}t|ƒ}t|gg ƒ}tƒ }tƒ }t|||d�}|  | ¡ ¡ |  t	|j
ƒd	¡ |  |j
d
 d	 jj|g¡ dS )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.
        rV   c                   S  s   d S rI   r#   r#   r#   r#   r$   rY   :  rZ   z=JanitorTests.test_postCaseCleanupWithErrors.<locals>.<lambda>r#   c                 S  s   d S rI   r#   rW   r#   r#   r$   rY   :  rZ   c                   S  s   dS r]   r#   r#   r#   r#   r$   rY   :  rZ   r^   rO   rF   r   N)r   r5   r;   rK   rH   r   r(   ro   r   ÚlenrJ   Úvaluer<   ©r    r[   r`   rP   rL   rq   rS   r#   r#   r$   Útest_postCaseCleanupWithErrors3  s"          ÿz+JanitorTests.test_postCaseCleanupWithErrorsc                 C  s<   t g ƒ}tƒ }tƒ }t|||d�}| ¡  |  |jg ¡ dS )z�
        The post-class cleanup method will not call C{addError} on the result
        if there are no pending calls or selectables.
        rO   N)r;   rK   rH   r   ÚpostClassCleanupr   rJ   rp   r#   r#   r$   Útest_postClassCleanupNoErrorsE  s    z*JanitorTests.test_postClassCleanupNoErrorsc              	   C  sŽ   t ddd„ di dd„ dd„ dd„ d�}t|ƒ}t|gg ƒ}tƒ }tƒ }t|||d�}| ¡  |  t|j	ƒd	¡ |  |j	d
 d	 j
j|g¡ dS )zŸ
        The post-class cleanup method call C{addError} on the result with a
        L{DirtyReactorAggregateError} Failure if there are pending calls.
        rV   c                   S  s   d S rI   r#   r#   r#   r#   r$   rY   W  rZ   zIJanitorTests.test_postClassCleanupWithPendingCallErrors.<locals>.<lambda>r#   c                 S  s   d S rI   r#   rW   r#   r#   r$   rY   W  rZ   c                   S  s   dS r]   r#   r#   r#   r#   r$   rY   W  rZ   r^   rO   rF   r   N)r   r5   r;   rK   rH   r   rw   r   rs   rJ   rt   r<   ru   r#   r#   r$   Ú*test_postClassCleanupWithPendingCallErrorsQ  s"          ÿz7JanitorTests.test_postClassCleanupWithPendingCallErrorsc                 C  sh   d}t g |gƒ}tƒ }tƒ }t|||d�}| ¡  |  t|jƒd¡ |  |jd d jj	t
|ƒg¡ dS )z�
        The post-class cleanup method call C{addError} on the result with a
        L{DirtyReactorAggregateError} Failure if there are selectables.
        zSELECTABLE HERErO   rF   r   N)r;   rK   rH   r   rw   r   rs   rJ   rt   r=   Úrepr)r    Z
selectablerP   rL   rq   rS   r#   r#   r$   Ú)test_postClassCleanupWithSelectableErrorsb  s    z6JanitorTests.test_postClassCleanupWithSelectableErrorsN)r.   r/   r0   r1   rT   r\   rb   rd   rj   rn   rr   rv   rx   ry   r{   r#   r#   r#   r$   rN   ¿   s   	rN   c                   @  s:   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zd
S )ÚRemoveSafelyTestsz*
    Tests for L{util._removeSafely}.
    r   r   c                 C  s8   |   ¡  d¡}t |¡ t |¡}|  tjtj	|¡ dS )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   Z_NoTrialMarkerÚ_removeSafely)r    Ú	directoryÚdirPathr#   r#   r$   Útest_removeSafelyNoTrialMarkerv  s    

z0RemoveSafelyTests.test_removeSafelyNoTrialMarkerc                 C  sv   ddœdd„}t ƒ }|  td|¡ |  ¡  d¡}t |¡ t |¡}| 	d¡ 
¡  ||_t |¡ |  d| ¡ ¡ d	S )
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.
        r   r   c                   S  s
   t ƒ ‚dS )ú…
            Raise an C{OSError} to emulate the branch of L{util._removeSafely}
            in which path removal fails.
            N©ÚOSErrorr#   r#   r#   r$   ÚdummyRemoveˆ  s    zORemoveSafelyTests.test_removeSafelyRemoveFailsMoveSucceeds.<locals>.dummyRemoveÚstdoutr}   ó   _trial_markerúcould not remove FilePathN)r   ÚpatchÚsysr   r~   r   r   r
   r€   ÚchildÚtouchÚremover   r‚   ÚassertInÚgetvalue)r    r‰   Úoutrƒ   r„   r#   r#   r$   Ú(test_removeSafelyRemoveFailsMoveSucceeds�  s    


z:RemoveSafelyTests.test_removeSafelyRemoveFailsMoveSucceedsc                 C  s¦   ddœdd„}dddddœd	d
„}t ƒ }|  td|¡ |  ¡  d¡}t |¡ t |¡}| 	d¡ 
¡  ||_||_|  ttj|¡}|  t|ƒd¡ |  d| ¡ ¡ dS )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.
        r   r   c                   S  s   t dƒ‚dS )r†   zpath removal failedNr‡   r#   r#   r#   r$   r‰   ¥  s    zLRemoveSafelyTests.test_removeSafelyRemoveFailsMoveFails.<locals>.dummyRemoveTrK   Úbool)ÚdestinationÚfollowLinksr   c                 S  s   t dƒ‚dS )z†
            Raise an C{OSError} to emulate the branch of L{util._removeSafely}
            in which path movement fails.
            úpath movement failedNr‡   )r—   r˜   r#   r#   r$   ÚdummyMoveTo¬  s    zLRemoveSafelyTests.test_removeSafelyRemoveFailsMoveFails.<locals>.dummyMoveTorŠ   r}   r‹   r™   rŒ   N)T)r   r�   rŽ   r   r~   r   r   r
   r€   r�   r�   r‘   ZmoveTor�   rˆ   r   r‚   r   r5   r’   r“   )r    r‰   rš   r”   rƒ   r„   r7   r#   r#   r$   Ú%test_removeSafelyRemoveFailsMoveFailsž  s    

z7RemoveSafelyTests.test_removeSafelyRemoveFailsMoveFailsN)r.   r/   r0   r1   r…   r•   r›   r#   r#   r#   r$   r|   q  s   r|   c                   @  s,   e Zd ZdZddœdd„Zddœdd„ZdS )	ÚExcInfoTestsz1
    Tests for L{excInfoOrFailureToExcInfo}.
    r   r   c                 C  s$   t t dƒdf}|  |t|ƒk¡ dS )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    Úinfor#   r#   r$   Útest_excInfoË  s    zExcInfoTests.test_excInfoc                 C  sH   zdd  W n t k
r&   tƒ }Y nX |  |j|j|jft|ƒ¡ dS )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.
        rF   r   N)ÚBaseExceptionr   r   Útypert   Útbr   )r    Úfr#   r#   r$   Útest_failureÓ  s
    zExcInfoTests.test_failureN)r.   r/   r0   r1   r    r¥   r#   r#   r#   r$   rœ   Æ  s   rœ   c                   @  sH   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zddœd
d„ZdS )ÚAcquireAttributeTestsz(
    Tests for L{acquireAttribute}.
    r   r   c                 C  s*   t ƒ  | _}|  |t| t ƒ gdƒk¡ dS )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.
        rt   N©rK   rt   r&   r   ©r    rt   r#   r#   r$   Útest_foundOnEarlierObjectå  s    z/AcquireAttributeTests.test_foundOnEarlierObjectc                 C  s*   t ƒ  | _}|  |tt ƒ | gdƒk¡ dS )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.
        rt   Nr§   r¨   r#   r#   r$   Útest_foundOnLaterObjectî  s    z-AcquireAttributeTests.test_foundOnLaterObjectc                 C  s   |   tttƒ gd¡ dS )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   rK   rD   r#   r#   r$   Útest_notFoundExceptionö  s    z,AcquireAttributeTests.test_notFoundExceptionc                 C  s$   t ƒ }|  |tt ƒ gd|ƒk¡ dS )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)rK   r&   r   )r    Údefaultr#   r#   r$   Útest_notFoundDefaultý  s    z*AcquireAttributeTests.test_notFoundDefaultN)r.   r/   r0   r1   r©   rª   r¬   r®   r#   r#   r#   r$   r¦   à  s
   	r¦   c                   @  sŽ   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zddœd
d„Zddœdd„Zddœdd„Z	ddœdd„Z
ddœdd„Zddœdd„ZdS )Ú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.
    r   r   c                 C  s$   g }d}t  |d¡}|  ||¡ dS )zB
        If things is empty, an empty string is returned.
        Ú ÚandN©r   Ú_listToPhraser   ©r    ÚsampleÚexpectedÚresultr#   r#   r$   Ú
test_empty  s    zListToPhraseTests.test_emptyc                 C  s&   dg}d}t  |d¡}|  ||¡ dS )z;
        With a single item, the item is returned.
        ÚOner±   Nr²   r´   r#   r#   r$   Útest_oneWord  s    zListToPhraseTests.test_oneWordc                 C  s(   ddg}d}t  |d¡}|  ||¡ dS )zA
        Two words are separated by the final delimiter.
        r¹   ÚTwozOne and Twor±   Nr²   r´   r#   r#   r$   Útest_twoWords   s    zListToPhraseTests.test_twoWordsc                 C  s*   dddg}d}t  |d¡}|  ||¡ dS )zY
        With more than two words, the first two are separated by the delimiter.
        r¹   r»   ÚThreezOne, Two, and Threer±   Nr²   r´   r#   r#   r$   Útest_threeWords)  s    
z!ListToPhraseTests.test_threeWordsc                 C  s0   ddddg}d}t j|ddd�}|  ||¡ d	S )
zW
        If a delimiter is specified, it is used instead of the default comma.
        r¹   r»   r½   ZFourzOne; Two; Three; or FourÚorz; )Ú	delimiterNr²   r´   r#   r#   r$   Útest_fourWords2  s    z ListToPhraseTests.test_fourWordsc                 C  s*   dddg}d}t  |d¡}|  ||¡ dS )zS
        If something in things is not a string, it is converted into one.
        rF   é   Zthreez1, 2, and threer±   Nr²   r´   r#   r#   r$   Útest_notString;  s    
z ListToPhraseTests.test_notStringc                 C  s*   d}|   ttj|d¡}|  t|ƒd¡ dS )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   r5   ©r    rµ   r7   r#   r#   r$   Útest_stringTypeErrorD  s    z&ListToPhraseTests.test_stringTypeErrorc                 C  s4   t dddgƒ}|  ttj|d¡}|  t|ƒd¡ dS )zB
        If things is an iterator, a TypeError is raised.
        rF   rÂ   é   r±   rÄ   N)Úiterr�   rÆ   r   r³   r   r5   rÇ   r#   r#   r$   Útest_iteratorTypeErrorL  s    z(ListToPhraseTests.test_iteratorTypeErrorc                 C  s4   ddœdd„}|   ttj|d¡}|  t|ƒd¡ dS )zB
        If things is a generator, a TypeError is raised.
        zGenerator[int, None, None]r   c                   s  s   t dƒE d H  d S )NrÂ   )Úranger#   r#   r#   r$   rµ   Y  s    z9ListToPhraseTests.test_generatorTypeError.<locals>.sampler±   rÄ   NrÅ   rÇ   r#   r#   r$   Útest_generatorTypeErrorT  s    z)ListToPhraseTests.test_generatorTypeErrorN)r.   r/   r0   r1   r¸   rº   r¼   r¾   rÁ   rÃ   rÈ   rË   rÍ   r#   r#   r#   r$   r¯     s   						r¯   c                   @  s,   e Zd ZdZddœdd„Zddœdd„ZdS )	ÚOpenTestLogTestsz#
    Tests for C{openTestLog}.
    r   r   c              	   C  s�   t  ¡ }|  t jt j|¡ t  t jd¡ d}t |  ¡ ¡}t|ƒ�}| 	|¡ W 5 Q R X t
|jdƒ�}| ¡ }W 5 Q R X t| d¡t|ƒƒ dS )zR
        The log file is opened in text mode and uses UTF-8 for encoding.
        )ÚCÚasciiu   Here comes the â˜‰Úrbr}   N)ÚlocaleÚ	getlocaleZ
addCleanupÚ	setlocaleÚLC_ALLr
   r€   r   r   ÚwriteÚopenr   Úreadr   r~   r   )r    ZcurrentLocaleÚtextÚpr¤   Zwrittenr#   r#   r$   Ú	test_utf8e  s    
zOpenTestLogTests.test_utf8c              	   C  s‚   d}d}dt j› dt j› �}t |  ¡ ¡}t|ƒ�}| |¡ W 5 Q R X t|ƒ�}| |¡ W 5 Q R X t| ¡  	d¡t
|ƒƒ dS )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.r}   N)r   Úlinesepr
   r€   r   r   rÖ   r   Z
getContentÚdecoder   )r    ZexistingTextZnewTextr¶   rÚ   r¤   r#   r#   r$   Útest_append{  s    

þzOpenTestLogTests.test_appendN)r.   r/   r0   r1   rÛ   rÞ   r#   r#   r#   r$   rÎ   `  s   rÎ   )+r1   Ú
__future__r   rÒ   r   rŽ   Úior   Útypingr   Zzope.interfacer   Zhamcrestr   r   Ztwisted.internet.baser   Ztwisted.internet.interfacesr	   Ztwisted.pythonr
   Ztwisted.python.failurer   Ztwisted.trialr   Ztwisted.trial.unittestr   Ztwisted.trial.utilr   r   r   r   r   r   r2   r;   rH   rN   r|   rœ   r¦   r¯   rÎ   r#   r#   r#   r$   Ú<module>   s4   	)3- 3U'Y