a
    ˆÏ?eÎ  ã                   @   sŠ  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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mZ er d dlmZ eddœdd„Zeedee ed dœdd„ƒZejedœdd„Zejddd�eed dœdd„ƒZejddd�eed dœdd„ƒZejdd �eed d!œd"d#„ƒZejdd �eed dœd$d%„ƒZejdd �d&ed d'œd(d)„ƒZdS )*é    N)Úcontextmanager)Ú	Generator)ÚOptional)ÚTYPE_CHECKING)Úapply_warning_filters)ÚConfig)Úparse_warning_filter)ÚSession)ÚItem)ÚTerminalReporter)ÚLiteral)ÚconfigÚreturnc                 C   s   |   dd¡ d S )NÚmarkerszŸfilterwarnings(warning): add a warning filter to the given test. see https://docs.pytest.org/en/stable/how-to/capture-warnings.html#pytest-mark-filterwarnings )Zaddinivalue_line)r   © r   úS/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/_pytest/warnings.pyÚpytest_configure   s    þr   z'Literal['config', 'collect', 'runtest'])NNN)r   ÚwhenÚitemr   c              	   c   sò   |   d¡}| jjpg }tjdd��¼}|dus0J ‚tjsRtjdtd� tjdt	d� t
||ƒ |du rhdn|j}|dur¦|jdd�D ]"}|jD ]}	tjt|	d	d
�Ž  qŒq‚dV  |D ]}
|jjt|
||dd�d� q°W d  ƒ n1 sä0    Y  dS )zíContext manager that catches warnings generated in the contained execution block.

    ``item`` can be None if we are not in the context of an item execution.

    Each warning captured triggers the ``pytest_warning_recorded`` hook.
    ÚfilterwarningsT)ÚrecordNÚalways)ÚcategoryÚ )ÚnameF)Úescape)Úwarning_messageÚnodeidr   Úlocation)Úkwargs)ZgetiniZknown_args_namespaceZpythonwarningsÚwarningsÚcatch_warningsÚsysÚwarnoptionsr   ÚDeprecationWarningÚPendingDeprecationWarningr   r   Ziter_markersÚargsr   Zpytest_warning_recordedZcall_historicÚdict)r   Úihookr   r   Zconfig_filtersZcmdline_filtersÚlogr   ÚmarkÚargr   r   r   r   Úcatch_warnings_for_item   s.    


üÿr,   )r   r   c                 C   s    | j }t t|ƒ| j| j| j| j¡}| jdurœzddl	}W n t
yL   Y nP0 | | j¡}|dur€d | ¡ ¡}|d|› �7 }nd}|d7 }|d|› d�7 }|S )	z.Convert a warnings.WarningMessage to a string.Nr   Ú
z
Object allocated at:
zPhttps://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warningszDEnable tracemalloc to get traceback where the object was allocated.
zSee z for more info.)Úmessager    ÚformatwarningÚstrr   ÚfilenameÚlinenoÚlineÚsourceÚtracemallocÚImportErrorÚget_object_tracebackÚjoinÚformat)r   Zwarn_msgÚmsgr5   ÚtbZformatted_tbÚurlr   r   r   Úwarning_record_to_strJ   s*    û
r=   T)ÚhookwrapperZtryfirst)r   r   c                 c   s>   t | j| jd| d�� d V  W d   ƒ n1 s00    Y  d S )NZruntest©r   r(   r   r   )r,   r   r(   )r   r   r   r   Úpytest_runtest_protocolh   s    ÿr@   )Úsessionr   c                 c   sB   | j }t||jdd d�� d V  W d   ƒ n1 s40    Y  d S )NZcollectr?   ©r   r,   Úhook©rA   r   r   r   r   Úpytest_collectionp   s
    
ÿrE   )r>   )Úterminalreporterr   c                 c   sB   | j }t||jdd d�� d V  W d   ƒ n1 s40    Y  d S ©Nr   r?   rB   )rF   r   r   r   r   Úpytest_terminal_summaryy   s
    
ÿrH   c                 c   sB   | j }t||jdd d�� d V  W d   ƒ n1 s40    Y  d S rG   rB   rD   r   r   r   Úpytest_sessionfinish„   s
    
ÿrI   r   )Úearly_configr   c                 c   s<   t | | jdd d�� d V  W d   ƒ n1 s.0    Y  d S rG   )r,   rC   )rJ   r   r   r   Úpytest_load_initial_conftests�   s    
ÿrK   ) r"   r    Ú
contextlibr   Útypingr   r   r   ZpytestZ_pytest.configr   r   r   Z_pytest.mainr	   Z_pytest.nodesr
   Z_pytest.terminalr   Ztyping_extensionsr   r   r,   ÚWarningMessager0   r=   Zhookimplr@   rE   rH   rI   rK   r   r   r   r   Ú<module>   sH   û-
þ


þ