o
    %if4                     @  s$  U d Z ddlmZ ddlZddlZddl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 ddlmZ ddlZdd	lmZ ddlZddlZzdd
lmZ W n eyc   d5ddZY nw G dd dZd5ddZG dd dejZG dd dZd6ddZG dd deZd7d d!Zd8d&d'Zed(kreZd)e d*< e! \Z"Z#Z$Z%e%du re& Z'ej()de' e'ej* ej+,d+d, ej+d+< ne%e_(e"d- ej+d.< e"d/ ej+d0< e-e"d1 ej+d2< ee#dZ.ee.e$,d$ ej(/e"d3 d e.j0_1e"e._"i e._2ee.eZ3e.j4j5e.d4 dS dS )9a/  
This module is executed in remote subprocesses and helps to
control a remote testing session and relay back information.
It assumes that 'py' is importable and does not have dependencies
on the rest of the xdist code.  This means that the xdist-plugin
needs not to be installed in remote environments.
    )annotationsN)Any)	Generator)Literal)Sequence)	TypedDict)_prepareconfig)setproctitletitlestrreturnNonec                 C  s   d S N r
   r   r   E/var/www/html/corbot_env/lib/python3.10/site-packages/xdist/remote.pyr	       s   r	   c                   @  s>   e Zd ZdZdddd
dZdddZdddZdddZdS )Producera  
    Simplified implementation of the same interface as py.log, for backward compatibility
    since we dropped the dependency on pylib.
    Note: this is defined here because this module can't depend on xdist, so we need
    to have the other way around.
    Tenablednamer   r   boolr   r   c                C  s   || _ || _d S r   )r   r   )selfr   r   r   r   r   __init__,   s   
zProducer.__init__c                 C  s    t | j d| jd| j dS )N(z
, enabled=))type__name__r   r   r   r   r   r   __repr__0   s    zProducer.__repr__ar   kc                 O  s8   | j rtd| j dg|R i |dtji d S d S )N[]file)r   printr   sysstderr)r   r   r    r   r   r   __call__3   s   .zProducer.__call__c                 C  s   t | || jdS )Nr   )r   r   )r   r   r   r   r   __getattr__7   s   zProducer.__getattr__N)r   r   r   r   r   r   )r   r   )r   r   r    r   r   r   )r   r   r   r   )r   
__module____qualname____doc__r   r   r'   r(   r   r   r   r   r   $   s    

r   c                 C  s$   zt |  W d S  ty   Y d S w r   )r	   	Exceptionr   r   r   r   worker_title;   s
   r-   c                   @  s   e Zd ZdZdZdS )Markerr      N)r   r)   r*   SHUTDOWNQUEUE_REPLACEDr   r   r   r   r.   C   s    r.   c                   @  s  e Zd ZdMddZdNd
dZdOddZdPddZejdQddZ	ejdRddZ
ejdddSd!d"ZejdTd#d$ZdUd'd(ZdVd+d,ZejdWd.d/ZdTd0d1ZdXd4d5ZejdRd6d7ZejdYd;d<ZejdYd=d>ZejdZdAdBZejd[dDdEZejd\dJdKZdLS )]WorkerInteractorconfigpytest.Configchannelexecnet.Channelr   r   c                 C  sd   || _ |j}|dd| _|d | _td| j |jjd| _|| _	| 
 | _d | _|j|  d S )Nworkerid?
testrunuidzworker-r   )r3   workerinputgetr7   r9   r   optiondebuglogr5   _make_queuetorunnextitem_indexpluginmanagerregister)r   r3   r5   r:   r   r   r   r   I   s   

zWorkerInteractor.__init__r   c                 C  s   | j jjj S r   )r5   gateway	execmodelqueueQueuer   r   r   r   r?   T   s   zWorkerInteractor._make_queueint | Literal[Marker.SHUTDOWN]c                 C  s,   | j  }|tju r| j  }|tju s
|S )zGets the next item from test queue. Handles the case when the queue
        is replaced concurrently in another thread.
        )r@   r;   r.   r1   )r   resultr   r   r   _get_next_item_indexW   s
   



