
    YfV                       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*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                  2    e Zd ZdZd	dZd	dZd	dZd	dZdS )
MktempTestszm
    Tests for L{TestCase.mktemp}, a helper function for creating temporary file
    or directory names.
    returnNonec                    |                                  }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dirss      N/var/www/html/env/lib/python3.11/site-packages/twisted/trial/test/test_util.pyr   zMktempTests.test_name)   sk    
 {{}}wt$$**26223B37NNN	
 	
 	
 	
 	
    c                ~    |                                  }|                     ||                                             dS )zF
        Repeated calls to C{mktemp} return different values.
        N)r   assertNotEqual)r"   r#   s     r%   test_uniquezMktempTests.test_unique4   s5     {{}}D$++--00000r&   c                4   |                                  }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   s      r%   test_createdzMktempTests.test_created;   sl     {{}}'//$''w//000--.....r&   c                    t           j                            |                                           }|                     |                    t          j                                         dS )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   sI     wt{{}}--	4455555r&   Nr   r   )__name__
__module____qualname____doc__r   r)   r.   r3    r&   r%   r   r   #   sn         
	
 	
 	
 	
1 1 1 1/ / / /6 6 6 6 6 6r&   r   c                  *    e Zd ZdZddZddZddZdS )	DirtyReactorAggregateErrorTestsz6
    Tests for the L{DirtyReactorAggregateError}.
    r   r   c                n    t          ddg          }|                     t          |          d           dS )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   sE     +E5>::JJ	
 	
 	
 	
 	
r&   c                p    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 2Nr?   rA   s     r%   test_formatSelectablesz6DirtyReactorAggregateErrorTests.test_formatSelectables_   sH     +2/OPPJJ	
 	
 	
 	
 	
r&   c                t    t          ddgddg          }|                     t          |          d           dS )zR
        Both delayed calls and selectables can appear in the same error.
        bleckBoozoSel1Sel2zReactor was unclean.
DelayedCalls: (set twisted.internet.base.DelayedCall.debug = True to debug)
bleck
Boozo
Selectables:
Sel1
Sel2Nr?   rA   s     r%   %test_formatDelayedCallsAndSelectableszEDirtyReactorAggregateErrorTests.test_formatDelayedCallsAndSelectablesm   sM     +GW+=?OPPJJ
	
 
	
 
	
 
	
 
	
r&   Nr4   )r5   r6   r7   r8   rC   rE   rK   r9   r&   r%   r;   r;   L   sZ         
 
 
 

 
 
 

 
 
 
 
 
r&   r;   c                  8    e Zd ZdZ	 ddd	ZdddZddZ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                F    || _         g | _        d| _        |sg }|| _        dS )z
        @param delayedCalls: See L{StubReactor.delayedCalls}.
        @param selectables: See L{StubReactor.selectables}.
        r   N)rN   
iterationsremoveAllCalledrP   )r"   rN   rP   s      r%   __init__zStubReactor.__init__   s6     ).0  	K&r&   timeoutfloat | Nonec                :    | j                             |           dS )z/
        Increment C{self.iterations}.
        N)rS   append)r"   rV   s     r%   iteratezStubReactor.iterate   s      	w'''''r&   c                    | j         S )z.
        Return C{self.delayedCalls}.
        )rN   r"   s    r%   getDelayedCallszStubReactor.getDelayedCalls   s       r&   list[object]c                0    | xj         dz  c_         | j        S )zS
        Increment C{self.removeAllCalled} and return C{self.selectables}.
           )rT   rP   r\   s    r%   	removeAllzStubReactor.removeAll   s!     	!r&   N)rN   rO   rP   rQ   r   r   )rV   rW   r   r   )r   rO   )r   r^   )r5   r6   r7   r8   rU   rZ   r]   ra   r9   r&   r%   rM   rM      s          SW' ' ' ' '( ( ( ( (! ! ! !           r&   rM   c                  "    e Zd ZdZddZ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                    g | _         d S rb   )errorsr\   s    r%   rU   zStubErrorReporter.__init__   s    46r&   testobjectrB   r   c                >    | j                             ||f           dS )z6
        Record parameters in C{self.errors}.
        N)rf   rY   )r"   rg   rB   s      r%   addErrorzStubErrorReporter.addError   s$     	D%=)))))r&   Nr4   )rg   rh   rB   r   r   r   )r5   r6   r7   r8   rU   rj   r9   r&   r%   rd   rd      sF         7 7 7 7* * * * * *r&   rd   c                  j    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S )JanitorTestsz 
    Tests for L{_Janitor}!
    r   r   c                    t          g           }t          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   )rM   r   _cleanPendingr!   rS   r"   ro   jans      r%   test_cleanPendingSpinsReactorz*JanitorTests.test_cleanPendingSpinsReactor   sX     b//tT7333+aV44444r&   c                    d	d}g }t          d|di |j        d           }t          |g          }t          dd|          }|                                 |                     ||g           dS )
