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: //lib/python3/dist-packages/twisted/trial/_dist/__pycache__/worker.cpython-38.pyc
U


W[�#�@sdZddlZddlmZddlmZddlmZmZddl	m
Z
ddlmZddl
mZdd	lmZdd
lmZddlmZmZddlmZmZdd
lmZmZddlmZGdd�de�ZGdd�de�Zee�Gdd�de��Z ee�Gdd�de��Z!Gdd�de�Z"dS)z:
This module implements the worker classes.

@since: 12.3
�N)�implementer)�ProcessProtocol)�
ITransport�IAddress)�Deferred)�AMP)�Failure)�namedObject)�Todo)�
TrialSuite�
TestLoader)�workercommands�managercommands)�_WORKER_AMP_STDIN�_WORKER_AMP_STDOUT)�WorkerReporterc@sBeZdZdZd
dd�Zdd�Zej�e�dd�Z	ej
�e	�d	S)�WorkerProtocolz5
    The worker-side trial distributed protocol.
    FcCst�|_t|�|_||_dS�N)r�_loaderr�_result�_forceGarbageCollection)�selfZforceGarbageCollection�r�</usr/lib/python3/dist-packages/twisted/trial/_dist/worker.py�__init__#s
zWorkerProtocol.__init__cCs.|j�|�}t|g|j�}|�|j�ddiS)z*
        Run a test case by name.
        �successT)rZ
loadByNamerr�runr)r�testCaseZcaseZsuiterrrr)szWorkerProtocol.runcCst�|�ddiS)zb
        Set up the worker, moving into given directory for tests to run in
        them.
        rT)�os�chdir)r�	directoryrrr�start5s
zWorkerProtocol.startN)F)�__name__�
__module__�__qualname__�__doc__rrr
�Run�	responderr!�Startrrrrrs
	rc@s�eZdZdZdd�Zej�e�dd�Zdd�Z	ej
�e	�dd	�Zej�e�d
d�Z
ej�e
�dd
�Zej�e�dd�Zej�e�dd�Zej�e�dd�Zdd�Zdd�ZdS)�LocalWorkerAMPz7
    Local implementation of the manager commands.
    cCs|j�|j�ddiS)z0
        Add a success to the reporter.
        rT)r�
addSuccess�	_testCase)r�testNamerrrr*FszLocalWorkerAMP.addSuccessc	CsZt|�}t||�}tdt|�d�D]2}|j�||||dt||d�ggf�q"|S)a�
        Helper to build a C{Failure} with some traceback.

        @param error: An C{Exception} instance.

        @param error: The class name of the C{error} class.

        @param frames: A flat list of strings representing the information need
            to approximatively rebuild C{Failure} frames.

        @return: A L{Failure} instance with enough information about a test
           error.
        r���)r	r�range�len�frames�append�int)r�error�
errorClassr2Z	errorType�failure�irrr�
_buildFailurePs
$�zLocalWorkerAMP._buildFailurecCs&|�|||�}|j�|j|�ddiS)z/
        Add an error to the reporter.
        rT)r9r�addErrorr+)rr,r5r6r2r7rrrr:fszLocalWorkerAMP.addErrorcCs&|�|||�}|j�|j|�ddiS)z0
        Add a failure to the reporter.
        rT)r9r�
addFailurer+)rr,ZfailZ	failClassr2r7rrrr;qszLocalWorkerAMP.addFailurecCs|j�|j|�ddiS)z-
        Add a skip to the reporter.
        rT)r�addSkipr+)rr,�reasonrrrr<|szLocalWorkerAMP.addSkipcCs"t|�}|j�|j||�ddiS)z:
        Add an expected failure to the reporter.
        rT)r
r�addExpectedFailurer+)rr,r5�todoZ_todorrrr>�sz!LocalWorkerAMP.addExpectedFailurecCs|j�|j|�ddiS)z<
        Add an unexpected success to the reporter.
        rT)r�addUnexpectedSuccessr+)rr,r?rrrr@�sz#LocalWorkerAMP.addUnexpectedSuccesscCs"|j�|d�|j��ddiS)z4
        Print test output from the worker.
        �
rT)�_testStream�write�flush)r�outrrr�	testWrite�s
zLocalWorkerAMP.testWritecCs|j�|j�|S)zL
        Stop the current running test case, forwarding the result.
        )rZstopTestr+)r�resultrrr�	_stopTest�szLocalWorkerAMP._stopTestcCs<||_||_|j�|�|��}|jtj|d�}|�|j�S)z
        Run a test.
        )r)	r+rZ	startTest�id�
callRemoter
r&ZaddCallbackrH)rrrGZ
testCaseId�drrrr�szLocalWorkerAMP.runcCs
||_dS)z?
        Set the stream used to log output from tests.
        N)rB)r�streamrrr�
setTestStream�szLocalWorkerAMP.setTestStreamN)r"r#r$r%r*rZ
AddSuccessr'r9r:ZAddErrorr;Z
AddFailurer<ZAddSkipr>ZAddExpectedFailurer@ZAddUnexpectedSuccessrFZ	TestWriterHrrMrrrrr)As&r)c@seZdZdZdS)�LocalWorkerAddressz
    A L{IAddress} implementation meant to provide stub addresses for
    L{ITransport.getPeer} and L{ITransport.getHost}.
    N)r"r#r$r%rrrrrN�srNc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�LocalWorkerTransportzi
    A stub transport implementation used to support L{AMP} over a
    L{ProcessProtocol} transport.
    cCs
||_dSr)�
_transport)r�	transportrrrr�szLocalWorkerTransport.__init__cCs|j�t|�dS)z,
        Forward data to transport.
        N�rPZwriteToChildr�r�datarrrrC�szLocalWorkerTransport.writecCs|D]}|j�t|�qdS)zP
        Emulate C{writeSequence} by iterating data in the C{sequence}.
        NrR)rZsequencerTrrr�
writeSequence�sz"LocalWorkerTransport.writeSequencecCs|j��dS)z'
        Closes the transport.
        N)rP�loseConnection�rrrrrV�sz#LocalWorkerTransport.loseConnectioncCst�S�z:
        Return a L{LocalWorkerAddress} instance.
        �rNrWrrr�getHost�szLocalWorkerTransport.getHostcCst�SrXrYrWrrr�getPeer�szLocalWorkerTransport.getPeerN)
r"r#r$r%rrCrUrVrZr[rrrrrO�srOc@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�LocalWorkeraX
    Local process worker protocol. This worker runs as a local process and
    communicates via stdin/out.

    @ivar _ampProtocol: The L{AMP} protocol instance used to communicate with
        the worker.

    @ivar _logDirectory: The directory where logs will reside.

    @ivar _logFile: The name of the main log file for tests output.
    cCs||_||_||_t�|_dSr)�_ampProtocol�
_logDirectory�_logFiler�endDeferred)rZampProtocol�logDirectoryZlogFilerrrrszLocalWorker.__init__cCs�|j�t|j��tj�|j�s,t�|j�t	tj�
|jd�d�|_t	tj�
|jd�d�|_t	tj�
|j|j
�d�|_|j�|j�|j}|jjtj|d�}|�dd��dS)	zL
        When connection is made, create the AMP protocol instance.
        zout.log�wbzerr.log�w)r cSsdSrr)�xrrr�<lambda> �z,LocalWorker.connectionMade.<locals>.<lambda>N)r]ZmakeConnectionrOrQr�path�existsr^�makedirs�open�join�_outLog�_errLogr_�_testLogrMrJr
r(Z
addErrback)rrarKrrr�connectionMades�
�zLocalWorker.connectionMadecCs"|j��|j��|j��dS)zk
        On connection lost, close the log files that we're managing for stdin
        and stdout.
        N)rl�closermrn�rr=rrr�connectionLost#s

zLocalWorker.connectionLostcCs&|�|�|j�|�|j�|�dS)z�
        When the process closes, call C{connectionLost} for cleanup purposes
        and forward the information to the C{_ampProtocol}.
        N)rrr]r`�callbackrqrrr�processEnded-s
zLocalWorker.processEndedcCs|j�|�dS)z8
        Send data received from stdout to log.
        N)rlrCrSrrr�outReceived7szLocalWorker.outReceivedcCs|j�|�dS)z*
        Write error data to log.
        N)rmrCrSrrr�errReceived?szLocalWorker.errReceivedcCs(|tkr|j�|�nt�|||�dS)zT
        Handle data received on the specific pipe for the C{_ampProtocol}.
        N)rr]ZdataReceivedr�childDataReceived)rZchildFDrTrrrrwFszLocalWorker.childDataReceivedN)r"r#r$r%rrorrrtrurvrwrrrrr\�s

r\)#r%rZzope.interfacerZtwisted.internet.protocolrZtwisted.internet.interfacesrrZtwisted.internet.deferrZtwisted.protocols.amprZtwisted.python.failurerZtwisted.python.reflectr	Ztwisted.trial.unittestr
Ztwisted.trial.runnerrrZtwisted.trial._distr
rrrZ"twisted.trial._dist.workerreporterrrr)�objectrNrOr\rrrr�<module>s*#/