o
    >h&k                     @   s  d 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mZ ddlmZ ddlmZmZ dd	lmZmZmZmZ dd
lmZmZmZmZmZmZ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,m-Z-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZA ddlBmCZCmDZDmEZE ddlFmGZGmHZHmIZImJZJmKZK ddlLmMZMmNZNmOZOmPZP ddlQmRZRmSZSmTZTmUZU ddlVmWZWmXZX ddlYmZZZmZ d d!l[m\Z\m]Z] d"d#l^m_Z_ eG d$d% d%Z`ee(jaG d&d' d'e7ZbG d(d) d)eZZcG d*d+ d+eZdG d,d- d-eZeG d.d/ d/eZfG d0d1 d1egZhG d2d3 d3ZieG d4d5 d5ZjG d6d7 d7ZkG d8d9 d9egZlG d:d; d;ZmeG d<d= d=ZneG d>d? d?ZodS )@z-
Tests for L{twisted.trial._dist.disttrial}.
    N)partial)StringIO)sep)CallableListSetTestCase)implementerverify)Factoryassocdefinefield)assert_thatcontains	ends_withequal_to
has_lengthnonestarts_with)AllOf)given)booleanssampled_from)
interfaces)ReactorBase)CancelledErrorDeferredsucceed)ProcessDone)ProcessProtocolProtocol)AlternateReactor)MemoryReactorClock)Failure)FilePath)FilesystemLock)_WORKER_AMP_STDIN)DistReporter)DistTrialRunner
WorkerPoolWorkerPoolConfig)countingCallsdiscardResultfromOptionaliterateWhilesequence)LocalWorker	RunResultWorkerWorkerAction)Reporter
TestResultTreeReporterUncleanWarningsReporterWrapper)ErrorHolder
TrialSuite)SynchronousTestCaser	      )	erroneoussample   )matches_resultc                   @   s<   e Zd ZU dZeeedZee	 e
d< dd Zdd ZdS )	FakeTransportz*
    A simple fake process transport.
    default_closedc                 C   s   dS )z%
        Ignore write calls.
        N )selffddatarF   rF   /var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/trial/_dist/test/test_disttrial.pywriteToChildI   s    zFakeTransport.writeToChildc                 C   s   | j | dS )z>
        Mark one of the child descriptors as closed.
        N)rE   add)rG   rH   rF   rF   rJ   closeChildFDN   s   zFakeTransport.closeChildFDN)__name__
__module____qualname____doc__r   r   setrE   r   int__annotations__rK   rM   rF   rF   rF   rJ   rB   A   s
   
 rB   c                   @   sL   e Zd ZdZdZdZdZdd Zdi dddddfddZd	d
 Z	dd Z