zW
        During pending-call cleanup, the janitor cancels pending timed calls.
        r   r@   c                     dS )NLulzr9   r9   r&   r%   funcz8JanitorTests.test_cleanPendingCancelsCalls.<locals>.func   s    6r&   ,  r9   c                    d S rb   r9   xs    r%   <lambda>z<JanitorTests.test_cleanPendingCancelsCalls.<locals>.<lambda>   s    QU r&   Nrn   r   r@   )r	   rY   rM   r   rp   r!   )r"   rw   	cancelleddelayedCallro   rr   s         r%   test_cleanPendingCancelsCallsz*JanitorTests.test_cleanPendingCancelsCalls   s    
	 	 	 	 (*	!#tRY5E~~VV{m,,tT7333[M22222r&   c           	         t          dd di d d d           }t          |          }t          |g          }t          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.
        rx   c                     d S rb   r9   r9   r&   r%   r|   zIJanitorTests.test_cleanPendingReturnsDelayedCallStrings.<locals>.<lambda>        r&   r9   c                    d S rb   r9   rz   s    r%   r|   zIJanitorTests.test_cleanPendingReturnsDelayedCallStrings.<locals>.<lambda>        r&   c                    d S rb   r9   rz   s    r%   r|   zIJanitorTests.test_cleanPendingReturnsDelayedCallStrings.<locals>.<lambda>        r&   c                     dS Nr   r9   r9   r&   r%   r|   zIJanitorTests.test_cleanPendingReturnsDelayedCallStrings.<locals>.<lambda>       WX r&   secondsNrn   )r	   r@   rM   r   rp   r!   )r"   r   delayedCallStringro   rr   stringss         r%   *test_cleanPendingReturnsDelayedCallStringsz7JanitorTests.test_cleanPendingReturnsDelayedCallStrings   s     "r2~~~~yy
 
 
  ,,{m,,tT7333##%%#4"566666r&   c                    t          g           }t          dd|          }|                                 |                     |j        d           dS )zM
        The Janitor will remove selectables during reactor cleanup.
        Nrn   r`   )rM   r   _cleanReactorr!   rT   rq   s      r%   #test_cleanReactorRemovesSelectablesz0JanitorTests.test_cleanReactorRemovesSelectables   sT     b//tT73330!44444r&   c                   t          t                     G d d                      } |            }t          g |g          }t          dd|          }|                                 |                     |j        dg           dS )zI
        The Janitor will kill processes during reactor cleanup.
        c                  "    e Zd ZdZd	dZd
dZdS )JJanitorTests.test_cleanReactorKillsProcesses.<locals>.StubProcessTransportz
            A stub L{IProcessTransport} provider which records signals.
            @ivar signals: The signals passed to L{signalProcess}.
            r   r   c                    g | _         d S rb   )signalsr\   s    r%   rU   zSJanitorTests.test_cleanReactorKillsProcesses.<locals>.StubProcessTransport.__init__  s    02r&   signal	str | intc                :    | j                             |           dS )zF
                Append C{signal} to C{self.signals}.
                N)r   rY   )r"   r   s     r%   signalProcesszXJanitorTests.test_cleanReactorKillsProcesses.<locals>.StubProcessTransport.signalProcess  s      ##F+++++r&   Nr4   )r   r   r   r   )r5   r6   r7   r8   rU   r   r9   r&   r%   StubProcessTransportr      sF         
3 3 3 3, , , , , ,r&   r   Nrn   KILL)r   r
   rM   r   r   r!   r   )r"   r   ptro   rr   s        r%   test_cleanReactorKillsProcessesz,JanitorTests.test_cleanReactorKillsProcesses   s    
 
&	'	'	, 	, 	, 	, 	, 	, 	, 
(	'	, "!##b2$''tT7333fX.....r&   c                     G d d          }t          g  |            g          }t          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                      e Zd ZdZddZdS )JJanitorTests.test_cleanReactorReturnsSelectableStrings.<locals>.Selectablezl
            A stub Selectable which only has an interesting string
            representation.
            r   r@   c                    dS )N(SELECTABLE!)r9   r\   s    r%   __repr__zSJanitorTests.test_cleanReactorReturnsSelectableStrings.<locals>.Selectable.__repr__   s    &r&   Nr}   )r5   r6   r7   r8   r   r9   r&   r%   
Selectabler     s2         
' ' ' ' ' 'r&   r   Nrn   r   )rM   r   r!   r   )r"   r   ro   rr   s       r%   )test_cleanReactorReturnsSelectableStringsz6JanitorTests.test_cleanReactorReturnsSelectableStrings  s    	' 	' 	' 	' 	' 	' 	' 	' b::<<.11tT7333**,,.?@@@@@r&   c                   t          g           }t                      }t                      }t          |||          }|                     |                                           |                     |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.
        rn   N)rM   rh   rd   r   r+   postCaseCleanupr!   rf   r"   ro   rg   reporterrr   s        r%   test_postCaseCleanupNoErrorsz)JanitorTests.test_postCaseCleanupNoErrors'  ss    
 b//xx$&&tXw777++--..."-----r&   c           	        t          dd di d d d           }t          |          }t          |gg           }t                      }t	                      }t          |||          }|                     |                                           |                     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.
        rx   c                     d S rb   r9   r9   r&   r%   r|   z=JanitorTests.test_postCaseCleanupWithErrors.<locals>.<lambda>:  r   r&   r9   c                    d S rb   r9   rz   s    r%   r|   z=JanitorTests.test_postCaseCleanupWithErrors.<locals>.<lambda>:  r   r&   c                    d S rb   r9   rz   s    r%   r|   z=JanitorTests.test_postCaseCleanupWithErrors.<locals>.<lambda>:  r   r&   c                     dS r   r9   r9   r&   r%   r|   z=JanitorTests.test_postCaseCleanupWithErrors.<locals>.<lambda>:  r   r&   r   rn   r`   r   N)r	   r@   rM   rh   rd   r   r-   r   r!   lenrf   valuerN   r"   r   r   ro   rg   r   rr   s          r%   test_postCaseCleanupWithErrorsz+JanitorTests.test_postCaseCleanupWithErrors3  s     "r2~~~~yy
 
 
  ,,{mR00xx$&&tXw777,,..///X_--q111+A.4ADUCVWWWWWr&   c                    t          g           }t                      }t                      }t          |||          }|                                 |                     |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.
        rn   N)rM   rh   rd   r   postClassCleanupr!   rf   r   s        r%   test_postClassCleanupNoErrorsz*JanitorTests.test_postClassCleanupNoErrorsE  sg    
 b//xx$&&tXw777"-----r&   c           	        t          dd di d d d           }t          |          }t          |gg           }t                      }t	                      }t          |||          }|                                 |                     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.
        rx   c                     d S rb   r9   r9   r&   r%   r|   zIJanitorTests.test_postClassCleanupWithPendingCallErrors.<locals>.<lambda>W  r   r&   r9   c                    d S rb   r9   rz   s    r%   r|   zIJanitorTests.test_postClassCleanupWithPendingCallErrors.<locals>.<lambda>W  r   r&   c                    d S rb   r9   rz   s    r%   r|   zIJanitorTests.test_postClassCleanupWithPendingCallErrors.<locals>.<lambda>W  r   r&   c                     dS r   r9   r9   r&   r%   r|   zIJanitorTests.test_postClassCleanupWithPendingCallErrors.<locals>.<lambda>W  r   r&   r   rn   r`   r   N)r	   r@   rM   rh   rd   r   r   r!   r   rf   r   rN   r   s          r%   *test_postClassCleanupWithPendingCallErrorsz7JanitorTests.test_postClassCleanupWithPendingCallErrorsQ  s    
 "r2~~~~yy
 
 
  ,,{mR00xx$&&tXw777X_--q111+A.4ADUCVWWWWWr&   c                ~   d}t          g |g          }t                      }t                      }t          |||          }|                                 |                     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 HERErn   r`   r   N)rM   rh   rd   r   r   r!   r   rf   r   rP   repr)r"   
