%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/twisted/trial/_dist/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/twisted/trial/_dist/__pycache__/worker.cpython-312.pyc

�

Ϫ�fe8��l�dZddlZddlmZmZmZmZmZmZm	Z	m
Z
ddlmZddl
mZddlmZddlmZmZddlmZmZdd	lmZdd
lmZmZddlmZddlmZdd
lm Z ddl!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(m)Z)m*Z*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1m2Z2ddl3m4Z4ddl5m6Z6m7Z7m8Z8ed��Gd�de9��Z:Gd�de�Z;Gd�de�Z<e
d �Z=ee<gee=fZ>Gd!�d"e �Z?Gd#�d$e �Z@ee�Gd%�d&��ZAee�Gd'�d(��ZBGd)�d*e9�ZCGd+�d,e�ZDy)-z:
This module implements the worker classes.

@since: 12.3
�N)�Any�	Awaitable�Callable�Dict�List�Optional�TextIO�TypeVar)�TestCase)�implementer)�frozen)�Protocol�	TypedDict)�Deferred�DeferredList)�ProcessDone)�IAddress�
ITransport)�ProcessProtocol)�Logger)�AMP)�Failure)�FilePath)�namedObject)�_WORKER_AMP_STDIN�_WORKER_AMP_STDOUT�managercommands�workercommands)�WorkerReporter)�
TestResult)�
TestLoader�
TrialSuite)�Todo�)�
StreamOpen�StreamReceiver�StreamWriteF)�auto_excc��eZdZUdZeed<y)�WorkerExceptionz�
    An exception was reported by a test running in a worker process.

    @ivar message: An error message describing the exception.
    �messageN)�__name__�
__module__�__qualname__�__doc__�str�__annotations__���</usr/lib/python3/dist-packages/twisted/trial/_dist/worker.pyr*r*+s����Lr3r*c��eZdZUdZeed<y)�	RunResultzB
    Represent the result of a L{workercommands.Run} command.
    �successN)r,r-r.r/�boolr1r2r3r4r6r66s����Mr3r6c�$�eZdZdZdededefd�Zy)�Workerz)
    An object that can run actions.
    �case�result�returnc��K�y�w)z"
        Run a test case.
        Nr2)�selfr;r<s   r4�runz
Worker.runCs����s�N)r,r-r.r/rr r6r@r2r3r4r:r:>s!����h��
��y�r3r:�_Tc��eZdZdZe�Zdd�Zejjde
defd��Zejjd��Zy)	�WorkerProtocolz5
    The worker-side trial distributed protocol.
    c�P�t�|_t|�|_||_y�N)r!�_loaderr�_result�_forceGarbageCollection)r?�forceGarbageCollections  r4�__init__zWorkerProtocol.__init__Ts��!�|���%�d�+���'=��$r3�testCaser=c��4K�|jj�5}|jj|�}t	|g|j
�}|j
|j�ddd�d}td���d{���D]M\}}|r�	d}|jjd||��	|jj||��d{����Od|iS#1swY�txYw7�d7�#t$r|jjd�Y��wxYw�w)	z*
        Run a test case by name.
        NT)�
consumeErrorsFz Result reporting for {id} failed)�failure�idz5Additionally, reporting the reporting failure failed.r7)rG�gatherReportingResultsrF�
loadByNamer"rHr@r�loggerrN�addErrorFallible�
BaseException)r?rK�resultsr;�suite�allSucceededr7r<s        r4r@zWorkerProtocol.runYs#����
�\�\�
0�
0�
2�	$�g��<�<�*�*�8�4�D���v�t�'C�'C�D�E��I�I�d�l�l�#�	$�
��%1�'��%N�N�	�O�G�V���!�L�
�K�K���2���	
 �
�
��l�l�3�3������'	�@�<�(�(�M	$�	$�� O��&��
!�
����#�#�K��	
�s_�D�AC�+D�C*�-D�4C.�C,�C.�D�C'�#D�,C.�.$D�D�D�Dc�4�tj|�ddiS)zb
        Set up the worker, moving into given directory for tests to run in
        them.
        r7T)�os�chdir)r?�	directorys  r4�startzWorkerProtocol.start�s��	������4� � r3N)F)r,r-r.r/rrRrJr�Run�	responderr0r6r@�Startr\r2r3r4rCrCMsd����X�F�>�
���!�!�*)�#�*)�)�*)�"�*)�X���#�#�!�$�!r3rCc
���eZdZdZd�fd�	Zejd��Zejd��Z	e
jjd��Zde
dedeed	efd
�Ze
j$jdededed
ed	eeeff
d��Ze
j.jdededed
ed	eeeff
d��Ze
j2jd��Ze
j6jdededeed	eeeffd��Ze
j<jd��Ze
j@jd��Z!de"de#d	e$fd�Z%d�Z&�xZ'S)�LocalWorkerAMPz7
    Local implementation of the manager commands.
    c�D��t�|�||�t�|_yrE)�superrJr&�_streams)r?�boxReceiver�locator�	__class__s   �r4rJzLocalWorkerAMP.__init__�s���
����g�.�&�(��
r3c�:�d|jj�iS)N�streamId)rd�open�r?s r4�
streamOpenzLocalWorkerAMP.streamOpen�s���D�M�M�.�.�0�1�1r3c�>�|jj||�iSrE)rd�write)r?ri�datas   r4�streamWritezLocalWorkerAMP.streamWrite�s���
�
���H�d�+��	r3c�T�|jj|j�ddiS)z0
        Add a success to the reporter.
        r7T)rG�
addSuccess�	_testCase)r?�testNames  r4rrzLocalWorkerAMP.addSuccess�s%��
	
��������/��4� � r3�error�
errorClass�framesr=c
���t|�}t||�}tdt|�d�D]:}|jj||||dzt
||dz�ggf��<|S)a�
        Helper to build a C{Failure} with some traceback.

        @param error: An C{Exception} instance.

        @param errorClass: 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$�)rr�range�lenrw�append�int)r?rurvrw�	errorTyperN�is       r4�
_buildFailurezLocalWorkerAMP._buildFailure�sv��& �
�+�	��%��+���q�#�f�+�q�)�	�A��N�N�!�!����F�1�q�5�M�3�v�a�!�e�}�+=�r�2�F�
�	��r3rt�
errorStreamId�framesStreamIdc�x�dj|jj|��jd�}|jj|�D�cgc]}|jd���}}|j	t|�||�}|jj|j|�ddiScc}w)a�
        Add an error to the reporter.

        @param errorStreamId: The identifier of a stream over which the text
            of this error was previously completely sent to the peer.

        @param framesStreamId: The identifier of a stream over which the lines
            of the traceback for this error were previously completely sent to
            the peer.

        @param error: A message describing the error.
        r3�utf-8r7T)	�joinrd�finish�decoder�r*rG�addErrorrs)	r?rtrvr�r�ru�framerwrNs	         r4r�zLocalWorkerAMP.addError�s���(������-�-�m�<�=�D�D�W�M��/3�}�}�/C�/C�N�/S�
�&+�E�L�L��!�
��
��$�$�_�U�%;�Z��P�������d�n�n�g�6��4� � ��
��B7�failStreamId�	failClassc�x�dj|jj|��jd�}|jj|�D�cgc]}|jd���}}|j	t|�||�}|jj|j|�ddiScc}w)az
        Add a failure to the reporter.

        @param failStreamId: The identifier of a stream over which the text of
            this failure was previously completely sent to the peer.

        @param framesStreamId: The identifier of a stream over which the lines
            of the traceback for this error were previously completely sent to the
            peer.
        r3r�r7T)	r�rdr�r�r�r*rG�
addFailurers)	r?rtr�r�r��failr�rwrNs	         r4r�zLocalWorkerAMP.addFailure�s���$�x�x��
�
�,�,�\�:�;�B�B�7�K��/3�}�}�/C�/C�N�/S�
�&+�E�L�L��!�
��
��$�$�_�T�%:�I�v�N�����������8��4� � ��

r�c�V�|jj|j|�ddiS)z-
        Add a skip to the reporter.
        r7T)rG�addSkiprs)r?rt�reasons   r4r�zLocalWorkerAMP.addSkips'��
	
