a
    /§»a  ã                   @   s¤   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Zd dlmZ d dl	m
Z
 d dlmZ d dlmZ ee ƒ Ze
ddœd	d
„Zeddœdd„ZG dd„ dƒZdS )é    N)Ú	Generator)ÚTextIO)ÚConfig)ÚParser)ÚItem)ÚStoreKey)ÚparserÚreturnc                 C   s   d}| j d|dd� d S )NzVDump the traceback of all threads if a test takes more than TIMEOUT seconds to finish.Úfaulthandler_timeoutç        )Údefault)Zaddini)r   Úhelp© r   úN/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/_pytest/faulthandler.pyÚpytest_addoption   s    ÿr   ©Úconfigr	   c                 C   sL   dd l }| ¡ s"| j tƒ d¡ n&t | ¡}|dkrH| jt d¡dd� d S )Nr   zfaulthandler-hookszcfaulthandler module enabled before pytest configuration step, 'faulthandler_timeout' option ignoredé   )Ú
stacklevel)	ÚfaulthandlerÚ
is_enabledZpluginmanagerÚregisterÚFaultHandlerHooksÚget_timeout_config_valueZissue_config_time_warningÚpytestZPytestConfigWarning)r   r   Útimeoutr   r   r   Úpytest_configure   s    
ÿûr   c                   @   sž   e Zd ZdZeddœdd„Zeddœdd„Zedd	„ ƒZed
d„ ƒZ	e
jddd�eed dœdd„ƒZe
jdd�ddœdd„ƒZe
jdd�ddœdd„ƒZdS )r   zˆImplements hooks that will actually install fault handler before tests execute,
    as well as correctly handle pdb and internal errors.Nr   c                 C   s<   dd l }t |  ¡ ¡}t|dƒ|jt< |j|jt d� d S )Nr   Úw©Úfile)r   ÚosÚdupÚ_get_stderr_filenoÚopenÚ_storeÚfault_handler_stderr_keyÚenable)Úselfr   r   Zstderr_fd_copyr   r   r   r   2   s    z"FaultHandlerHooks.pytest_configurec                 C   s:   dd l }| ¡  |jt  ¡  |jt= |j|  ¡ d� d S ©Nr   r   )r   Údisabler$   r%   Úcloser&   r"   )r'   r   r   r   r   r   Úpytest_unconfigure9   s
    z$FaultHandlerHooks.pytest_unconfigurec               	   C   sF   zt j ¡ } | dkrtƒ ‚| W S  ttjfy@   t j ¡  Y S 0 d S )Néÿÿÿÿ)ÚsysÚstderrÚfilenoÚAttributeErrorÚioÚUnsupportedOperationÚ
__stderr__)r/   r   r   r   r"   E   s    
z$FaultHandlerHooks._get_stderr_filenoc                 C   s   t |  d¡pdƒS )Nr
   r   )ÚfloatZgetini)r   r   r   r   r   T   s    z*FaultHandlerHooks.get_timeout_config_valueT)ZhookwrapperZtrylast)NNN)Úitemr	   c                 c   sh   |   |j¡}|jjt }|dkr^|d ur^dd l}|j||d� zd V  W | ¡  qd| ¡  0 nd V  d S r(   )r   r   r$   r%   r   Zdump_traceback_laterÚcancel_dump_traceback_later)r'   r5   r   r.   r   r   r   r   Úpytest_runtest_protocolX   s    z)FaultHandlerHooks.pytest_runtest_protocol)Ztryfirst)r	   c                 C   s   ddl }| ¡  dS )z@Cancel any traceback dumping due to timeout before entering pdb.r   N©r   r6   ©r'   r   r   r   r   Úpytest_enter_pdbg   s    z"FaultHandlerHooks.pytest_enter_pdbc                 C   s   ddl }| ¡  dS )zRCancel any traceback dumping due to an interactive exception being
        raised.r   Nr8   r9   r   r   r   Úpytest_exception_interactn   s    z+FaultHandlerHooks.pytest_exception_interact)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r+   Ústaticmethodr"   r   r   Zhookimplr   r   r7   r:   r;   r   r   r   r   r   .   s   



r   )r1   r    r-   Útypingr   r   r   Z_pytest.configr   Z_pytest.config.argparsingr   Z_pytest.nodesr   Z_pytest.storer   r%   r   r   r   r   r   r   r   Ú<module>   s   
