o
    Óó·i–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                   @  ó8   e Zd ZdZddd„Zddd„Zddd	„Zdd
d„ZdS )ÚMktempTestszm
    Tests for L{TestCase.mktemp}, a helper function for creating temporary file
    or directory names.
    ÚreturnÚNonec                 C  s8   |   ¡ }tj |¡ tj¡dd… }|  |g d¢¡ 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#   úbC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\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©r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r%   r)   r-   r#   r#   r#   r$   r   #   s    


	r   c                   @  ó.   e Zd ZdZddd„Zddd„Z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 2Nr6   r8   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
Sel2Nr6   r8   r#   r#   r$   Ú%test_formatDelayedCallsAndSelectablesm   s
   þzEDirtyReactorAggregateErrorTests.test_formatDelayedCallsAndSelectablesNr.   )r/   r0   r1   r2   r:   r;   r<   r#   r#   r#   r$   r4   L   s
    

r4   c                   @  s>   e Zd ZdZ	ddd	d
„Zdddd„Zddd„Z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}.
    NÚdelayedCallsúlist[DelayedCall]Úselectablesúlist[object] | Noner   r   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__Útimeoutúfloat | Nonec                 C  ó   | j  |¡ dS )z/
        Increment C{self.iterations}.
        N)rB   Úappend)r    rE   r#   r#   r$   Úiterate˜   ó   zStubReactor.iteratec                 C  s   | j S )z.
        Return C{self.delayedCalls}.
        N)r>   ©r    r#   r#   r$   ÚgetDelayedCallsž   s   zStubReactor.getDelayedCallsúlist[object]c                 C  s   |  j d7  _ | jS )zS
        Increment C{self.removeAllCalled} and return C{self.selectables}.
        é   N)rC   r@   rK   r#   r#   r$   Ú	removeAll¤   s   zStubReactor.removeAll©N)r>   r?   r@   rA   r   r   )rE   rF   r   r   )r   r?   )r   rM   )r/   r0   r1   r2   rD   rI   rL   rO   r#   r#   r#   r$   r=      s    ÿ
r=   c                   @  s$   e Zd ZdZddd„Z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  ó
   g | _ d S rP   )ÚerrorsrK   r#   r#   r$   rD   µ   ó   
zStubErrorReporter.__init__ÚtestÚobjectr9   r   c                 C  s   | j  ||f¡ dS )z6
        Record parameters in C{self.errors}.
        N)rS   rH   )r    rU   r9   r#   r#   r$   ÚaddError¸   s   zStubErrorReporter.addErrorNr.   )rU   rV   r9   r   r   r   )r/   r0   r1   r2   rD   rW   r#   r#   r#   r$   rQ   ¬   s    
rQ   c                   @  s~   e Zd ZdZddd„Zddd„Zddd	„Zdd
d„Zddd„Zddd„Z	ddd„Z
ddd„Zddd„Zddd„Z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   rB   ©r    rZ   Újanr#   r#   r$   Útest_cleanPendingSpinsReactorÄ   s   z*JanitorTests.test_cleanPendingSpinsReactorc                 C  sX   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.
        r   r7   c                   S  ó   dS )NZLulzr#   r#   r#   r#   r$   ÚfuncÕ   ó   z8JanitorTests.test_cleanPendingCancelsCalls.<locals>.funcé,  r#   c                 S  ó   d S rP   r#   ©Úxr#   r#   r$   Ú<lambda>Ù   ó    z<JanitorTests.test_cleanPendingCancelsCalls.<locals>.<lambda>NrY   ©r   r7   )r   rH   r=   r   r[   r   )r    r`   Ú	cancelledÚdelayedCallrZ   r]   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.
        rb   c                   S  rc   rP   r#   r#   r#   r#   r$   rf   è   rg   zIJanitorTests.test_cleanPendingReturnsDelayedCallStrings.<locals>.<lambda>r#   c                 S  rc   rP   r#   rd   r#   r#   r$   rf   è   rg   c                   S  r_   ©Nr   r#   r#   r#   r#   r$   rf   è   rg   ©ÚsecondsNrY   )r   r7   r=   r   r[   r   )r    rj   ÚdelayedCallStringrZ   r]   Ú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.
        NrY   rN   )r=   r   Ú_cleanReactorr   rC   r\   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„Z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  rR   rP   )ÚsignalsrK   r#   r#   r$   rD     rT   zSJanitorTests.test_cleanReactorKillsProcesses.<locals>.StubProcessTransport.__init__Úsignalú	str | intc                 S  rG   )zF
                Append C{signal} to C{self.signals}.
                N)rt   rH   )r    ru   r#   r#   r$   ÚsignalProcess  rJ   zXJanitorTests.test_cleanReactorKillsProcesses.<locals>.StubProcessTransport.signalProcessNr.   )ru   rv   r   r   )r/   r0   r1   r2   rD   rw   r#   r#   r#   r$   ÚStubProcessTransportþ   s    