�����T�^�^�V�4��4� � r3�todoc���dj|jj|��jd�}t	|�dn|�}|j
j
|j||�ddiS)z�
        Add an expected failure to the reporter.

        @param errorStreamId: The identifier of a stream over which the text
            of this error was previously completely sent to the peer.
        r3r�z	<unknown>r7T)r�rdr�r�r#rG�addExpectedFailurers)r?rtr�r�ru�_todos      r4r�z!LocalWorkerAMP.addExpectedFailuresa��������-�-�m�<�=�D�D�W�M���D�L�[�d�;�����'�'�����u�E��4� � r3c�V�|jj|j|�ddiS)z<
        Add an unexpected success to the reporter.
        r7T)rG�addUnexpectedSuccessrs)r?rtr�s   r4r�z#LocalWorkerAMP.addUnexpectedSuccesss'��
	
���)�)�$�.�.�$�?��4� � r3c�z�|jj|dz�|jj�ddiS)z4
        Print test output from the worker.
        �
r7T)�_testStreamrn�flush)r?�outs  r4�	testWritezLocalWorkerAMP.testWrites9��
	
�����s�T�z�*������ ��4� � r3rKr<c��JK�||_||_|jj|�|j�}	|j	t
j|���d{���|jj|�S7�#|jj|�wxYw�w)z
        Run a test.
        )rKN)rsrG�	startTestrO�
callRemoterr]�stopTest)r?rKr<�
testCaseIds    r4r@zLocalWorkerAMP.run(s|����"�����������x�(��[�[�]�
�	,�����);�);�j��Q�Q��L�L�!�!�(�+�R���L�L�!�!�(�+�s.�:B#�$B�!B�"B�%B#�B�B � B#c��||_y)z?
        Set the stream used to log output from tests.
        N)r�)r?�streams  r4�
setTestStreamzLocalWorkerAMP.setTestStream5s��"��r3)NN)(r,r-r.r/rJr%r^rlr'rpr�
AddSuccessrrr*r0rrr��AddErrorr~rr8r��
AddFailurer��AddSkipr��AddExpectedFailurerr��AddUnexpectedSuccessr��	TestWriter�rr r6r@r��
__classcell__)rgs@r4rara�s����)����2��2����������)�)�!�*�!�������S�	�	�

��6���'�'�!��!��!��	!�
�!�
�c�4�i��
!�(�!�>���)�)�!��!��!��	!�
�!�
�c�4�i��
!�*�!�4���&�&�!�'�!��'�'�1�1�!��!�,/�!�7?��}�!�	
�c�4�i��!�2�!��)�)�3�3�!�4�!����(�(�!�)�!�,�(�,�J�,�9�,�"r3rac��eZdZdZy)�LocalWorkerAddressz
    A L{IAddress} implementation meant to provide stub addresses for
    L{ITransport.getPeer} and L{ITransport.getHost}.
    N�r,r-r.r/r2r3r4r�r�<s��r3r�c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�LocalWorkerTransportzi
    A stub transport implementation used to support L{AMP} over a
    L{ProcessProtocol} transport.
    c��||_yrE)�
_transport)r?�	transports  r4rJzLocalWorkerTransport.__init__Ks	��#��r3c�D�|jjt|�y)z,
        Forward data to transport.
        N�r��writeToChildr�r?ros  r4rnzLocalWorkerTransport.writeNs��	
���$�$�%6��=r3c�R�|D]"}|jjt|��$y)zP
        Emulate C{writeSequence} by iterating data in the C{sequence}.
        Nr�)r?�sequenceros   r4�
writeSequencez"LocalWorkerTransport.writeSequenceTs*���	B�D��O�O�(�(�):�D�A�	Br3c�8�|jj�y)z'
        Closes the transport.
        N)r��loseConnectionrks r4r�z#LocalWorkerTransport.loseConnection[s��	