dS )CountingReactorz
    A fake reactor that counts the calls to L{IReactorCore.run},
    L{IReactorCore.stop}, and L{IReactorProcess.spawnProcess}.
    r   c                 C   s   t |  || _d S N)r$   __init___workers)rG   workersrF   rF   rJ   rW   `   s   

zCountingReactor.__init__rF   Nc
           
      C   s*   | j | |t  |  jd7  _dS )z
        See L{IReactorProcess.spawnProcess}.

        @param workerProto: See L{IReactorProcess.spawnProcess}.
        @param args: See L{IReactorProcess.spawnProcess}.
        @param kwargs: See L{IReactorProcess.spawnProcess}.
        r@   N)rX   appendmakeConnectionrB   
spawnCount)
rG   workerProto
executableargsenvpathuidgidusePTYchildFDsrF   rF   rJ   spawnProcessd   s   zCountingReactor.spawnProcessc                 C   s>   t |  d| jv r| jd d d d   |  jd7  _dS )z+
        See L{IReactorCore.stop}.
        beforeshutdownr   r@   N)r$   stoptriggers	stopCountrG   rF   rF   rJ   ri   {   s   

zCountingReactor.stopc                 C   sT   |  j d7  _ d| _d| _| jD ]\}}}||i | q|   |  jd8  _dS )z*
        See L{IReactorCore.run}.
        r@   TN)runCountrunninghasRunwhenRunningHooksri   rk   )rG   fr_   kwargsrF   rF   rJ   run   s   zCountingReactor.run)rN   rO   rP   rQ   r\   rk   rm   rW   rf   ri   rs   rF   rF   rF   rJ   rU   U   s     
rU   c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )CountingReactorTestsz'
    Tests for L{CountingReactor}.
    c                 C   s   g | _ t| j | _d S rV   )rY   rU   reactorrl   rF   rF   rJ   setUp   s   zCountingReactorTests.setUpc                 C   s   t tj| j dS )zJ
        L{CountingReactor} instances provide L{IReactorProcess}.
        N)r   verifyObjectr   IReactorProcessru   rl   rF   rF   rJ   test_providesIReactorProcess   s   z1CountingReactorTests.test_providesIReactorProcessc                 C   sj   |  | jj t }dD ]&}| jj|tjtjgd | |j | 	| j
|g|  | 	| jj| qdS )z
        The process protocol for a spawned process is connected to a
        transport and appended onto the provided C{workers} list, and
        the reactor's C{spawnCount} increased.
        r@      )r_   N)assertFalseru   r\   r"   rf   sysr^   
assertTrue	transportassertEqualrY   )rG   protocountrF   rF   rJ   test_spawnProcess   s   z&CountingReactorTests.test_spawnProcessc                 C   s6   |  | jj dD ]}| j  | | jj| q	dS )zB
        Stopping the reactor increments its C{stopCount}
        rz   N)r|   ru   rk   ri   r   )rG   r   rF   rF   rJ   	test_stop   s
   
zCountingReactorTests.test_stopc                 C   sj   |  | jj g }| j|jd dD ]}| j  | | jj| | | jjd | t|| qdS )z
        Running the reactor increments its C{runCount}, does not imply
        C{stop}, and calls L{IReactorCore.callWhenRunning} hooks.
        Nrz   r   )	r|   ru   rm   callWhenRunningrZ   rs   r   rk   len)rG   whenRunningCallsr   rF   rF   rJ   test_run   s   
zCountingReactorTests.test_runN)	rN   rO   rP   rQ   rv   ry   r   r   r   rF   rF   rF   rJ   rt      s    	rt   c                   @   sr   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	e
e edde dgdededdfddZdS )WorkerPoolTestsz"
    Tests for L{WorkerPool}.
    c                 C   s@   t |  | _| jd| _td| jg dd| _t| j| _d S )N_trial_temp   out.log)
numWorkersworkingDirectoryworkerArgumentslogFile)	r&   mktempparentchildr   r,   configr+   poolrl   rF   rF   rJ   rv      s   zWorkerPoolTests.setUpc                 C   sR   dd t dD }| j|tdt }|D ]}| |t q| dt| dS )zw
        C{_createLocalWorkers} iterates the list of protocols and create one
        L{LocalWorker} for each.
        c                 S      g | ]}t  qS rF   )object).0xrF   rF   rJ   
<listcomp>       z;WorkerPoolTests.test_createLocalWorkers.<locals>.<listcomp>r   ra   N)	ranger   _createLocalWorkersr&   r   assertIsInstancer2   r   r   )rG   	protocolsrY   srF   rF   rJ   test_createLocalWorkers   s
   z'WorkerPoolTests.test_createLocalWorkersc                    s   dd t dD }g  i di dddddf fdd	}| j||d	g |  d  d
  | tj d  | d	 d  | tj	t
jd  dS )z
        Given a C{spawnProcess} function, C{_launchWorkerProcess} launches a
        python process with an existing path as its argument.
        c                 S   r   rF   )r!   r   irF   rF   rJ   r      r   z>WorkerPoolTests.test_launchWorkerProcesses.<locals>.<listcomp>r   rF   Nr   c	           	         s"     |  | | d S rV   )rZ   extendupdate)	processProtocolr^   r_   r`   ra   rb   rc   rd   re   	argumentsenvironmentrF   rJ   fakeSpawnProcess   s   