rx   NrY   ZKILL)r   r	   r=   r   rr   r   rt   )r    rx   ÚptrZ   r]   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„ZdS )zJJanitorTests.test_cleanReactorReturnsSelectableStrings.<locals>.Selectablezl
            A stub Selectable which only has an interesting string
            representation.
            r   r7   c                 S  r_   )Nú(SELECTABLE!)r#   rK   r#   r#   r$   Ú__repr__   ra   zSJanitorTests.test_cleanReactorReturnsSelectableStrings.<locals>.Selectable.__repr__Nrh   )r/   r0   r1   r2   r|   r#   r#   r#   r$   Ú
Selectable  s    r}   NrY   r{   )r=   r   r   rr   )r    r}   rZ   r]   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.
        rY   N)r=   rV   rQ   r   r&   ÚpostCaseCleanupr   rS   ©r    rZ   rU   Úreporterr]   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.
        rb   c                   S  rc   rP   r#   r#   r#   r#   r$   rf   :  rg   z=JanitorTests.test_postCaseCleanupWithErrors.<locals>.<lambda>r#   c                 S  rc   rP   r#   rd   r#   r#   r$   rf   :  rg   c                   S  r_   rl   r#   r#   r#   r#   r$   rf   :  rg   rm   rY   rN   r   N)r   r7   r=   rV   rQ   r   r(   r   r   ÚlenrS   Úvaluer>   ©r    rj   ro   rZ   rU   r�   r]   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.
        rY   N)r=   rV   rQ   r   ÚpostClassCleanupr   rS   r€   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.
        rb   c                   S  rc   rP   r#   r#   r#   r#   r$   rf   W  rg   zIJanitorTests.test_postClassCleanupWithPendingCallErrors.<locals>.<lambda>r#   c                 S  rc   rP   r#   rd   r#   r#   r$   rf   W  rg   c                   S  r_   rl   r#   r#   r#   r#   r$   rf   W  rg   rm   rY   rN   r   N)r   r7   r=   rV   rQ   r   r‡   r   rƒ   rS   r„   r>   r…   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 HERErY   rN   r   N)r=   rV   rQ   r   r‡   r   rƒ   rS   r„   r@   Úrepr)r    Z
selectablerZ   rU   r�   r]   r#   r#   r$   Ú)test_postClassCleanupWithSelectableErrorsb  s   $z6JanitorTests.test_postClassCleanupWithSelectableErrorsNr.   )r/   r0   r1   r2   r^   rk   rq   rs   rz   r~   r‚   r†   rˆ   r‰   r‹   r#   r#   r#   r$   rX   ¿   s    




	




rX   c                   @  r3   )Ú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  sr   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 ƒ ‚)ú…
            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 FilePathNr.   )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„}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  ó   t dƒ‚)r–   zpath removal failedNr—   r#   r#   r#   r$   r™   ¥  ó   zLRemoveSafelyTests.test_removeSafelyRemoveFailsMoveFails.<locals>.dummyRemoveTÚdestinationrV   ÚfollowLinksÚboolc                 S  r¦   )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¬  r§   zLRemoveSafelyTests.test_removeSafelyRemoveFailsMoveFails.<locals>.dummyMoveTorš   r�   r›   r«   rœ   Nr.   )T)r¨   rV   r©   rª   r   r   )r   r�   rž   r   rŽ   r   r�   r
   r�   rŸ   r    r¡   ZmoveTor‘   r˜   r   r’   r   r7   r¢   r£   )r    r™   r¬   r¤   r“   r”   r9   r#   r#   r$   Ú%test_removeSafelyRemoveFailsMoveFailsž  s   


z7RemoveSafelyTests.test_removeSafelyRemoveFailsMoveFailsNr.   )r/   r0   r1   r2   r•   r¥   r­   r#   r#   r#   r$   rŒ   q  s
    

