
    Vh&k                        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%             Z` ee(j                         G d& d'e7             Zb G d( d)eZ      Zc G d* d+e      Zd G d, d-e      Ze G d. d/e      Zf G d0 d1eg      Zh G d2 d3      Zie G d4 d5             Zj G d6 d7      Zk G d8 d9eg      Zl G d: d;      Zme G d< d=             Zne G d> d?             Zoy)@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                   L    e Zd ZU dZ e ee            Zee	   e
d<   d Zd Zy)FakeTransportz*
    A simple fake process transport.
    default_closedc                      y)z%
        Ignore write calls.
        N )selffddatas      W/home/dcms/DCMS/lib/python3.12/site-packages/twisted/trial/_dist/test/test_disttrial.pywriteToChildzFakeTransport.writeToChildI   s        c                 :    | j                   j                  |       y)z>
        Mark one of the child descriptors as closed.
        N)rF   add)rI   rJ   s     rL   closeChildFDzFakeTransport.closeChildFDN   s     	rN   N)__name__
__module____qualname____doc__r   r   setrF   r   int__annotations__rM   rQ   rH   rN   rL   rC   rC   A   s*     gcl3GSX3
rN   rC   c                   D    e Zd ZdZdZdZdZd Zdi dddddfdZd Z	d Z
y)	CountingReactorz
    A fake reactor that counts the calls to L{IReactorCore.run},
    L{IReactorCore.stop}, and L{IReactorProcess.spawnProcess}.
    r   c                 <    t        j                  |        || _        y N)r$   __init___workers)rI   workerss     rL   r]   zCountingReactor.__init__`   s    ##D)rN   rH   Nc
                     | j                   j                  |       |j                  t                      | xj                  dz  c_        y)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)r^   appendmakeConnectionrC   
spawnCount)
rI   workerProto
executableargsenvpathuidgidusePTYchildFDss
             rL   spawnProcesszCountingReactor.spawnProcessd   s4    & 	[)""=?31rN   c                     t        j                  |        d| j                  v r | j                  d   d   d   d           | xj                  dz  c_        y)z+
        See L{IReactorCore.stop}.
        beforeshutdownr   r@   N)r$   stoptriggers	stopCountrI   s    rL   rq   zCountingReactor.stop{   sN     	% t}}$5DMM(#J/2157!rN   c                     | xj                   dz  c_         d| _        d| _        | j                  D ]  \  }}} ||i |  | j	                          | xj
                  dz  c_        y)z*
        See L{IReactorCore.run}.
        r@   TN)runCountrunninghasRunwhenRunningHooksrq   rs   )rI   frf   kwargss       rL   runzCountingReactor.run   sa     	 #44 	OAtVtv			!rN   )rR   rS   rT   rU   rc   rs   rv   r]   rm   rq   r|   rH   rN   rL   rZ   rZ   U   sC    
 JIH  .
