
    VhV                       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      L/home/dcms/DCMS/lib/python3.12/site-packages/twisted/trial/test/test_util.pyr   zMktempTests.test_name)   sK    
 {{}wwt$**26623B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     ww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,     +E5>: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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   s4     +GW+=?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/tT7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`    
	 (*	!#tRY5E5E~V{m,tT7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     "r2~~y
  ,{m,tT7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/tT7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    
 
&	'	, 	, 
(	, "#b2$'tT73fX.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tT7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$&tXw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     "r2~~y
  ,{mR0x$&tXw7,,./X__-q1+A.44AADUCV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$&tXw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    
 "r2~~y
  ,{mR0x$&tXw7X__-q1+A.44AADUCV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$&tXw7X__-q1+A.44@@4
CSBT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     KKM((1	
##I.$--t/A/A7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#& KKM((1	
##I.&'--/$7#13<<>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#& KKM((1	
##I.&'--/ %$!!'4+=+=wGU%;<13<<>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,    
 Ju-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 	!&&!''14402KA2N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!142BG!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!168T2BG!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    
 	.*:VXJ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*     (#3VXJ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      ##FE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     ##FE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      ##FE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     )(##FE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-##FDD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     !$##FE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     Qx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'dkkm,^ 	qGGDM	 !&&$ 	1ffhG	 	DKK((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::,.>rzzlKdkkm,^ 	"qGGL!	"^ 	qGGG	 	LLN!!'*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% &6R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$   