B
    `<J                 @   s  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 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 d dlmZ d dlmZ d dlm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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 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+ d d#l,m-Z- d d$l.m/Z/ d%d& Z0ed'd(d)Z1G d*d( d(Z2e3ee2 d+d,d-d.Z4e#G d/d0 d0e2Z5e#G d1d2 d2e2Z6G d3d4 d4eZ7ee6e5f eee3ef  d5d6d7Z8ee3ef eee6e5f  d8d9d:Z9e2ee3ef d5d;d<Z:ee3ef ee3ef d=d>d?Z;dS )@    )StringIO)Path)pprint)Any)cast)Dict)Iterable)Iterator)List)Optional)Tuple)Type)TYPE_CHECKING)TypeVar)UnionN)ExceptionChainRepr)ExceptionInfo)ExceptionRepr)	ReprEntry)ReprEntryNative)ReprExceptionInfo)ReprFileLocation)ReprFuncArgs)
ReprLocals)ReprTraceback)TerminalRepr)TerminalWriter)final)Config)	Collector)Item)skip)NoReturn)Literal)CallInfoc          
   C   s\   y| j S  tk
rV   | j}d|d d d  }d|d |d ||d  | _ }|S X d S )Nz%s.%s.%sversion_info   z[{}] {} -- Python {} {}idZsysplatform
executable)Z_workerinfocacheAttributeErrorZ
workerinfoformat)nodedvers r/   W/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/_pytest/reports.pygetworkerinfoline-   s    r1   _R
BaseReport)boundc               @   s  e Zd ZU ee ed< eeeee ef  ed< ede	e
 eeeef eef ed< eeeef  ed< eed< edddd	Zereed
ddZeddddZeeeeef  dddZeedddZeedddZeedddZeedddZedd Zedd Zedd Zeedd d!Zeedd"d#Zeee dd$d%Z e!d&d'd(Z"e#eef dd)d*Z$e%e&e' e#ee(f e'd+d,d-Z)dS ).r3   whenlocationNlongreprsectionsnodeid)kwreturnc             K   s   | j | d S )N)__dict__update)selfr:   r/   r/   r0   __init__E   s    zBaseReport.__init__)keyr;   c             C   s   d S )Nr/   )r>   r@   r/   r/   r0   __getattr__J   s    zBaseReport.__getattr__)outr;   c             C   s   t | dr|t| j | j}|d kr,d S t |drLtt|}|| n0yt|}W n t	k
rp   d}Y nX || d S )Nr+   
toterminalz<unprintable longrepr>)
hasattrliner1   r+   r7   r   r   rC   strUnicodeEncodeError)r>   rB   r7   Zlongrepr_terminalr.   r/   r/   r0   rC   M   s    



zBaseReport.toterminal)prefixr;   c             c   s,   x&| j D ]\}}||r||fV  qW d S )N)r8   
startswith)r>   rH   namecontentr/   r/   r0   get_sections_   s    
zBaseReport.get_sections)r;   c             C   s.   t  }t|}d|_| | | }| S )zRead-only property that returns the full string representation of
        ``longrepr``.

        .. versionadded:: 3.0
        F)r   r   Z	hasmarkuprC   getvaluestrip)r>   fileZtwexcr/   r/   r0   longreprtextd   s    
zBaseReport.longreprtextc             C   s   d dd | dD S )z_Return captured log lines, if log capturing is enabled.

        .. versionadded:: 3.5
        
c             s   s   | ]\}}|V  qd S )Nr/   ).0rH   rK   r/   r/   r0   	<genexpr>y   s    z$BaseReport.caplog.<locals>.<genexpr>zCaptured log)joinrL   )r>   r/   r/   r0   caplogr   s    zBaseReport.caplogc             C   s   d dd | dD S )zbReturn captured text from stdout, if capturing is enabled.

        .. versionadded:: 3.0
         c             s   s   | ]\}}|V  qd S )Nr/   )rS   rH   rK   r/   r/   r0   rT      s    z'BaseReport.capstdout.<locals>.<genexpr>zCaptured stdout)rU   rL   )r>   r/   r/   r0   	capstdout|   s    zBaseReport.capstdoutc             C   s   d dd | dD S )zbReturn captured text from stderr, if capturing is enabled.

        .. versionadded:: 3.0
        rW   c             s   s   | ]\}}|V  qd S )Nr/   )rS   rH   rK   r/   r/   r0   rT      s    z'BaseReport.capstderr.<locals>.<genexpr>zCaptured stderr)rU   rL   )r>   r/   r/   r0   	capstderr   s    zBaseReport.capstderrc             C   s
   | j dkS )Npassed)outcome)xr/   r/   r0   <lambda>       zBaseReport.<lambda>c             C   s
   | j dkS )Nfailed)r[   )r\   r/   r/   r0   r]      r^   c             C   s
   | j dkS )Nskipped)r[   )r\   r/   r/   r0   r]      r^   c             C   s   | j dd S )Nz::r   )r9   split)r>   r/   r/   r0   fspath   s    zBaseReport.fspathc             C   s   dS )a6  **Experimental** Whether this report should be counted towards the
        totals shown at the end of the test session: "1 passed, 1 failure, etc".

        .. note::

            This function is considered **experimental**, so beware that it is subject to changes
            even in patch releases.
        Tr/   )r>   r/   r/   r0   count_towards_summary   s    
z BaseReport.count_towards_summaryc             C   s   | j dk	r| j \}}}|S dS )a  **Experimental** The head line shown with longrepr output for this
        report, more commonly during traceback representation during
        failures::

            ________ Test.foo ________


        In the example above, the head_line is "Test.foo".

        .. note::

            This function is considered **experimental**, so beware that it is subject to changes
            even in patch releases.
        N)r6   )r>   rb   linenodomainr/   r/   r0   	head_line   s    
zBaseReport.head_line)configc             C   s   |j j| |d\}}}|S )N)reportrg   )hookZpytest_report_teststatus)r>   rg   Z	_categoryZ_shortverboser/   r/   r0   _get_verbose_word   s    zBaseReport._get_verbose_wordc             C   s   t | S )zReturn the contents of this report as a dict of builtin entries,
        suitable for serialization.

        This was originally the serialize_report() function from xdist (ca03269).

        Experimental method.
        )_report_to_json)r>   r/   r/   r0   _to_json   s    zBaseReport._to_json)cls
reportdictr;   c             C   s   t |}| f |S )a  Create either a TestReport or CollectReport, depending on the calling class.

        It is the callers responsibility to know which class to pass here.

        This was originally the serialize_report() function from xdist (ca03269).

        Experimental method.
        )_report_kwargs_from_json)rn   ro   kwargsr/   r/   r0   
_from_json   s    
zBaseReport._from_json)*__name__
__module____qualname__r   rF   __annotations__r   intr   r   BaseExceptionr   r
   r   r?   r   rA   r   rC   r	   rL   propertyrQ   rV   rX   rY   rZ   r_   r`   rb   boolrc   rf   r   rk   r   rm   classmethodr   r2   objectrr   r/   r/   r/   r0   r3   <   s@   