zDWorkerPoolTests.test_launchWorkerProcesses.<locals>.fakeSpawnProcessfoor@   r{   r=   
PYTHONPATH)r   r   _launchWorkerProcessesr   r~   osra   existspathsepjoinr}   )rG   r   r   rF   r   rJ   test_launchWorkerProcesses   s    z*WorkerPoolTests.test_launchWorkerProcessesc                    sZ   | j   g  | jtg }| |}| fdd}| | t t| j	j
 dS )zY
        C{run} dispatches the given action to each of its workers exactly once.
        c                    s   t  | S rV   )r   rZ   )wrY   rF   rJ   <lambda>  s    z*WorkerPoolTests.test_run.<locals>.<lambda>N)r   makedirsr   startrU   successResultOfrs   r   r   r   r   )rG   startingstartedrn   rF   r   rJ   r     s   


zWorkerPoolTests.test_runc                 C   sh   | j   t| jjd }| |  | |j t	g }| 
| j|}| |j| jd dS )z
        L{WorkerPool.start} checks if the test directory is already locked, and if
        it is generates a name based on it.
        z.lockz_trial_temp-1N)r   r   r'   r   ra   r~   lock
addCleanupunlockrU   r   r   r   r   sibling)rG   r   fakeReactorr   rF   rF   rJ   test_runUsedDirectory  s   

z%WorkerPoolTests.test_runUsedDirectoryc                 C   s   | j   tg }| | j|}t| }| 	| |j
D ](}t|jjtt |jjD ]}|| q0|j|jfD ]
}|ttd q>q!t| |t  t|jjtd t|jjtd dS )z
        L{StartedWorkerPool.join} causes all of the workers to exit, closes the
        log file, and unlocks the test directory.
        r   TFN)r   r   rU   r   r   r   r   fromCoroutiner   assertNoResultrX   r   r   rE   r   r(   childConnectionLostprocessExitedprocessEndedr%   r    r   testLogclosedr   testDirLocklocked)rG   ru   r   joiningr   rH   rq   rF   rF   rJ   	test_join3  s   


zWorkerPoolTests.test_joinr   subdirabsoluter   returnNc                 C   sx   |r
| j jt | }t| j|d}|rt|}ntt|jjt	t| }t
|}| |tg }t|jj| dS )z
        L{WorkerPool.start} creates a L{StartedWorkerPool} configured with a
        log file based on the L{WorkerPoolConfig.logFile}.
        )r   N)r   ra   r   r   r   r   r   r   r   r   r+   r   r   rU   r   r   name)rG   r   r   r   matchesr   r   rF   rF   rJ   test_logFileH  s   


zWorkerPoolTests.test_logFile)rN   rO   rP   rQ   rv   r   r   r   r   r   r   r   r   r   boolstrr   rF   rF   rF   rJ   r      s"    !
	r   c                   @   s   e Zd ZdZeedgZdd Zdd Z	dd Z
d%ddZdd Zdd Zd%ddZd%ddZd%ddZd%ddZdd Zdd Zd%ddZd%dd Zd%d!d"Zd#d$ Zd
S )&DistTrialRunnerTestsz'
    Tests for L{DistTrialRunner}.
    test_fooc              
   K   s@   t t|  t dg ttddtg d}|| tdi |S )z.
        Create a runner for testing.
        r   T)autostop)reporterFactoryr   stream
maxWorkersr   workerPoolFactoryru   NrF   )	dictr8   r   r   r   LocalWorkerPoolrU   r   r*   )rG   	overridesr_   rF   rF   rJ   	getRunnerr  s   

	zDistTrialRunnerTests.getRunnerc                 C   s:   t  }tt|}|  }|| | | dk dS )ze
        L{DistTrialRunner.writeResults} writes to the stream specified in the
        init.
        r   N)r   r)   r6   r   writeResultsr~   tell)rG   stringIOresultrunnerrF   rF   rJ   test_writeResults  s
   