rN   rZ   c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)CountingReactorTestsz'
    Tests for L{CountingReactor}.
    c                 F    g | _         t        | j                         | _        y r\   )r_   rZ   reactorrt   s    rL   setUpzCountingReactorTests.setUp   s    &t||4rN   c                 `    t        j                  t        j                  | j                         y)zJ
        L{CountingReactor} instances provide L{IReactorProcess}.
        N)r   verifyObjectr   IReactorProcessr   rt   s    rL   test_providesIReactorProcessz1CountingReactorTests.test_providesIReactorProcess   s     	J66ErN   c                    | j                  | j                  j                         t               }dD ]  }| j                  j	                  |t
        j                  t
        j                  g       | j                  |j                         | j                  | j                  |g|z         | j                  | j                  j                  |        y)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@      )rf   N)assertFalser   rc   r"   rm   sysre   
assertTrue	transportassertEqualr_   )rI   protocounts      rL   test_spawnProcessz&CountingReactorTests.test_spawnProcess   s     	001
 	=ELL%%eS^^3>>BR%SOOEOO,T\\E7U?;T\\44e<		=rN   c                     | j                  | j                  j                         dD ]B  }| j                  j                          | j	                  | j                  j                  |       D y)zB
        Stopping the reactor increments its C{stopCount}
        r   N)r   r   rs   rq   r   )rI   r   s     rL   	test_stopzCountingReactorTests.test_stop   sU     	//0 	<ELLT\\33U;	<rN   c                    | j                  | j                  j                         g }| j                  j                  |j                  d       dD ]  }| j                  j                          | j                  | j                  j                  |       | j                  | j                  j                  d       | j                  t        |      |        y)z
        Running the reactor increments its C{runCount}, does not imply
        C{stop}, and calls L{IReactorCore.callWhenRunning} hooks.
        Nr   r   )	r   r   rv   callWhenRunningra   r|   r   rs   len)rI   whenRunningCallsr   s      rL   test_runzCountingReactorTests.test_run   s    
 	../$$%5%<%<dC 	;ELLT\\22E:T\\33Q7S!12E:		;rN   N)	rR   rS   rT   rU   r   r   r   r   r   rH   rN   rL   r~   r~      s!    5F=<;rN   r~   c            	           e Zd ZdZd Zd Zd Zd Zd Zd Z	 e
 e        edd	e dg            d
ededdfd       Zy)WorkerPoolTestsz"
    Tests for L{WorkerPool}.
    c                     t        | j                               | _        | j                  j                  d      | _        t        d| j                  g d      | _        t        | j                        | _        y )N_trial_temp   out.log)
numWorkersworkingDirectoryworkerArgumentslogFile)	r&   mktempparentchildr   r,   configr+   poolrt   s    rL   r   zWorkerPoolTests.setUp   s[    t{{}- $ 1 1- @&!22	
 t{{+	rN   c                    t        d      D cg c]  }t                }}| j                  j                  |t	        d      t                     }|D ]  }| j                  |t                | j                  dt        |             yc c}w )zw
        C{_createLocalWorkers} iterates the list of protocols and create one
        L{LocalWorker} for each.
        r   rh   N)
rangeobjectr   _createLocalWorkersr&   r   assertIsInstancer2   r   r   )rI   x	protocolsr_   ss        rL   test_createLocalWorkersz'WorkerPoolTests.test_createLocalWorkers   st    
 (-Qx0!VX0	0))//	8F;KXZX 	2A!!![1	2CL)	 1s   Bc                    t        d      D cg c]  }t                }}g i di dddddffd	}| j                  j                  ||dg       | j	                  d   d          | j                  t        j                  j                  d                | j	                  dd	          | j	                  t        j                  j                  t        j                        d
          yc c}w )z
        Given a C{spawnProcess} function, C{_launchWorkerProcess} launches a
        python process with an existing path as its argument.
        r   rH   Nr   c	                 l    	j                  |       	j                  |       
j                  |       y r\   )ra   extendupdate)processProtocolre   rf   rg   rh   ri   rj   rk   rl   	argumentsenvironments            rL   fakeSpawnProcesszDWorkerPoolTests.test_launchWorkerProcesses.<locals>.fakeSpawnProcess   s/     Z(T"s#rN   foor@   r   r=   
PYTHONPATH)r   r!   r   _launchWorkerProcessesr   r   osrh   existspathsepjoinr   )rI   ir   r   r   r   s       @@rL   test_launchWorkerProcessesz*WorkerPoolTests.test_launchWorkerProcesses   s    
 16a91_&9	9	
 	$ 			(()99ugN1y|4y|45	!- 	2K4MN5 :s   C2c                 D   | j                   j                          g | j                  j                  t	        g             }| j                  |      }|j                  fd      }| j                  |       t        t        | j                  j                               y)zY
        C{run} dispatches the given action to each of its workers exactly once.
        c                 8    t        j                  |             S r\   )r   ra   )wr_   s    rL   <lambda>z*WorkerPoolTests.test_run.<locals>.<lambda>  s    q0A(B rN   N)r   makedirsr   startrZ   successResultOfr|   r   r   r   r   )rI   startingstartedrw   r_   s       @rL   r   zWorkerPoolTests.test_run  sw     	99???2#67&&x0++BCW%GZ(>(>?@rN   c                    | j                   j                          t        | j                  j                  dz         }| j                  |j                                | j                  |j                         t        g       }| j                  | j                  j                  |            }| j                  |j                  | j                  j                  d             y)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   rh   r   lock
addCleanupunlockrZ   r   r   r   r   sibling)rI   r   fakeReactorr   s       rL   test_runUsedDirectoryz%WorkerPoolTests.test_runUsedDirectory  s     	 d33887BC		$$ &b)&&tyy{'CD 	$$!!))/:	
rN   c           	      6   | j                   j                          t        g       }| j                  | j                  j                  |            }t        j                  |j                               }| j                  |       |j                  D ]  }t        |j                  j                  t        t                     |j                  j                  D ]  }|j!                  |        |j"                  |j$                  fD ]  } |t'        t)        d                     t        | j                  |      t+                      t        |j,                  j.                  t1        d             t        |j2                  j4                  t1        d             y)z
        L{StartedWorkerPool.join} causes all of the workers to exit, closes the
        log file, and unlocks the test directory.
        r   TFN)r   r   rZ   r   r   r   r   fromCoroutiner   assertNoResultr^   r   r   rF   r   r(   childConnectionLostprocessExitedprocessEndedr%   r    r   testLogclosedr   testDirLocklocked)rI   r   r   joiningr   rJ   rz   s          rL   	test_joinzWorkerPoolTests.test_join3  s-   
 	!"%&&tyyw'?@((8G$!! 	+A++X6G-HIkk)) *%%b)*ooq~~6 +'+a.)*+		+ 	D((146:GOO**HTN;G''..@rN   r   subdirabsoluter   returnNc                    |r | j                   j                  t        z   |z   }t        | j                  |      }|rt        |      }n9t        t        |j                  j                        t        t        |z               }t        |      }| j                  |j                  t        g                   }t        |j                  j                   |       y)z
        L{WorkerPool.start} creates a L{StartedWorkerPool} configured with a
        log file based on the L{WorkerPoolConfig.logFile}.
        )r   N)r   rh   r   r   r   r   r   r   r   r   r+   r   r   rZ   r   r   name)rI   r   r   r   matchesr   r   s          rL   test_logFilezWorkerPoolTests.test_logFileH  s     kk&&,w6Gt{{G4w'G F33889#-(G &!&&tzz/"2E'FGGOO(('2rN   )rR   rS   rT   rU   r   r   r   r   r   r   r   r   r   r   boolstrr   rH   rN   rL   r   r      sx    	,	*OBA
0A* 
W%	
3T 3C 3D 33rN   r   c                       e Zd ZdZ e ej                  d      g      Zd Zd Z	d Z
ddZd Zd	 Zdd
ZddZddZddZd Zd ZddZddZddZd Zy)DistTrialRunnerTestsz'
    Tests for L{DistTrialRunner}.
    test_fooc                     t        t        | j                         t               dg t	        t
        d      t        g             }|j                  |       t        di |S )z.
        Create a runner for testing.
        r   T)autostop)reporterFactoryr   stream
maxWorkersr   workerPoolFactoryr   rH   )	dictr8   r   r   r   LocalWorkerPoolrZ   r   r*   )rI   	overridesrf   s      rL   	getRunnerzDistTrialRunnerTests.getRunnerr  sS     (![[]:%oE#B'
 	I&&&rN   c                     t               }t        t        |            }| j                         }|j	                  |       | j                  |j                         dkD         y)ze
        L{DistTrialRunner.writeResults} writes to the stream specified in the
        init.
        r   N)r   r)   r6   r   writeResultsr   tell)rI   stringIOresultrunners       rL   test_writeResultsz&DistTrialRunnerTests.test_writeResults  sK    
 :hx01!F#!+,rN   c                 8   dfd}d}d}| j                  ||      }t        t        |      D cg c]  }t                c}      }| j	                  |j                  |             t        j                  d   j                  t        |             yc c}w )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kwr   s     rL   recordingFactoryzADistTrialRunnerTests.test_minimalWorker.<locals>.recordingFactory  s    "A;;;DKrN      r=   )r   r   r   )
r   r;   r   r	   r   runAsyncr   _startedr_   r   )rI   r   r   numTestsr   nsuiter   s          @rL   test_minimalWorkerz'DistTrialRunnerTests.test_minimalWorker  s    
 	
 
!5E   
 h@1HJ@AV__U34DMM!$,,j.BC As   BNc                     | j                  d      }|j                  | j                        }| j                  |      }| j	                  |t
               | j	                  |j                  t               y)z
        Running with the C{unclean-warnings} option makes L{DistTrialRunner} uses
        the L{UncleanWarningsReporterWrapper}.
        T)uncleanWarningsN)r   r  r  r   r   r)   originalr9   )rI   r   dr   s       rL   test_runUncleanWarningsz,DistTrialRunnerTests.test_runUncleanWarnings  s[    
 5OODJJ'%%a(fl3foo/MNrN   c                     t               }| j                  |      }| j                  |j                  t	                           }| j                  |t               |j                         }| j                  d|       | j                  d|       y)zA
        L{DistTrialRunner} can run an empty test suite.
        r   Running 0 testPASSEDN)	r   r   r   r  r;   r   r)   getvalueassertIn)rI   r   r   r   outputs        rL   test_runWithoutTestz(DistTrialRunnerTests.test_runWithoutTest  so     v.%%foojl&CDfl3"&/h'rN   c                    t        dt        t        d                  }t               }| j	                  |      }| j                  |j                  |            }| j                  |t               |j                         }| j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       y)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  )rI   errr   r   r   r  s         rL   !test_runWithoutTestButWithAnErrorz6DistTrialRunnerTests.test_runWithoutTestButWithAnError  s     *gl9.E&FGv.%%fooc&:;fl3"&/i(j&)j&)h'rN   c                 ,   | j                  t              }| j                  |j                  | j                              }|j
                  j                  }t        |t        d             t        |d   d   j                  t        t                     y)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rI   r   r   r  s       rL   test_runUnexpectedErrorz,DistTrialRunnerTests.test_runUnexpectedError  sm    
 2BC%%foodjj&AB''FJqM*F1IaL%%x0@'ABrN   c                     | j                  t              }| j                  t              5  |j	                  | j
                         ddd       y# 1 sw Y   yxY w)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   r|   r  )rI   r   s     rL   test_runUnexpectedErrorCtrlCz1DistTrialRunnerTests.test_runUnexpectedErrorCtrlC  sG    
 /B~. 	#JJtzz"	# 	# 	#s   AAc                 L   | j                  t        t        t        d            }| j	                  |j                  | j                              }|j                  j                  }t        |t        d             t        |d   d   j                  t        t                     y)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   s       rL   test_runUnexpectedWorkerErrorz2DistTrialRunnerTests.test_runUnexpectedWorkerError  s    
 %/AD   

 %%foodjj&AB''FJqM*F1IaL%%x'=>rN   c                    dfd}| j                  |      }t        j                  |j                  | j                              }| j                  d       J j                  d   j                  }| j                  |       |j                  d       | j                  |      }| j                  |t               y)zG
        L{DistTrialRunner} waits for the worker pool to stop.
        Nc                  "    t        | ddi|S )Nr   Fr   r   s     rL   r   zPDistTrialRunnerTests.test_runWaitForProcessesDeferreds.<locals>.recordingFactory  s    "A<<<DKrN   r  zworker pool was never createdr   )r   r   r   r  r  failr  _stoppedr   callbackr   r   r)   )rI   r   r   r  stoppedr   r   s         @rL   !test_runWaitForProcessesDeferredsz6DistTrialRunnerTests.test_runWaitForProcessesDeferreds  s     	
 .   
 ""6??4::#>?<II56--"++A%%a(fl3rN   c           	      f   t               }t        t        j                  d      t	        j
                  d      t        j                  d      g      }| j                  |dd      }|j                  |      }| j                  |      }t        |j                  t        dt        d                   y	)
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   )rI   r   r  r   r  r   s         rL   test_exitFirstz#DistTrialRunnerTests.test_exitFirst	  s    
 z*))+6z*
 v!LOOE"%%a(OO#A	
rN   c                 j   t               }t        j                  d      }| j                  |      }|j	                  |d      }| j                  |      }| j                  d|j                         | j                  |j                                |j                         }| j                  |j                  d      |j                  dz
  d       | j                  d	|       t        dd
      D ]  }| j                  d| |        | j                  |j                  d      |j                  d       y)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   )rI   r   caser   r  r   r  r   s           rL   test_runUntilFailurez)DistTrialRunnerTests.test_runUntilFailure"  s   
 229=v.OODtO4%%a(DFF#--/0" 	LL"FFQJ.	
 	ff% q! 	4AMMJqc*F3	4 	LL)*FF@	
rN   c                     | j                         }|j                  | j                        }t        |j	                         t        d             t        |j                  t        d             y)zw
        L{DistTrialRunner.run} returns a L{DistReporter} containing the result of
        the test suite run.
        Tr@   N)r   r|   r  r   rA  r   r5  )rI   r   r   s      rL   r   zDistTrialRunnerTests.test_runE  sM    
 !DJJ'F((*HTN;F$$hqk2rN   c                 0   t        g       }t        |      5  | j                  d      }ddd       j                  | j                        }t        |j                  t        g              t        |j                  t        g              t        |j                         t        d             t        |j                  t        d             t        |j                  t        d             t        |j                  t        d             y# 1 sw Y   xY w)z
        L{DistTrialRunner.run} uses the installed reactor L{DistTrialRunner} was
        constructed without a reactor.
        Nr   Tr@   )rZ   r#   r   r|   r  r   r  r   r6  rA  r5  rv   rs   )rI   r   r   r   s       rL   test_installedReactorz*DistTrialRunnerTests.test_installedReactorO  s    
 ""%g& 	2^^D^1F	2DJJ'FMM8B<0FOOXb\2F((*HTN;F$$hqk2G$$hqk2G%%x{3	2 	2s   DDc                     G d dt               }t        t        j                         G d d             } G d d      }t	         |             5  | j                  t              5  | j                  d       ddd       ddd       t	         |             5  | j                  t              5  | j                  d       ddd       ddd       t	         |             5  | j                  t              5  | j                  d       ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   sxY w# 1 sw Y   wxY w# 1 sw Y   BxY w# 1 sw Y   yxY w)	z
        L{DistTrialRunner} raises L{TypeError} if the installed reactor provides
        neither L{IReactorCore} nor L{IReactorProcess} and no other reactor is
        given.
        c                       e Zd Zd Zy)=DistTrialRunnerTests.test_wrongInstalledReactor.<locals>.Corec                      y r\   rH   rt   s    rL   installWakerzJDistTrialRunnerTests.test_wrongInstalledReactor.<locals>.Core.installWakerg  s    rN   N)rR   rS   rT   rL  rH   rN   rL   CorerJ  f  s    rN   rM  c                        e Zd Z	 	 	 	 	 	 ddZy)@DistTrialRunnerTests.test_wrongInstalledReactor.<locals>.ProcessNc
                      y r\   rH   )
rI   r   re   rf   rg   rh   ri   rj   rk   rl   s
             rL   rm   zMDistTrialRunnerTests.test_wrongInstalledReactor.<locals>.Process.spawnProcessl  s     rN   )NNNNFN)rR   rS   rT   rm   rH   rN   rL   ProcessrO  j  s     rN   rQ  c                       e Zd Zy)@DistTrialRunnerTests.test_wrongInstalledReactor.<locals>.NeitherNrR   rS   rT   rH   rN   rL   NeitherrS  z      rN   rU  NrF  )r   r
   r   r   r#   r#  	TypeErrorr   )rI   rM  rQ  rU  s       rL   test_wrongInstalledReactorz/DistTrialRunnerTests.test_wrongInstalledReactor_  s7   	; 	 
Z//	0	 	 
1		 	 gi( 	-""9- -t,-	-
 df% 	-""9- -t,-	-
 gi( 	-""9- -t,-	- 	-- -	- 	-- -	- 	-- -	- 	-sl   D(&D9D(E /D4E "E8EED%	!D((D14D=	9E  E	E	EE!c                      G d dt               fd}| j                  |      }| j                        5  |j                  | j                         ddd       y# 1 sw Y   yxY w)z
        If there is an unexpected exception running the test suite then it is
        re-raised by L{DistTrialRunner.run}.
        c                       e Zd Zy);DistTrialRunnerTests.test_runFailure.<locals>.BrokenFactoryNrT  rH   rN   rL   BrokenFactoryr[    rV  rN   r\  c                              r\   rH   )rf   r{   r\  s     rL   brokenFactoryz;DistTrialRunnerTests.test_runFailure.<locals>.brokenFactory  s    /!rN   r  N)	Exceptionr   r#  r|   r  )rI   r^  r   r\  s      @rL   test_runFailurez$DistTrialRunnerTests.test_runFailure  sY    	I 		" -@}- 	#JJtzz"	# 	# 	#s   AA'r   N)rR   rS   rT   rU   r;   r?   r7  r  r   r   r  r  r  r  r!  r$  r)  r0  r9  rC  r   rG  rX  r`  rH   rN   rL   r   r   k  sv     z234E' 	-D,	O