���&�&�(r3c��t�S�z:
        Return a L{LocalWorkerAddress} instance.
        �r�rks r4�getHostzLocalWorkerTransport.getHosta�
��"�#�#r3c��t�Sr�r�rks r4�getPeerzLocalWorkerTransport.getPeergr�r3N)
r,r-r.r/rJrnr�r�r�r�r2r3r4r�r�Ds&���
$�>�B�)�$�$r3r�c��eZdZdZy)�
NotRunningzN
    An operation was attempted on a worker process which is not running.
    Nr�r2r3r4r�r�ns��r3r�c�`�eZdZdZdedeedefd�Zdd�Z	d	�Z
d
�Zdeddfd�Z
d
�Zd�Zd�Zy)�LocalWorkeraL
    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 main log file for tests output.
    �ampProtocol�logDirectory�logFilec�L�||_||_||_t�|_yrE)�_ampProtocol�
_logDirectory�_logFiler�endDeferred)r?r�r�r�s    r4rJzLocalWorker.__init__�s%��(���)�����
�+3�:��r3r=Nc���K�|j�
t��|j}|jjt�	|�d{���y7�#t
$rYywxYw�w)z3
        Cause the worker process to exit.
        N)r�r�r��closeChildFDrr)r?r�s  r4�exitzLocalWorker.exit�sW�����>�>�!��,���&�&�����#�#�$5�6�	������	��	�s<�AA!�A�
A�A�A!�A�	A�A!�A�A!c�@�|jjt|j��|jjd��|jj
d�jd�|_|jj
d�jd�|_	|jj|j�|jjtj|jj��}|j!d��y)	zL
        When connection is made, create the AMP protocol instance.
        T)�ignoreExistingDirectoryzout.log�wzerr.log)r[c��yrEr2)�xs r4�<lambda>z,LocalWorker.connectionMade.<locals>.<lambda>�s�r3N)r��makeConnectionr�r�r��makedirs�childrj�_outLog�_errLogr�r�r�rr_�path�
addErrback)r?�ds  r4�connectionMadezLocalWorker.connectionMade�s���	
���(�(�)=�d�n�n�)M�N����#�#�D�#�A��)�)�/�/�	�:�?�?��D����)�)�/�/�	�:�?�?��D������'�'��
�
�6����(�(�� � ��(�(�-�-�
)�
��	
���^�$r3c�z�|jj�|jj�d|_y)zk
        On connection lost, close the log files that we're managing for stdin
        and stdout.
        N)r��closer�r��r?r�s  r4�connectionLostzLocalWorker.connectionLost�s+��
	
��������������r3r�c��|j|�|jj|�|jj|�y)z�
        When the process closes, call C{connectionLost} for cleanup purposes
        and forward the information to the C{_ampProtocol}.
        N)r�r�r��callbackr�s  r4�processEndedzLocalWorker.processEnded�s:��
	
���F�#����(�(��0����!�!�&�)r3c�:�|jj|�y)z8
        Send data received from stdout to log.
        N)r�rnr�s  r4�outReceivedzLocalWorker.outReceived�s��
	
�����4� r3c�:�|jj|�y)z*
        Write error data to log.
        N)r�rnr�s  r4�errReceivedzLocalWorker.errReceived�s��	
�����4� r3c�|�|tk(r|jj|�ytj|||�y)zT
        Handle data received on the specific pipe for the C{_ampProtocol}.
        N)rr��dataReceivedr�childDataReceived)r?�childFDros   r4r�zLocalWorker.childDataReceived�s3���(�(����*�*�4�0��-�-�d�G�T�Br3)r=N)r,r-r.r/rarrr	rJr�r�r�rr�r�r�r�r2r3r4r�r�ts^��
�	6�#�	6��s�m�	6��		6��%�"�*�7�*�t�*�!�!�Cr3r�)Er/rY�typingrrrrrrr	r
�unittestr�zope.interfacer�attrsr
rr�twisted.internet.deferrr�twisted.internet.errorr�twisted.internet.interfacesrr�twisted.internet.protocolr�twisted.loggerr�twisted.protocols.ampr�twisted.python.failurer�twisted.python.filepathr�twisted.python.reflectr�twisted.trial._distrrrr�"twisted.trial._dist.workerreporterr�twisted.trial.reporterr �twisted.trial.runnerr!r"�twisted.trial.unittestr#r�r%r&r'�	Exceptionr*r6r:rA�WorkerActionrCrar�r�r�r�r2r3r4�<module>r	s,���
�R�R�R��&��&�9�.�<�5�!�%�*�,�.���>�-�7�'�;�;�����i�����	���X��
�T�]�����)�B�-�/�0��@!�S�@!�Fi"�S�i"�X
�X������
�Z��&$�&$��&$�R���]C�/�]Cr3

Zerion Mini Shell 1.0