z%WorkerInteractor._get_next_item_indexr   r   kwargsobjectc                 K  s"   |  d|| | j||f d S )Nsending)r>   r5   send)r   r   rK   r   r   r   	sendevent`   s   zWorkerInteractor.sendeventexcreprc                 C  s6   t |}|dD ]}| d| q	tjd|d d S )N
zIERROR>internal_error)formatted_error)r   splitr>   
interactorrO   )r   rP   rS   liner   r   r   pytest_internalerrord   s   z%WorkerInteractor.pytest_internalerrorsessionpytest.Sessionc                 C  s   || _ t }| jd|d d S )Nworkerready)
workerinfo)rX   getinfodictrO   )r   rX   r[   r   r   r   pytest_sessionstartk   s   z$WorkerInteractor.pytest_sessionstartT)hookwrapper
exitstatusintGenerator[None, object, None]c                 c  sF    | j j}t||d< | jj|d< | jj|d< d V  | jd|d d S )Nr_   
shouldfail
shouldstopworkerfinished)workeroutput)r3   re   r`   rX   rb   rc   rO   )r   r_   re   r   r   r   pytest_sessionfinishq   s   z%WorkerInteractor.pytest_sessionfinishc                 C  s   |  d d S )NcollectionstartrO   r   r   r   r   pytest_collection{   s   z"WorkerInteractor.pytest_collectioncommand5tuple[str, dict[str, Any]] | Literal[Marker.SHUTDOWN]c                 C  s   |t ju r| jt j d S |\}}| d|| |dkr,|d D ]}| j| q!d S |dkrCtt| jjD ]}| j| q8d S |dkrP| jt j d S |dkr]| 	|d  d S d S )Nzreceived commandruntestsindicesruntests_allshutdownsteal)
r.   r0   r@   putr>   rangelenrX   itemsrp   )r   rj   r   rK   ir   r   r   handle_command   s$   
zWorkerInteractor.handle_commandrm   Sequence[int]c                   s|   t |}g }j  _d fdd}t|d D ]}||v r(|| qj| qjd|d  tj d S )Nr   
int | Nonec                     s@   t jjjjj   W  d    S 1 sw   Y  d S r   )
contextlibsuppressr5   rD   rE   rF   Empty
get_nowaitr   	old_queuer   r   r   old_queue_get_nowait_noraise   s    z<WorkerInteractor.steal.<locals>.old_queue_get_nowait_noraiseunscheduled)rm   )r   rx   )	setr@   r?   iterappendrq   rO   r.   r1   )r   rm   indices_setstolenr   ru   r   r}   r   rp      s   zWorkerInteractor.stealr   c                 C  s^   |  d | jj| jtjd |  | _| jtjur-|   |j	s$|j
r'	 dS | jtjusdS )Nzentering main loop)	endmarkerT)r>   r5   setcallbackrv   r.   r0   rJ   rA   run_one_testrb   rc   r   rX   r   r   r   pytest_runtestloop   s   

z#WorkerInteractor.pytest_runtestloopc                 C  s   t | jtsJ | j| _|  | _| jj}|| j }| jtju r#d }n| jd us*J || j }t	d|j
  t }| jjj||d t | }t	d | jd| j|d d S )Nz[pytest-xdist running] %s)itemnextitemz[pytest-xdist idle]runtest_protocol_complete)
item_indexduration)
isinstancerA   r`   r   rJ   rX   rt   r.   r0   r-   nodeidtimeperf_counterr3   hookpytest_runtest_protocolrO   )r   rt   r   r   startr   r   r   r   r      s"   



zWorkerInteractor.run_one_testrt   list[pytest.Item]c                 C  sd   | dr.|D ](}|d}|sqt|jdkr|jd n|jdd}|j d| |_qd S d S )N	loadgroupxdist_groupr   r   default@)getvalueget_closest_markerrs   argsrK   r;   r   _nodeid)r   r3   rt   r   markgnamer   r   r   pytest_collection_modifyitems   s   


z.WorkerInteractor.pytest_collection_modifyitemsc                 C  s(   | j dt| jjdd |jD d d S )Ncollectionfinishc                 S  s   g | ]}|j qS r   )r   ).0r   r   r   r   
<listcomp>   s    z=WorkerInteractor.pytest_collection_finish.<locals>.<listcomp>)topdirids)rO   r   r3   rootpathrt   r   r   r   r   pytest_collection_finish   s
   