selectablero   rg   r   rr   s         r%   )test_postClassCleanupWithSelectableErrorsz6JanitorTests.test_postClassCleanupWithSelectableErrorsb  s    
 '
b:,//xx$&&tXw777X_--q111+A.4@4
CSCSBTUUUUUr&   Nr4   )r5   r6   r7   r8   rs   r   r   r   r   r   r   r   r   r   r   r9   r&   r%   rl   rl      s        
5 
5 
5 
53 3 3 37 7 7 7"5 5 5 5/ / / /6A A A A&
. 
. 
. 
.X X X X$
. 
. 
. 
.X X X X"V V V V V Vr&   rl   c                  *    e Zd ZdZddZddZddZdS )	RemoveSafelyTestsz*
    Tests for L{util._removeSafely}.
    r   r   c                    |                                                      d          }t          j        |           t	          j        |          }|                     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   _NoTrialMarker_removeSafely)r"   	directorydirPaths      r%   test_removeSafelyNoTrialMarkerz0RemoveSafelyTests.test_removeSafelyNoTrialMarkerv  sc     KKMM((11	
#I..$-t/A7KKKKKr&   c                   d	d}t                      }|                     t          d|           |                                                     d          }t          j        |           t          j        |          }|	                    d          
                                 ||_        t          j        |           |                     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                     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 FilePathNr4   )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    	 	 	 	 jj