((&	C#?42
2!
F34 +-Z#rN   r   c                   8    e Zd ZdZddZddZddZddZddZy)	FunctionalTestsz8
    Tests for the functional helpers that need it.
    Nc                     t        t        dd      t        d             t        t        dd      t        d             y)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   rt   s    rL   test_fromOptionalz!FunctionalTests.test_fromOptional  s.     	LD)8A;7LA&4rN   c                     t               }t        |      }| j                  |       |j                  d       t	        | j                  |      t                      y)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   )rI   r   r  s      rL   test_discardResultz"FunctionalTests.test_discardResult  sF    
 $:!A	

8D((+TV4rN   c                    t               }t               }t        j                  t        ||            }|j                  d       | j	                  |       |j                  d       t        | j                  |      t        d             y)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   )rI   r   bcs       rL   test_sequencezFunctionalTests.test_sequence  sf     $:#:""8Aq>2	

2A	

7D((+Xb\:rN   c                    t               t               t               g}d }t        j                  t        |t        |      j                              }|j	                         j                  d       | j                  |       |j	                         j                  d       t        | j                  |      t        d             y)z
        ``iterateWhile`` executes the actions from its factory until the predicate
        does not match an action result.
        c                     | dk7  S )Nri  rH   )values    rL   	predicatez4FunctionalTests.test_iterateWhile.<locals>.predicate  s    B;rN   r  ri  N)