z)WorkerInteractor.pytest_collection_finishr   locationtuple[str, int | None, str]c                 C     | j d||d d S )Nlogstartr   r   rh   r   r   r   r   r   r   pytest_runtest_logstart      z(WorkerInteractor.pytest_runtest_logstartc                 C  r   )N	logfinishr   rh   r   r   r   r   pytest_runtest_logfinish   r   z)WorkerInteractor.pytest_runtest_logfinishreportpytest.TestReportc                 C  s^   | j jj| j |d}| j|d< | j|d< | j|d< | jj| j j|jks&J | j	d|d d S )Nr3   r   r   	worker_idtestrun_uid
testreportdata)
r3   r   pytest_report_to_serializabler   r7   r9   rX   rt   r   rO   r   r   r   r   r   r   pytest_runtest_logreport   s   


z)WorkerInteractor.pytest_runtest_logreportpytest.CollectReportc                 C  s0   |j s| jjj| j|d}| jd|d d S d S )Nr   collectreportr   )passedr3   r   r   rO   r   r   r   r   pytest_collectreport  s   z%WorkerInteractor.pytest_collectreportwarning_messagewarnings.WarningMessagewhentuple[str, int, str] | Nonec                 C  s   | j dt||||d d S )Nwarning_recorded)warning_message_datar   r   r   )rO   serialize_warning_message)r   r   r   r   r   r   r   r   pytest_warning_recorded
  s   
z(WorkerInteractor.pytest_warning_recordedN)r3   r4   r5   r6   r   r   )r   r   )r   rH   )r   r   rK   rL   r   r   )rP   rL   r   r   )rX   rY   r   r   )r_   r`   r   ra   )r   r   )rj   rk   r   r   )rm   rw   r   r   )rX   rY   r   r   )r3   r4   rt   r   r   r   )r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   )
r   r   r   r   r   r   r   r   r   r   )r   r)   r*   r   r?   rJ   rO   pytesthookimplrW   r]   rf   ri   rv   rp   r   r   r   r   r   r   r   r   r   r   r   r   r   r2   H   s>    



	
	





r2   r   r   dict[str, Any]c           
   	   C  s  t | jtr2t| jj}t| jj}t| j}z	t| jj	 W n tj
y,   d }Y nw | jj	}n	| j}d }d }d }| jrG| jj}| jj}nd }d }||||||d}| jD ](}|dv r^qWt| |}	zt|	 W n tj
yz   t|	||< Y qWw |	||< qW|S )N)message_strmessage_modulemessage_class_namemessage_argscategory_modulecategory_class_name)messagecategory)r   r   Warningr   r)   r   r   execnetdumpsr   	DumpErrorr   _WARNING_DETAILSgetattrrepr)
r   r   r   r   r   r   r   rI   	attr_nameattrr   r   r   r     sJ   



	

r   c                   @  sN   e Zd ZU ded< ded< ded< ded< ded< ded< ded	< d
ed< dS )
WorkerInfor   versionztuple[int, int, int, str, int]version_infosysplatformplatform
executablecwdidzexecnet.XSpecspecN)r   r)   r*   __annotations__r   r   r   r   r   N  s   
 r   c                  C  s0   dd l } ttjttjtj |   tjt dS )Nr   )r   r   r   r   r   r   )	r   dictr%   r   tupler   r   osgetcwd)r   r   r   r   r\   Y  s   r\   r3   r4   basetemp
str | Nonec                 C  sN   |  ddk| j_d| j_d| j_d| j_d| j_d | j_d | j_|| j_	d S )Ndistr   Fno)
r   r<   r   
looponfailusepdbr   distloadnumprocessesmaxprocessesr   )r3   r   r   r   r   setup_configf  s   r   __channelexec__r6   r5   
PYTHONPATH r9   PYTEST_XDIST_TESTRUNUIDr7   PYTEST_XDIST_WORKERworkercountPYTEST_XDIST_WORKER_COUNTmainargv)r3   )r
   r   r   r   )r   r   r   r   )r   r   )r3   r4   r   r   r   r   )6r+   
__future__r   ry   enumr   r%   r   typingr   r   r   r   r   warnings_pytest.configr   r   r   r	   ImportErrorr   r-   Enumr.   r2   r   r   r\   r   r   r5   r   receiver:   r   option_dictchange_sys_pathr   
importpathpathinsertpathsepenvironr;   r   r3   basename_parserprogre   rU   r   pytest_cmdline_mainr   r   r   r   <module>   sd    
 
T3





