B
    `                 @   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rd 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markerszfilterwarnings(warning): add a warning filter to the given test. see https://docs.pytest.org/en/stable/warnings.html#pytest-mark-filterwarnings )Zaddinivalue_line)r    r   X/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/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k	s0ttjsRtjdt	d tjdt
d t|| |dkrhdn|j}|dk	rx6|jddD ]&}x |jD ]}	tjt|	d	d
  qW qW dV  x@|D ]8}
|jjt|
||ddd |jjt|
||ddd qW W dQ R X dS )zContext 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_messager   r   location)kwargs)r   nodeidr   r   )ZgetiniZknown_args_namespaceZpythonwarningswarningscatch_warningsAssertionErrorsyswarnoptionsr   DeprecationWarningPendingDeprecationWarningr   r   Ziter_markersargsr   Zpytest_warning_capturedZcall_historicdictZpytest_warning_recorded)r   ihookr   r   Zconfig_filtersZcmdline_filterslogr   markargr   r   r   r   catch_warnings_for_item   s6    


r-   )r   r   c             C   s(   | j }tt|| j| j| j| j}|S )z.Convert a warnings.WarningMessage to a string.)messager    formatwarningstrr   filenamelinenoline)r   Zwarn_msgmsgr   r   r   warning_record_to_strR   s    r5   T)hookwrapperZtryfirst)r   r   c          	   c   s*   t | j| jd| d d V  W d Q R X d S )NZruntest)r   r)   r   r   )r-   r   r)   )r   r   r   r   pytest_runtest_protocol_   s    r7   )sessionr   c          	   c   s.   | j }t||jdd d d V  W d Q R X d S )NZcollect)r   r)   r   r   )r   r-   hook)r8   r   r   r   r   pytest_collectiong   s    r:   )r6   )terminalreporterr   c          	   c   s.   | j }t||jdd d d V  W d Q R X d S )Nr   )r   r)   r   r   )r   r-   r9   )r;   r   r   r   r   pytest_terminal_summaryp   s    r<   c          	   c   s.   | j }t||jdd d d V  W d Q R X d S )Nr   )r   r)   r   r   )r   r-   r9   )r8   r   r   r   r   pytest_sessionfinish{   s    r=   r   )early_configr   c          	   c   s(   t | | jdd d d V  W d Q R X d S )Nr   )r   r)   r   r   )r-   r9   )r>   r   r   r   pytest_load_initial_conftests   s    r?   ) 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   r5   Zhookimplr7   r:   r<   r=   r?   r   r   r   r   <module>   sB   0