r   r   r0   listpopr.  r   r   r   r   )rI   actionsrq  r  s       rL   test_iterateWhilez!FunctionalTests.test_iterateWhile  s    
 )1
HJ
'K	 $11DM$5$56
 	q! 	A 	r"D((+Xb\:rN   c                     t         dt        dt        fd       }t        dd      D ]  }t         |       t	        |              y)z
        ``countingCalls`` decorates a function so that it is called with an
        increasing counter and passes the return value through.
        r  r   c                     | dz   S )Nr@   rH   )r  s    rL   targetz2FunctionalTests.test_countingCalls.<locals>.target  s    q5LrN   r@   
   N)r-   rW   r   r   r   )rI   rx  expecteds      rL   test_countingCallsz"FunctionalTests.test_countingCalls  sL     
	c 	c 	 
	 a 	6H(8"45	6rN   ra  )	rR   rS   rT   rU   re  rg  rm  ru  r{  rH   rN   rL   rc  rc    s     5	5;;26rN   rc  c                       e Zd ZdZy)r  zx
    An exception for ``StartedWorkerPoolBroken`` to fail with to allow tests
    to exercise exception code paths.
    NrR   rS   rT   rU   rH   rN   rL   r  r    s    rN   r  c                   .    e Zd ZdZded   ddfdZddZy)StartedWorkerPoolBrokenzn
    A broken, started worker pool.  Its workers cannot run actions.  They
    always raise an exception.
    workerActionNr   c                    K   t               wr\   )r  )rI   r  s     rL   r|   zStartedWorkerPoolBroken.run  s          c                    K   y wr\   rH   rt   s    rL   r   zStartedWorkerPoolBroken.join  s	     s   ra  )rR   rS   rT   rU   r5   r|   r   rH   rN   rL   r  r    s$    