z&DistTrialRunnerTests.test_writeResultsc                    sf   d  fdd}d}d}| j ||d}tdd t|D }| || t jd	 jt| dS )
zq
        L{DistTrialRunner.runAsync} doesn't try to start more workers than the
        number of tests.
        Nc                        t | ddi|  S )Nr   Tr   akwr   rF   rJ   recordingFactory     zADistTrialRunnerTests.test_minimalWorker.<locals>.recordingFactory   r=   )r   r   c                 S   r   rF   r   )r   nrF   rF   rJ   r     r   z;DistTrialRunnerTests.test_minimalWorker.<locals>.<listcomp>r   )	r   r;   r   r   runAsyncr   _startedrY   r   )rG   r   r   numTestsr   suiterF   r   rJ   test_minimalWorker  s   z'DistTrialRunnerTests.test_minimalWorkerr   Nc                 C   s@   | j dd}|| j}| |}| |t | |jt dS )z
        Running with the C{unclean-warnings} option makes L{DistTrialRunner} uses
        the L{UncleanWarningsReporterWrapper}.
        T)uncleanWarningsN)r   r   r   r   r   r)   originalr9   )rG   r   dr   rF   rF   rJ   test_runUncleanWarnings  s
   
z,DistTrialRunnerTests.test_runUncleanWarningsc                 C   sT   t  }| j|d}| |t }| |t | }| d| | d| dS )zA
        L{DistTrialRunner} can run an empty test suite.
        r   Running 0 testPASSEDN)	r   r   r   r   r;   r   r)   getvalueassertIn)rG   r   r   r   outputrF   rF   rJ   test_runWithoutTest  s   z(DistTrialRunnerTests.test_runWithoutTestc                 C   s   t dttd}t }| j|d}| ||}| |t |	 }| 
d| | 
d| | 
d| | 
d| | 
d| dS )z
        Even if there is no test, the suite can contain an error (most likely,
        an import error): this should make the run fail, and the error should
        be printed.
        zan errorzfoo barr   r   zerrors=1FAILEDN)r:   r%   RuntimeErrorr   r   r   r   r   r)   r   r   )rG   errr   r   r   r   rF   rF   rJ   !test_runWithoutTestButWithAnError  s   z6DistTrialRunnerTests.test_runWithoutTestButWithAnErrorc                 C   sP   | j td}| || j}|jj}t|td t|d d j	t
t dS )z
        If for some reasons we can't connect to the worker process, the error is
        recorded in the result object.
        r   r@   r   N)r   BrokenWorkerPoolr   r   r   r   errorsr   r   typer   WorkerPoolBrokenrG   r   r   r  rF   rF   rJ   test_runUnexpectedError  s
   z,DistTrialRunnerTests.test_runUnexpectedErrorc                 C   sH   | j td}| t || j W d   dS 1 sw   Y  dS )z
        If the reactor is stopped by C-c (i.e. `run` returns before the test
        case's Deferred has been fired) we should cancel the pending test run.
        r  N)r   r   assertRaisesr   rs   r   )rG   r   rF   rF   rJ   test_runUnexpectedErrorCtrlC  s   "z1DistTrialRunnerTests.test_runUnexpectedErrorCtrlCc                 C   sZ   | j tttddd}| || j}|jj}t	|t
d t	|d d jtt dS )z~
        If for some reason the worker process cannot run a test, the error is
        recorded in the result object.
        T)workerFactoryr   r  r@   r   N)r   r   r   _BrokenLocalWorkerr   r   r   r   r  r   r   r  r   WorkerBrokenr  rF   rF   rJ   test_runUnexpectedWorkerError  s   z2DistTrialRunnerTests.test_runUnexpectedWorkerErrorc                    s   d  fdd}| j |d}t|| j} du r | d  dus&J  jd j}| | |	d | 
|}| |t dS )zG
        L{DistTrialRunner} waits for the worker pool to stop.
        Nc                     r   )Nr   Fr   r   r   rF   rJ   r     r   zPDistTrialRunnerTests.test_runWaitForProcessesDeferreds.<locals>.recordingFactoryr  zworker pool was never createdr   )r   r   r   r   r   failr   _stoppedr   callbackr   r   r)   )rG   r   r   r   stoppedr   rF   r   rJ   !test_runWaitForProcessesDeferreds  s   



z6DistTrialRunnerTests.test_runWaitForProcessesDeferredsc                 C   sf   t  }ttdtdtdg}| j|ddd}||}| |}t	|j
tdtdd d	S )
z
        L{DistTrialRunner} can run in C{exitFirst} mode where it will run until a
        test fails and then abandon the rest of the suite.
        r   	test_failtest_barTr{   )r   	exitFirstr   r@   )	successesfailuresN)r   r;   r?   FooTestr>   TestRegularFailr   r   r   r   r   rA   r   )rG   r   r   r   r   r   rF   rF   rJ   test_exitFirst	  s"   