"			
r"   )	type_namereport_classr;   c             C   sn   d}t  }td|d td|  |d td| |d t||d td| |d td|d t| d S )Nz+https://github.com/pytest-dev/pytest/issueszd----------------------------------------------------------------------------------------------------)streamz.INTERNALERROR: Unknown entry type returned: %szreport_name: %szPlease report this bug at %s)r   r   RuntimeErrorrM   )r}   r~   ro   urlr   r/   r/   r0   _report_unserialization_failure   s    r   c               @   s   e Zd ZdZdZdeeeee ef de	de
e eeeef eef deeeef  eeeeeef   dd	d	d
ZedddZeedd dddZdS )
TestReportzSBasic test report object (also used for setup and teardown calls if
    they fail).Fr/   r   Nz&Literal['passed', 'failed', 'skipped']z$Literal['setup', 'call', 'teardown'])	r9   r6   r[   r7   r5   r8   durationuser_propertiesr;   c
             K   sR   || _ || _|| _|| _|| _|| _t|	p,g | _t|| _|| _	| j
|
 d S )N)r9   r6   keywordsr[   r7   r5   listr   r8   r   r<   r=   )r>   r9   r6   r   r[   r7   r5   r8   r   r   extrar/   r/   r0   r?      s    
zTestReport.__init__)r;   c             C   s   d | jj| j| j| jS )Nz <{} {!r} when={!r} outcome={!r}>)r*   	__class__rs   r9   r5   r[   )r>   r/   r/   r0   __repr__  s    zTestReport.__repr__zCallInfo[None])itemcallr;   c             C   s  |j }|dkst|j}dd |jD }|j}g }|jsBd}d}	nvt|tsVd}|}	nbt|jtj	rd}|
 }