!l4&8 !T !rN   r  c                   @    e Zd ZU dZeed<   dej                  defdZ	y)r  zF
    A worker pool that has workers with a broken ``run`` method.
    _configr   r   c                    K   t               S wr\   )r  )rI   r   s     rL   r   zBrokenWorkerPool.start	  s      '((r  N)
rR   rS   rT   rU   r,   rX   r   r   r  r   rH   rN   rL   r  r    s*     )!11)	 )rN   r  c                   $    e Zd ZdZdededefdZy)_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..
    rB  r   r   c                 H   K   t        |g      j                  |       ddiS w)z8
        Directly run C{case} in the usual way.
        successT)r;   r|   rI   rB  r   s      rL   r|   z_LocalWorker.run  s(      	D6v&4  s    "N)rR   rS   rT   rU   PyUnitTestCaser7   r3   r|   rH   rN   rL   r  r    s!    !n !j !Y !rN   r  c                       e Zd ZdZy)r(  zE
    A worker tried to run a test case but the worker is broken.
    Nr}  rH   rN   rL   r(  r(     s    rN   r(  c                   $    e Zd ZdZdededdfdZy)r'  z:
    A L{Worker} that always fails to run test cases.
    rB  r   r   Nc                    K   t               w)z@
        Raise an exception instead of running C{case}.
        )r(  r  s      rL   r|   z_BrokenLocalWorker.run+  s      nr  )rR   rS   rT   rU   r  r7   r|   rH   rN   rL   r'  r'  &  s!    n j T rN   r'  c                   ^    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Zd	 Zy)