z#DistTrialRunnerTests.test_exitFirstc                 C   s   t  }td}| j|d}|j|dd}| |}| d|j | |	  |
 }| |d|jd d | d	| tdd
D ]}| d| | qD| |d|jd dS )z
        L{DistTrialRunner} can run in C{untilFailure} mode where it will run
        the given tests until they fail.
        test_itr   T)untilFailure   r   r@   z expected to see PASSED in outputFAIL   z
Test Pass zRan 1 tests inz2expected to see per-iteration test count in outputN)r   r>   EventuallyFailingTestCaser   r   r   r   r   r|   wasSuccessfulr   r   r   r   )rG   r   caser   r   r   r   r   rF   rF   rJ   test_runUntilFailure"  s*   

z)DistTrialRunnerTests.test_runUntilFailurec                 C   s:   |   }|| j}t| td t|jtd dS )zw
        L{DistTrialRunner.run} returns a L{DistReporter} containing the result of
        the test suite run.
        Tr@   N)r   rs   r   r   r#  r   r  )rG   r   r   rF   rF   rJ   r   E  s   zDistTrialRunnerTests.test_runc                 C   s   t g }t| | jdd}W d   n1 sw   Y  || j}t|jtg  t|jtg  t|	 td t|j
td t|jtd t|jtd dS )z
        L{DistTrialRunner.run} uses the installed reactor L{DistTrialRunner} was
        constructed without a reactor.
        Nru   Tr@   )rU   r#   r   rs   r   r   r  r   r  r#  r  rm   rk   )rG   ru   r   r   rF   rF   rJ   test_installedReactorO  s   
z*DistTrialRunnerTests.test_installedReactorc              	   C   sl  G dd dt }ttjG dd d}G dd d}t| # | t | jdd W d   n1 s7w   Y  W d   n1 sFw   Y  t| # | t | jdd W d   n1 sgw   Y  W d   n1 svw   Y  t| , | t | jdd W d   n1 sw   Y  W d   dS W d   dS 1 sw   Y  dS )	z
        L{DistTrialRunner} raises L{TypeError} if the installed reactor provides
        neither L{IReactorCore} nor L{IReactorProcess} and no other reactor is
        given.
        c                   @   s   e Zd Zdd ZdS )z=DistTrialRunnerTests.test_wrongInstalledReactor.<locals>.Corec                 S      d S rV   rF   rl   rF   rF   rJ   installWakerg  s   zJDistTrialRunnerTests.test_wrongInstalledReactor.<locals>.Core.installWakerN)rN   rO   rP   r)  rF   rF   rF   rJ   Coref  s    r*  c                   @   s"   e Zd Z						dddZdS )z@DistTrialRunnerTests.test_wrongInstalledReactor.<locals>.ProcessNFc
           
      S   r(  rV   rF   )
