HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/trial/_dist/__pycache__/disttrial.cpython-38.pyc
U


W["�@s�dZddlZddlZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZdd	lmZmZdd
lmZddlmZddlmZmZGd
d�de�ZdS)z�
This module contains the trial distributed runner, the management class
responsible for coordinating all of trial's behavior at the highest level.

@since: 12.3
�N)�FilePath)�
theSystemPath)�DeferredList��	cooperate)�_unusedTestDirectory)�
_iterateTests)�LocalWorker�LocalWorkerAMP)�DistReporter)�UncleanWarningsReporterWrapper)�_WORKER_AMP_STDIN�_WORKER_AMP_STDOUTc@s^eZdZdZeZdd�Zdd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdedfdd�Z
dd�ZdS)�DistTrialRunneraY
    A specialized runner for distributed trial. The runner launches a number of
    local worker processes which will run tests.

    @ivar _workerNumber: the number of workers to be spawned.
    @type _workerNumber: C{int}

    @ivar _stream: stream which the reporter will use.

    @ivar _reporterFactory: the reporter class to be used.
    cCs.|j|j|j|jd�}|jr$t|�}|�|�S)zL
        Make reporter factory, and wrap it with a L{DistReporter}.
        )Zrealtime)�_reporterFactory�_stream�	_tbformat�	_rterrors�_uncleanWarningsr�_distReporterFactory)�selfZreporter�r�?/usr/lib/python3/dist-packages/twisted/trial/_dist/disttrial.py�_makeResult+s�zDistTrialRunner._makeResultN�defaultF�test.log�_trial_tempc