t|
j|
j|
jf}	n2d}|j dkr||}	n|j||jd	d
d}	x.|jD ]$\}}}|d| d| |f qW | |j|j|||	||||jd	S )z>Create and fill a TestReport with standard item and call info.collectc             S   s   i | ]
}d |qS )   r/   )rS   r\   r/   r/   r0   
<dictcomp>+  s    z1TestReport.from_item_and_call.<locals>.<dictcomp>rZ   Nr_   r`   r   Ztbstyleauto)stylez	Captured  )r   )r5   AssertionErrorr   r   excinfo
isinstancer   valuer!   	ExceptionZ_getreprcrashrF   pathrd   messageZrepr_failureZ_repr_failure_pyrg   Z	getoptionZ_report_sectionsappendr9   r6   r   )rn   r   r   r5   r   r   r   r8   r[   r7   rZrwhenr@   rK   r/   r/   r0   from_item_and_call$  sB    

zTestReport.from_item_and_call)r/   r   N)rs   rt   ru   __doc__Z__test__rF   r   r   rw   r   r   rx   r   r   floatr|   r?   r   r{   r    r   r/   r/   r/   r0   r      s     X%r   c               @   sb   e Zd ZdZdZdedeeee	e
f   eeeef  ddddZed	d
 ZedddZdS )CollectReportzCollection report object.r   r/   z&Literal['passed', 'skipped', 'failed']N)r9   r[   resultr8   r;   c             K   s6   || _ || _|| _|pg | _t|| _| j| d S )N)r9   r[   r7   r   r   r8   r<   r=   )r>   r9   r[   r7   r   r8   r   r/   r/   r0   r?   \  s    


zCollectReport.__init__c             C   s   | j d | j fS )N)rb   )r>   r/   r/   r0   r6   z  s    zCollectReport.location)r;   c             C   s   d | jt| j| jS )Nz.<CollectReport {!r} lenresult={} outcome={!r}>)r*   r9   lenr   r[   )r>   r/   r/   r0   r   ~  s    zCollectReport.__repr__)r/   )rs   rt   ru   r   r5   rF   r   r
   r   r    r   r   r   r?   ry   r6   r   r/   r/   r/   r0   r   V  s   &r   c               @   s,   e Zd ZeddddZeddddZdS )CollectErrorReprN)msgr;   c             C   s
   || _ d S )N)r7   )r>   r   r/   r/   r0   r?     s    zCollectErrorRepr.__init__)rB   r;   c             C   s   |j | jdd d S )NT)Zred)rE   r7   )r>   rB   r/   r/   r0   rC     s    zCollectErrorRepr.toterminal)rs   rt   ru   rF   r?   r   rC   r/   r/   r/   r0   r     s   r   )rh   r;   c             C   s*   t | ttfr&|  }| jj|d< |S d S )Nz$report_type)r   r   r   rm   r   rs   )rh   datar/   r/   r0   pytest_report_to_serializable  s
    r   )r   r;   c             C   sN   d| krJ| d dkrt | S | d dkr4t| S dsJtd| d d S )Nz$report_typer   r   Fz(Unknown report_type unserialize data: {})r   rr   r   r   r*   )r   r/   r/   r0   pytest_report_from_serializable  s    


r   c                s  t ttf tttf dddttttf dfddtt ttttf  ddd	 t	tttf d
 fdd}| j
 }t| jdrt| jdrt| jdr|| |d< qt| j|d< n
| j|d< xF|D ]>}t|| tjjtfrt|| ||< q|dkrd||< qW |S )zReturn the contents of this report as a dict of builtin entries,
    suitable for serialization.

    This was originally the serialize_report() function from xdist (ca03269).
    )entryr;   c             S   sL   t | }x,| D ] \}}t|drt |||< qW t| j|d}|S )Nr<   )typer   )attrasdictitemsrD   r   rs   )r   r   r@   r   
entry_datar/   r/   r0   serialize_repr_entry  s    

z-_report_to_json.<locals>.serialize_repr_entry)reprtracebackr;   c                s&   t | } fdd| jD |d< |S )Nc                s   g | ]} |qS r/   r/   )rS   r\   )r   r/   r0   
<listcomp>  s    zE_report_to_json.<locals>.serialize_repr_traceback.<locals>.<listcomp>reprentries)r   r   r   )r   r   )r   r/   r0   serialize_repr_traceback  s    
z1_report_to_json.<locals>.serialize_repr_traceback)	reprcrashr;   c             S   s   | d k	rt | S d S d S )N)r   r   )r   r/   r/   r0   serialize_repr_crash  s    
z-_report_to_json.<locals>.serialize_repr_crash)repr;   c                s   | j d k	sttt| j } |j|j|jd}t|trzg |d< x:|j	D ]&\}}}|d 
| ||f qNW nd |d< |S )N)r   r   r8   chain)r7   r   r   r   r   r   r8   r   r   r   r   )r   r7   r   Zrepr_tracebackZ
repr_crashdescription)r   r   r/   r0   serialize_exception_longrepr  s    

z5_report_to_json.<locals>.serialize_exception_longreprrC   r   r   r7   r   N)r   r   r   r   rF   r   r   r   r   r3   r<   copyrD   r7   r   pyr   localr   )rh   r   r,   rJ   r/   )r   r   r   r0   rl     s&    




rl   )ro   r;   c                s   fdd  fdd}t tttf  ddd}d rd	d krd
d kr|d d
 }|d d	 }d d rg }x2d d D ]"\}}}||||||f qW t|}	n
t||}	xd d D ]}
|	j|
  qW |	d< S )zReturn **kwargs that can be used to construct a TestReport or
    CollectReport instance.

    This was originally the serialize_report() function from xdist (ca03269).
    c                s   | d }| d }|dkrd }d }d }|d r:t f |d }|d rPtf |d }|d rht|d d }t|d ||||d d	}n"|d
krt|d }nt|t  |S )Nr   r   r   reprfuncargsreprfileloc
reprlocalslinesr   )r   r   r   r   r   r   )r   r   r   r   r   r   r   )r   r   Z
entry_typer   r   r   Z	reprentry)ro   r/   r0   deserialize_repr_entry  s,    z8_report_kwargs_from_json.<locals>.deserialize_repr_entryc                s$    fdd| d D | d< t f | S )Nc                s   g | ]} |qS r/   r/   )rS   r\   )r   r/   r0   r     s    zP_report_kwargs_from_json.<locals>.deserialize_repr_traceback.<locals>.<listcomp>r   )r   )Zrepr_traceback_dict)r   r/   r0   deserialize_repr_traceback  s    z<_report_kwargs_from_json.<locals>.deserialize_repr_traceback)repr_crash_dictc             S   s   | d k	rt f | S d S d S )N)r   )r   r/   r/   r0   deserialize_repr_crash  s    
z8_report_kwargs_from_json.<locals>.deserialize_repr_crashr7   r   r   r   r8   )r   r   rF   r   r   r   r   Z
addsection)ro   r   r   r   r   r   Zrepr_traceback_dataZrepr_crash_datar   exception_infosectionr/   )r   ro   r0   rp     s0    

rp   )<ior   pathlibr   r   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   Z_pytest._code.coder   r   r   r   r   r   r   r   r   r   r   Z_pytest._ior   Z_pytest.compatr   Z_pytest.configr   Z_pytest.nodesr   r    Z_pytest.outcomesr!   r"   Ztyping_extensionsr#   Z_pytest.runnerr$   r1   r2   r3   rF   r   r   r   r   r   r   rl   rp   r/   r/   r/   r0   <module>   sl    p-	


I