rŒ   c                   @  ó$   e Zd ZdZd	dd„Zd	dd„ZdS )
ÚExcInfoTestsz1
    Tests for L{excInfoOrFailureToExcInfo}.
    r   r   c                 C  s$   t t dƒdf}|  |t|ƒu ¡ 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  sF   zdd  W n t y   tƒ }Y nw |  |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.
        rN   r   N)ÚBaseExceptionr   r   Útyper„   Útbr   )r    Úfr#   r#   r$   Útest_failureÓ  s   
ÿ zExcInfoTests.test_failureNr.   )r/   r0   r1   r2   r³   r¸   r#   r#   r#   r$   r¯   Æ  s    
r¯   c                   @  r   )ÚAcquireAttributeTestsz(
    Tests for L{acquireAttribute}.
    r   r   c                 C  s*   t ƒ  | _}|  |t| t ƒ gdƒu ¡ 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.
        r„   N©rV   r„   r&   r   ©r    r„   r#   r#   r$   Útest_foundOnEarlierObjectå  s   z/AcquireAttributeTests.test_foundOnEarlierObjectc                 C  s*   t ƒ  | _}|  |tt ƒ | gdƒu ¡ 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.
        r„   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   rV   rK   r#   r#   r$   Útest_notFoundExceptionö  s   z,AcquireAttributeTests.test_notFoundExceptionc                 C  s$   t ƒ }|  |tt ƒ gd|ƒu ¡ 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)rV   r&   r   )r    Údefaultr#   r#   r$   Útest_notFoundDefaultý  s   z*AcquireAttributeTests.test_notFoundDefaultNr.   )r/   r0   r1   r2   r¼   r½   r¿   rÁ   r#   r#   r#   r$   r¹   à  s    

	
r¹   c                   @  sj   e Zd ZdZddd„Zddd„Zddd	„Zdd
d„Zddd„Zddd„Z	ddd„Z
ddd„Z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   ó   zListToPhraseTests.test_twoWordsc                 C  ó(   g d¢}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)  rÐ   z!ListToPhraseTests.test_threeWordsc                 C  s,   g d¢}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  rÑ   )zS
        If something in things is not a string, it is converted into one.
        )rN   é   Zthreez1, 2, and threerÄ   NrÅ   rÇ   r#   r#   r$   Útest_notString;  rÐ   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   r7   ©r    rÈ   r9   r#   r#   r$   Útest_stringTypeErrorD  s   z&ListToPhraseTests.test_stringTypeErrorc                 C  s2   t g d¢ƒ}|  ttj|d¡}|  t|ƒd¡ dS )zB
        If things is an iterator, a TypeError is raised.
        )rN   r×   é   rÄ   rÙ   N)Úiterr‘   rÛ   r   rÆ   r   r7   rÜ   r#   r#   r$   Útest_iteratorTypeErrorL  s   z(ListToPhraseTests.test_iteratorTypeErrorc                 C  s0   ddd„}|   ttj|d¡}|  t|ƒd¡ dS )	zB
        If things is a generator, a TypeError is raised.
        r   úGenerator[int, None, None]c                   s  s   � t dƒE d H  d S )Nr×   )Úranger#   r#   r#   r$   rÈ   Y  s   €z9ListToPhraseTests.test_generatorTypeError.<locals>.samplerÄ   rÙ   N)r   rá   rÚ   rÜ   r#   r#   r$   Útest_generatorTypeErrorT  s   
z)ListToPhraseTests.test_generatorTypeErrorNr.   )r/   r0   r1   r2   rË   rÍ   rÏ   rÓ   rÖ   rØ   rÝ   rà   rã   r#   r#   r#   r$   rÂ     s    

	
	
	
	
	
	
rÂ   c                   @  r®   )
ÚOpenTestLogTestsz#
    Tests for C{openTestLog}.
    r   r   c                 C  s¸   t  ¡ }|  t jt j|¡ t  t jd¡ d}t |  ¡ ¡}t|ƒ�}| 	|¡ W d  ƒ n1 s1w   Y  t
|jdƒ�}| ¡ }W d  ƒ n1 sKw   Y  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 â˜‰NÚrbr�   )Ú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 d  ƒ n1 s)w   Y  t|ƒ�}| |¡ W d  ƒ n1 sBw   Y  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.Nr�   )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_appendNr.   )r/   r0   r1   r2   rñ   rô   r#   r#   r#   r$   rä   `  s    
rä   )+r2   Ú
__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   r4   r=   rQ   rX   rŒ   r¯   r¹   rÂ   rä   r#   r#   r#   r$   Ú<module>   s6   	)3- 3U'Y