StartedLocalWorkerPoolz'
    A started L{LocalWorkerPool}.
    r   r_   Nr-  r  r   c                 R   K   | j                   D ]  } ||       d{     y7 w)z8
        Run the action with each local worker.
        N)r_   )rI   r  workers      rL   r|   zStartedLocalWorkerPool.run<  s,      ll 	'Fv&&&	'&s   '%'c                 8   K   | j                    d {    y 7 wr\   )r-  rt   s    rL   r   zStartedLocalWorkerPool.joinC  s     mms   )rR   rS   rT   rU   r&   r   rX   r   r4   r   r5   r|   r   rH   rN   rL   r  r  2  sD     sm#&\tn'l4&8 'T 'rN   r  c                       e Zd ZU dZeed<    e ee            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
Zy)r   z_
    Implement a worker pool that runs tests in-process instead of in child
    processes.
    r  rD   r  F	_autostop_workerFactoryr   r   c                 B  K   t        | j                  j                        D cg c]  }| j                          }}t	        | j                  j
                  || j                  rt        d       n	t                     }| j                  j                  |       |S c c}w wr\   )r   r  r   r  r  r   r  r   r   r  ra   )rI   r   r   r_   r   s        rL   r   zLocalWorkerPool.startS  s}      388O8O2PQQ4&&(QQ(LL))"nnWT](*

 	W% Rs   "BBA$BN)rR   rS   rT   rU   r,   rX   r   r   rr  r  r   r  r  r   r  r  r   r4   r   r   r   rH   rN   rL   r   r   G  s`    
 -274=-IHd)*IIt+7NHRZ(7
!11
	
rN   r   )prU   r   r   	functoolsr   ior   os.pathr   typingr   r   r   unittestr	   r  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   rC   r   rZ   r~   r   r   rc  r_  r  r  r  r  r(  r'  r  r   rH   rN   rL   <module>r     s   
 
    & & / . / /   +  8 ' - D D . ? @ 7 * , 2 1 9 W W  T S  9 @ % $   & Z''(?( ? )?D5;. 5;pX3h X3vq#8 q#h	K6h K6\y 
 
 
) 
) 
)! !"9 	 	   (   rN   