rG   r   r^   r_   r`   ra   rb   rc   rd   re   rF   rF   rJ   rf   l  s   zMDistTrialRunnerTests.test_wrongInstalledReactor.<locals>.Process.spawnProcess)NNNNFN)rN   rO   rP   rf   rF   rF   rF   rJ   Processj  s    r+  c                   @      e Zd ZdS )z@DistTrialRunnerTests.test_wrongInstalledReactor.<locals>.NeitherNrN   rO   rP   rF   rF   rF   rJ   Neitherz      r.  Nr&  )r   r
   r   rx   r#   r
  	TypeErrorr   )rG   r*  r+  r.  rF   rF   rJ   test_wrongInstalledReactor_  s.   "z/DistTrialRunnerTests.test_wrongInstalledReactorc                    sd   G dd dt   fdd}| j|d}|   || j W d   dS 1 s+w   Y  dS )z
        If there is an unexpected exception running the test suite then it is
        re-raised by L{DistTrialRunner.run}.
        c                   @   r,  )z;DistTrialRunnerTests.test_runFailure.<locals>.BrokenFactoryNr-  rF   rF   rF   rJ   BrokenFactory  r/  r2  c                     s     rV   rF   )r_   rr   r2  rF   rJ   brokenFactory  s   z;DistTrialRunnerTests.test_runFailure.<locals>.brokenFactoryr  N)	Exceptionr   r
  rs   r   )rG   r4  r   rF   r3  rJ   test_runFailure  s   "z$DistTrialRunnerTests.test_runFailurer   N)rN   rO   rP   rQ   r;   r?   r  r   r   r   r   r   r   r  r	  r  r  r  r  r%  r   r'  r1  r6  rF   rF   rF   rJ   r   k  s&    



	

#


-r   c                   @   sB   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S )FunctionalTestsz8
    Tests for the functional helpers that need it.
    r   Nc                 C   s,   t tddtd t tddtd dS )z
        ``fromOptional`` accepts a default value and an ``Optional`` value of the
        same type and returns the default value if the optional value is
        ``None`` or the optional value otherwise.
        r@   Nr{   )r   r/   r   rl   rF   rF   rJ   test_fromOptional  s   z!FunctionalTests.test_fromOptionalc                 C   s8   t  }t|}| | |d t| |t  dS )z
        ``discardResult`` accepts an awaitable and returns a ``Deferred`` that
        fires with ``None`` after the awaitable completes.
        r   N)r   r.   r   r  r   r   r   )rG   r   r   rF   rF   rJ   test_discardResult  s
   

z"FunctionalTests.test_discardResultc                 C   sR   t  }t  }t t||}|d | | |d t| |td dS )z
        ``sequence`` accepts two awaitables and returns an awaitable that waits
        for the first one to complete and then completes with the result of
        the second one.
        *   helloN)r   r   r1   r  r   r   r   r   )rG   r   bcrF   rF   rJ   test_sequence  s   


zFunctionalTests.test_sequencec                 C   sl   t  t  t  g}dd }t t|t|j}| d | | | d t| |t	d dS )z
        ``iterateWhile`` executes the actions from its factory until the predicate
        does not match an action result.
        c                 S   s   | dkS )Nr;  rF   )valuerF   rF   rJ   	predicate  s   z4FunctionalTests.test_iterateWhile.<locals>.predicater   r;  N)
r   r   r0   listpopr  r   r   r   r   )rG   actionsrA  r   rF   rF   rJ   test_iterateWhile  s   
z!FunctionalTests.test_iterateWhilec                 C   s:   t dtdtfdd}tddD ]
}t| t| qdS )z
        ``countingCalls`` decorates a function so that it is called with an
        increasing counter and passes the return value through.
        r   r   c                 S   s   | d S )Nr@   rF   )r   rF   rF   rJ   target  s   z2FunctionalTests.test_countingCalls.<locals>.targetr@   
   N)r-   rS   r   r   r   )rG   rF  expectedrF   rF   rJ   test_countingCalls  s
   z"FunctionalTests.test_countingCallsr7  )	rN   rO   rP   rQ   r9  r:  r?  rE  rI  rF   rF   rF   rJ   r8    s    

	

r8  c                   @      e Zd ZdZdS )r  zx
    An exception for ``StartedWorkerPoolBroken`` to fail with to allow tests
    to exercise exception code paths.
    NrN   rO   rP   rQ   rF   rF   rF   rJ   r        r  c                   @   s0   e Zd ZdZded ddfddZd	ddZdS )
StartedWorkerPoolBrokenzn
    A broken, started worker pool.  Its workers cannot run actions.  They
    always raise an exception.
    workerActionNr   c                       t  rV   )r  )rG   rN  rF   rF   rJ   rs     s   zStartedWorkerPoolBroken.runc                    s   d S rV   rF   rl   rF   rF   rJ   r     s   zStartedWorkerPoolBroken.joinr7  )rN   rO   rP   rQ   r5   rs   r   rF   rF   rF   rJ   rM    s    rM  c                   @   s.   e Zd ZU dZeed< dejdefddZ	dS )r  zF
    A worker pool that has workers with a broken ``run`` method.
    _configru   r   c                    s   t  S rV   )rM  )rG   ru   rF   rF   rJ   r   	  s   zBrokenWorkerPool.startN)
rN   rO   rP   rQ   r,   rT   r   rx   rM  r   rF   rF   rF   rJ   r    s   
 r  c                   @   s&   e Zd ZdZdededefddZdS )_LocalWorkerz
    A L{Worker} that runs tests in this process in the usual way.

    This is a test double for L{LocalWorkerAMP} which allows testing worker
    pool logic without sending tests over an AMP connection to be run
    somewhere else..
    r$  r   r   c                    s   t |g| ddiS )z8
        Directly run C{case} in the usual way.
        successT)r;   rs   rG   r$  r   rF   rF   rJ   rs     s   z_LocalWorker.runN)rN   rO   rP   rQ   PyUnitTestCaser7   r3   rs   rF   rF   rF   rJ   rQ    s    rQ  c                   @   rJ  )r  zE
    A worker tried to run a test case but the worker is broken.
    NrK  rF   rF   rF   rJ   r     rL  r  c                   @   s&   e Zd ZdZdededdfddZdS )r  z:
    A L{Worker} that always fails to run test cases.
    r$  r   r   Nc                    rO  )z@
        Raise an exception instead of running C{case}.
        )r  rS  rF   rF   rJ   rs   +  s   z_BrokenLocalWorker.run)rN   rO   rP   rQ   rT  r7   rs   rF   rF   rF   rJ   r  &  s    r  c                   @   sT   e Zd ZU dZee ed< ee ed< e	d ed< de
d ddfdd	Zd
d ZdS )StartedLocalWorkerPoolz'
    A started L{LocalWorkerPool}.
    r   rY   Nr  rN  r   c                    s    | j D ]	}||I dH  qdS )z8
        Run the action with each local worker.
        Nr   )rG   rN  workerrF   rF   rJ   rs   <  s   
zStartedLocalWorkerPool.runc                    s   | j I d H  d S rV   )r  rl   rF   rF   rJ   r   C  s   zStartedLocalWorkerPool.join)rN   rO   rP   rQ   r&   r   rT   r   r4   r   r5   rs   r   rF   rF   rF   rJ   rU  2  s   
 rU  c                   @   sh   e Zd ZU dZeed< eeedZ	e
e ed< dZeed< eZeg ef ed< dejd	efd
dZdS )r   z_
    Implement a worker pool that runs tests in-process instead of in child
    processes.
    rP  rC   r   F	_autostop_workerFactoryru   r   c                    sL    fddt  jjD }t jj| jrtd nt } j	| |S )Nc                    s   g | ]}   qS rF   )rX  r   rl   rF   rJ   r   V  s    z)LocalWorkerPool.start.<locals>.<listcomp>)
r   rP  r   rU  r   rW  r   r   r   rZ   )rG   ru   rY   r   rF   rl   rJ   r   S  s   zLocalWorkerPool.startN)rN   rO   rP   rQ   r,   rT   r   r   rB  r   r   rU  rW  r   rQ  rX  r   r4   r   rx   r   rF   rF   rF   rJ   r   G  s   
 r   )prQ   r   r}   	functoolsr   ior   os.pathr   typingr   r   r   unittestr	   rT  zope.interfacer
   r   attrsr   r   r   r   hamcrestr   r   r   r   r   r   r   hamcrest.core.core.allofr   
hypothesisr   hypothesis.strategiesr   r   twisted.internetr   twisted.internet.baser   twisted.internet.deferr   r   r   twisted.internet.errorr    twisted.internet.protocolr!   r"   #twisted.internet.test.modulehelpersr#   twisted.internet.testingr$   twisted.python.failurer%   twisted.python.filepathr&   twisted.python.lockfiler'   twisted.trial._distr(    twisted.trial._dist.distreporterr)   twisted.trial._dist.disttrialr*   r+   r,   twisted.trial._dist.functionalr-   r.   r/   r0   r1   twisted.trial._dist.workerr2   r3   r4   r5   twisted.trial.reporterr6   r7   r8   r9   twisted.trial.runnerr:   r;   twisted.trial.unittestr<   testr>   r?   matchersrA   rB   rx   rU   rt   r   r   r8  r5  r  rM  r  rQ  r  r  rU  r   rF   rF   rF   rJ   <module>   sp   $	B8   6N