Cs`||_||_||_|dkr tj}||_||_||_||_d|_	|	|_
||_d|_d|_
d|_dS)NF)�
_workerNumber�_workerArgumentsr�sys�stdoutrrrrZ_result�_workingDirectory�_logFileZ_logFileObserverZ_logFileObjectZ_logWarnings)
rZreporterFactory�workerNumberZworkerArguments�streamZtracebackFormatZrealTimeErrorsZuncleanWarningsZlogfile�workingDirectoryrrr�__init__6szDistTrialRunner.__init__cCs|��dS)z�
        Write test run final outcome to result.

        @param result: A C{TestResult} which will print errors and the summary.
        N)Zdone)r�resultrrr�writeResultsNszDistTrialRunner.writeResultscs��fdd�t|�D�S)aY
        Create local worker protocol instances and return them.

        @param protocols: An iterable of L{LocalWorkerAMP} instances.

        @param workingDirectory: The base path in which we should run the
            workers.
        @type workingDirectory: C{str}

        @return: A list of C{quantity} C{LocalWorker} instances.
        c	s,g|]$\}}t|tj��t|���j��qSr)r	�os�path�join�strr")�.0�xZprotocol�rr%rr�
<listcomp>cs
��z6DistTrialRunner.createLocalWorkers.<locals>.<listcomp>)�	enumerate)r�	protocolsr%rr/r�createLocalWorkersWs�z"DistTrialRunner.createLocalWorkersc	
Csvtdjj}ddddddtdtdi}tj��}tj�	t
j�|d<|D],}t
j|g}|�|�||t
j|||d�qDd	S)
a
        Spawn processes from a list of process protocols.

        @param spawner: A C{IReactorProcess.spawnProcess} implementation.

        @param protocols: An iterable of C{ProcessProtocol} instances.

        @param arguments: Extra arguments passed to the processes.
        ztwisted.trial._dist.workertrialr�w��r�ZTRIAL_PYTHONPATH)�args�childFDs�envN)
rZfilePathr*r
rr)�environ�copy�pathsepr+r�
executable�extend)	rZspawnerr2Z	argumentsZworkertrialPathr9r;�workerr8rrr�launchWorkerProcessesis
��


�z%DistTrialRunner.launchWorkerProcessescs6�fdd�����fdd��|�fdd�|D����S)a�
        Drive a L{LocalWorkerAMP} instance, iterating the tests and calling
        C{run} for every one of them.

        @param worker: The L{LocalWorkerAMP} to drive.

        @param result: The global L{DistReporter} instance.

        @param testCases: The global list of tests to iterate.

        @param cooperate: The cooperate function to use, to be customized in
            tests.
        @type cooperate: C{function}

        @return: A C{Deferred} firing when all the tests are finished.
        cs�j�||�|S�N)�originalZ
addFailure)�error�case)r'rr�
resultErrback�sz3DistTrialRunner._driveWorker.<locals>.resultErrbackcs��|��}|��|�|SrB)�runZ
addErrback)rE�d)r'rFr@rr�task�sz*DistTrialRunner._driveWorker.<locals>.taskc3s|]}�|�VqdSrBr)r-rE)rIrr�	<genexpr>�sz/DistTrialRunner._driveWorker.<locals>.<genexpr>)ZwhenDone)rr@r'�	testCasesrr)r'rFrIr@r�_driveWorker�szDistTrialRunner._driveWorkercs@�dkrddlm������
��}�j�d|f�|sT�
��j������St	t
�j��\}�t|�j
�}dd�t|�D�����|j�}dd�|D�����j|�j������
fdd	��g�	�����fd
d����	�fdd
�}	���	fdd�}
��fdd����}|���|�|	���dd|
�����S)a{
        Spawn local worker processes and load tests. After that, run them.

        @param suite: A tests suite to be run.

        @param reactor: The reactor to use, to be customized in tests.
        @type reactor: A provider of
            L{twisted.internet.interfaces.IReactorProcess}

        @param cooperate: The cooperate function to use, to be customized in
            tests.
        @type cooperate: C{function}

        @param untilFailure: If C{True}, continue to run the tests until they
            fail.
        @type untilFailure: C{bool}.

        @return: The test result.
        @rtype: L{DistReporter}
        Nr)�reactorzRunning %d tests.
cSsg|]
}t��qSr)r
)r-r.rrrr0�sz'DistTrialRunner.run.<locals>.<listcomp>cSsg|]
}|j�qSr)ZendDeferred)r-r@rrrr0�sc	sDttt����}g}�D]}|��j|�|�d��qt|ddd�S)NrT)�
consumeErrorsZfireOnOneErrback)�iter�listr�appendrLr)rKZworkerDeferredsr@)�
ampWorkersrr'r�suiterr�runTests�s
���z%DistTrialRunner.run.<locals>.runTestscs.�����sdS���sdS��}|���SrB)r(Z
wasSuccessful�addCallback)�ignrH)�nextRunr'rTr�untilFailurerrrW�s
z$DistTrialRunner.run.<locals>.nextRuncs"����s��d����dSrB)ZunlockrQ�stop�rV)rM�stopping�testDirLockrrrY�s
z!DistTrialRunner.run.<locals>.stopcs(�s$��d�t�dd�}|���SdS)NT)rN)rQrrU)rH)�continueShutdown�processEndDeferredsr[rr�beforeShutDown�s
z+DistTrialRunner.run.<locals>.beforeShutDowncs����|SrB)r(rZ)r'rrrr]�s
z-DistTrialRunner.run.<locals>.continueShutdownZbeforeZshutdown)Ztwisted.internetrMrZcountTestCasesr�writerGrCr(rrr!�minr�ranger3r*rAZspawnProcessrrUZaddBothZaddSystemEventTrigger)rrSrMrrX�countZtestDirr#ZworkersrYr_rHr)
rRr]rrWr^rMr'rTrr[rSr\rXrrG�s>
�
�	

zDistTrialRunner.runcCs|j|dd�S)z|
        Run the tests with local worker processes until they fail.

        @param suite: A tests suite to be run.
        T)rX)rG)rrSrrr�runUntilFailure�szDistTrialRunner.runUntilFailure)NrFFrr)�__name__�
__module__�__qualname__�__doc__rrrr&r(r3rArLrrGrdrrrrrs$�
	�
[r)rhr)rZtwisted.python.filepathrZtwisted.python.modulesrZtwisted.internet.deferrZtwisted.internet.taskrZtwisted.trial.utilrZtwisted.trial._asyncrunnerrZtwisted.trial._dist.workerr	r
Z twisted.trial._dist.distreporterrZtwisted.trial.reporterrZtwisted.trial._distr
r�objectrrrrr�<module>s