3#&&& KKMM((11	
#I..&''--///$7###13<<>>BBBBBr&   c                V   dd}ddd	}t                      }|                     t          d
|           |                                                     d          }t          j        |           t          j        |          }|	                    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                      t          d          )r   zpath removal failedr   r9   r&   r%   r   zLRemoveSafelyTests.test_removeSafelyRemoveFailsMoveFails.<locals>.dummyRemove  s    
 /000r&   Tdestinationrh   followLinksboolc                     t          d          )z
            Raise an C{OSError} to emulate the branch of L{util._removeSafely}
            in which path movement fails.
            path movement failedr   )r   r   s     r%   dummyMoveTozLRemoveSafelyTests.test_removeSafelyRemoveFailsMoveFails.<locals>.dummyMoveTo  s    
 0111r&   r   r   r   r   r   Nr4   )T)r   rh   r   r   r   r   )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 	1 	1 	1	2 	2 	2 	2 	2 jj

3#&&& KKMM((11	
#I..&''--/// %$!!'4+=wGGU%;<<<13<<>>BBBBBr&   Nr4   )r5   r6   r7   r8   r   r   r   r9   r&   r%   r   r   q  sh         	L 	L 	L 	LC C C C:%C %C %C %C %C %Cr&   r   c                  "    e Zd ZdZddZddZdS )ExcInfoTestsz1
    Tests for L{excInfoOrFailureToExcInfo}.
    r   r   c                |    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"   infos     r%   test_excInfozExcInfoTests.test_excInfo  s>    
 Ju--t4 9$ ? ??@@@@@r&   c                    	 ddz   n# t           $ r t                      }Y nw xY 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.
        r`   r   N)BaseExceptionr   r!   typer   tbr   )r"   fs     r%   test_failurezExcInfoTests.test_failure  sl    	EEE 	 	 			AAA	!&!'1402KA2N2NOOOOOs    ##Nr4   )r5   r6   r7   r8   r   r   r9   r&   r%   r   r     sP         A A A A
P 
P 
P 
P 
P 
Pr&   r   c                  2    e Zd ZdZd	dZd	dZd	dZd	dZdS )
AcquireAttributeTestsz(
    Tests for L{acquireAttribute}.
    r   r   c                    t                      x| _        }|                     |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rh   r   r+   r   r"   r   s     r%   test_foundOnEarlierObjectz/AcquireAttributeTests.test_foundOnEarlierObject  sE     $XX%
U!142BG!L!LLMMMMMr&   c                    t                      x| _        }|                     |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   s     r%   test_foundOnLaterObjectz-AcquireAttributeTests.test_foundOnLaterObject  sE    
 $XX%
U!1688T2BG!L!LLMMMMMr&   c                d    |                      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   rh   r\   s    r%   test_notFoundExceptionz,AcquireAttributeTests.test_notFoundException  s+    
 	.*:VXXJNNNNNr&   c                    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)rh   r+   r   )r"   defaults     r%   test_notFoundDefaultz*AcquireAttributeTests.test_notFoundDefault  s=     ((#3VXXJw#O#OOPPPPPr&   Nr4   )r5   r6   r7   r8   r   r   r  r  r9   r&   r%   r   r     s         N N N NN N N NO O O OQ Q Q Q Q Q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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                d    g }d}t          j        |d          }|                     ||           dS )zB
        If things is empty, an empty string is returned.
         andNr   _listToPhraser!   r"   sampleexpectedresults       r%   
test_emptyzListToPhraseTests.test_empty  s<      #FE226*****r&   c                f    dg}d}t          j        |d          }|                     ||           dS )z;
        With a single item, the item is returned.
        Oner  Nr  r  s       r%   test_oneWordzListToPhraseTests.test_oneWord  s>     #FE226*****r&   c                h    ddg}d}t          j        |d          }|                     ||           dS )zA
        Two words are separated by the final delimiter.
        r  TwozOne and Twor  Nr  r  s       r%   test_twoWordszListToPhraseTests.test_twoWords   s@      #FE226*****r&   c                h    g d}d}t          j        |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  s       r%   test_threeWordsz!ListToPhraseTests.test_threeWords)  sB     )(((#FE226*****r&   c                l    g d}d}t          j        |dd          }|                     ||           dS )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  sG     100-#FDDAAA6*****r&   c                h    g d}d}t          j        |d          }|                     ||           dS )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;  s@     !$#FE226*****r&   c                    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!   r@   r"   r  rB   s      r%   test_stringTypeErrorz&ListToPhraseTests.test_stringTypeErrorD  sH     #!!)T-?OOU%GHHHHHr&   c                    t          g d          }|                     t          t          j        |d          }|                     t          |          d           dS )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  sR     iii!!)T-?OOU%GHHHHHr&   c                    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               3  4   K   t          d          E d {V  d S )Nr"  )ranger9   r&   r%   r  z9ListToPhraseTests.test_generatorTypeError.<locals>.sampleY  s*      Qxxr&   r  r&  N)r   r0  r'  r)  s      r%   test_generatorTypeErrorz)ListToPhraseTests.test_generatorTypeErrorT  sW    
	  	  	  	  !!)T-?OOU%GHHHHHr&   Nr4   )r5   r6   r7   r8   r  r  r  r  r   r$  r*  r.  r3  r9   r&   r%   r  r    s         + + + ++ + + ++ + + ++ + + ++ + + ++ + + +I I I II I I I	I 	I 	I 	I 	I 	Ir&   r  c                  "    e Zd ZdZddZddZdS )OpenTestLogTestsz#
    Tests for C{openTestLog}.
    r   r   c                j   t          j                    }|                     t           j        t           j        |           t          j        t           j        d           d}t          j        |                                           }t          |          5 }|	                    |           ddd           n# 1 swxY w Y   t          |j        d          5 }|                                }ddd           n# 1 swxY w 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	getlocale
addCleanup	setlocaleLC_ALLr   r   r   r   writeopenr   readr   r   r   )r"   currentLocaletextpr   writtens         r%   	test_utf8zOpenTestLogTests.test_utf8e  sk    (**(&-GGG777'dkkmm,,^^ 	qGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 !&$ 	1ffhhG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	DKK(((7*;*;<<<<<s$   B77B;>B;C88C<?C<c                   d}d}dt           j         dt           j         }t          j        |                                           }t          |          5 }|                    |           ddd           n# 1 swxY w Y   t          |          5 }|                    |           ddd           n# 1 swxY w 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   
getContentdecoder   )r"   existingTextnewTextr  rD  r   s         r%   test_appendzOpenTestLogTests.test_append{  sa   
 *%K2:KKrzKKdkkmm,,^^ 	"qGGL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"^^ 	qGGG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	LLNN!!'**X	
 	
 	
 	
 	
s$   A88A<?A<B44B8;B8Nr4   )r5   r6   r7   r8   rF  rM  r9   r&   r%   r5  r5  `  sF         = = = =,
 
 
 
 
 
r&   r5  )+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   rd   rl   r   r   r   r  r5  r9   r&   r%   <module>rZ     s7  
  # " " " " "  				 



             & & & & & & * * * * * * * * - - - - - - 9 9 9 9 9 9 # # # # # # * * * * * *       6 6 6 6 6 6             &6 &6 &6 &6 &6% &6 &6 &6R0
 0
 0
 0
 0
&9 0
 0
 0
f*  *  *  *  *  *  *  * Z* * * * * * * *&oV oV oV oV oV& oV oV oVdRC RC RC RC RC+ RC RC RCjP P P P P& P P P4$Q $Q $Q $Q $Q/ $Q $Q $QNVI VI VI VI VI+ VI VI VIr,
 ,
 ,
 ,
 ,
* ,
 ,
 ,
 ,
 ,
r&   