a
    !fhQ                     @   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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 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& Z/ed'd(d)Z0G d*d( d(Z1e2ee1 ed+d,d-Z3e#G d.d/ d/e1Z4e#G d0d1 d1e1Z5G d2d3 d3eZ6ee5e4f eee2ef  d4d5d6Z7ee2ef eee5e4f  d7d8d9Z8e1ee2ef d4d:d;Z9ee2ef ee2ef d<d=d>Z:dS )?    N)StringIO)pprint)Any)cast)Dict)Iterable)Iterator)List)Mapping)NoReturn)Optional)Tuple)Type)TYPE_CHECKING)TypeVar)Union)ExceptionChainRepr)ExceptionInfo)ExceptionRepr)	ReprEntry)ReprEntryNative)ReprExceptionInfoReprFileLocation)ReprFuncArgs)
ReprLocalsReprTraceback)TerminalRepr)TerminalWriter)final)Config)	Collector)Item)skip)Literal)CallInfoc              
   C   s`   z| j W S  tyZ   | j}d|d d d  }d|d |d ||d  | _ }| Y S 0 d S )Nz%s.%s.%sversion_info   z[{}] {} -- Python {} {}idZsysplatform
executable)Z_workerinfocacheAttributeErrorZ
workerinfoformat)nodedvers r1   P/var/www/html/python-backend/venv/lib/python3.9/site-packages/_pytest/reports.pygetworkerinfoline,   s    
r3   _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< d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e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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/d0d1Z)dS )2r5   whenlocationNlongreprsectionsnodeid&Literal['passed', 'failed', 'skipped']outcome)kwreturnc                 K   s   | j | d S N)__dict__update)selfr>   r1   r1   r2   __init__E   s    zBaseReport.__init__)keyr?   c                 C   s   d S r@   r1   )rC   rE   r1   r1   r2   __getattr__J   s    zBaseReport.__getattr__outr?   c                 C   s   t | dr"t| j}|r"|| | j}|d u r4d S t |drTtt|}|| n.zt|}W n t	yv   d}Y n0 || d S )Nr-   
toterminalz<unprintable longrepr>)
hasattrr3   r-   liner9   r   r   rI   strUnicodeEncodeError)rC   rH   Zworker_infor9   Zlongrepr_terminalr0   r1   r1   r2   rI   M   s    





zBaseReport.toterminal)prefixr?   c                 c   s(   | j D ]\}}||r||fV  qd S r@   )r:   
startswith)rC   rN   namecontentr1   r1   r2   get_sectionsa   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	hasmarkuprI   getvaluestrip)rC   fileZtwexcr1   r1   r2   longreprtextf   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 r@   r1   .0rN   rQ   r1   r1   r2   	<genexpr>z   s   z$BaseReport.caplog.<locals>.<genexpr>zCaptured logjoinrR   rC   r1   r1   r2   caplogt   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 r@   r1   rZ   r1   r1   r2   r\      s   z'BaseReport.capstdout.<locals>.<genexpr>zCaptured stdoutr]   r_   r1   r1   r2   	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
        ra   c                 s   s   | ]\}}|V  qd S r@   r1   rZ   r1   r1   r2   r\      s   z'BaseReport.capstderr.<locals>.<genexpr>zCaptured stderrr]   r_   r1   r1   r2   	capstderr   s    
zBaseReport.capstderrc                 C   s
   | j dkS )zWhether the outcome is passed.passedr=   r_   r1   r1   r2   rd      s    zBaseReport.passedc                 C   s
   | j dkS )zWhether the outcome is failed.failedre   r_   r1   r1   r2   rf      s    zBaseReport.failedc                 C   s
   | j dkS )zWhether the outcome is skipped.skippedre   r_   r1   r1   r2   rg      s    zBaseReport.skippedc                 C   s   | j dd S )z3The path portion of the reported node, as a string.z::r   )r;   splitr_   r1   r1   r2   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.
        Tr1   r_   r1   r1   r2   count_towards_summary   s    
z BaseReport.count_towards_summaryc                 C   s   | j du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)r8   )rC   ri   linenodomainr1   r1   r2   	head_line   s    
zBaseReport.head_line)configc                 C   s   |j j| |d\}}}|S )N)reportrn   )hookZpytest_report_teststatus)rC   rn   Z	_categoryZ_shortverboser1   r1   r2   _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_jsonr_   r1   r1   r2   _to_json   s    zBaseReport._to_json)cls
reportdictr?   c                 C   s   t |}| f i |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)ru   rv   kwargsr1   r1   r2   
_from_json   s    
zBaseReport._from_json)*__name__
__module____qualname__r   rL   __annotations__r   intr   r   BaseExceptionr   r	   r   rD   r   rF   r   rI   r   rR   propertyrX   r`   rb   rc   boolrd   rf   rg   ri   rj   rm   r!   rr   r   rt   classmethodr   r4   objectry   r1   r1   r1   r2   r5   ;   sJ   
			
)	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   RuntimeErrorrT   )r   r   rv   urlr   r1   r1   r2   _report_unserialization_failure   s    r   c                   @   s   e Zd ZdZdZdeeeee ef 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eef   ddd	d
ZedddZeedd dddZdS )
TestReportzBasic test report object (also used for setup and teardown calls if
    they fail).

    Reports can contain arbitrary extra attributes.
    Fr1   r   Nr<   z$Literal['setup', 'call', 'teardown'])r;   r8   keywordsr=   r9   r7   r:   durationstartstopuser_propertiesr?   c                 K   s^   || _ || _|| _|| _|| _|| _t|p,g | _t|| _|| _	|	| _
|
| _| j| d S r@   )r;   r8   r   r=   r9   r7   listr   r:   r   r   r   rA   rB   )rC   r;   r8   r   r=   r9   r7   r:   r   r   r   r   extrar1   r1   r2   rD      s    
zTestReport.__init__rS   c                 C   s   d | jj| j| j| jS )Nz <{} {!r} when={!r} outcome={!r}>)r,   	__class__rz   r;   r7   r=   r_   r1   r1   r2   __repr__9  s    zTestReport.__repr__zCallInfo[None])itemcallr?   c                 C   sf  |j }|dksJ |j}|j}|j}dd |jD }|j}g }	|jsNd}
d}nt|tsbd}
|}nt|jt	j
rd}
| }|dusJ d|jjr| dd	 \}}|dusJ t||d
 |jf}nt|j|j|jf}n2d}
|j dkr||}n|j||jddd}|jD ]&\}}}|	d| d| |f q| |j|j||
|||	||||jdS )zCreate and fill a TestReport with standard item and call info.

        :param item: The item.
        :param call: The call info.
        collectc                 S   s   i | ]
}|d qS )   r1   r[   xr1   r1   r2   
<dictcomp>K      z1TestReport.from_item_and_call.<locals>.<dictcomp>rd   Nrf   rg   z=There should always be a traceback entry for skipping a test.   r   r   Ztbstyleauto)stylez	Captured  )r   )r7   r   r   r   r   excinfo
isinstancer   valuer$   	ExceptionZ_getreprcrashZ_use_item_locationZ
reportinfoosri   messagerL   pathrk   Zrepr_failureZ_repr_failure_pyrn   Z	getoptionZ_report_sectionsappendr;   r8   r   )ru   r   r   r7   r   r   r   r   r   r:   r=   r9   rr   rK   ZrwhenrE   rQ   r1   r1   r2   from_item_and_call>  s`    

zTestReport.from_item_and_call)r1   r   r   r   N)rz   r{   r|   __doc__Z__test__rL   r   r   r~   r
   r   r   r   r   r   r   floatr   rD   r   r   r#   r   r1   r1   r1   r2   r      s4        
<r   c                
   @   s   e Zd ZdZdZdededee e	ee
ef eef eeeeef   ee	eef  ddddZeee	eee
 ef  d	d
dZed	ddZdS )CollectReportzSCollection report object.

    Reports can contain arbitrary extra attributes.
    r   r1   r<   N)r;   r=   r9   resultr:   r?   c                 K   s6   || _ || _|| _|pg | _t|| _| j| d S r@   )r;   r=   r9   r   r   r:   rA   rB   )rC   r;   r=   r9   r   r:   r   r1   r1   r2   rD     s    

zCollectReport.__init__rS   c                 C   s   | j d | j fS r@   )ri   r_   r1   r1   r2   r8     s    zCollectReport.locationc                 C   s   d | jt| j| jS )Nz.<CollectReport {!r} lenresult={} outcome={!r}>)r,   r;   lenr   r=   r_   r1   r1   r2   r     s    zCollectReport.__repr__)r1   )rz   r{   r|   r   r7   rL   r   r   r   r   r~   r   r   r	   r#   r"   r   rD   r   r8   r   r1   r1   r1   r2   r     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 r@   )r9   )rC   r   r1   r1   r2   rD     s    zCollectErrorRepr.__init__rG   c                 C   s   |j | jdd d S )NT)red)rK   r9   )rC   rH   r1   r1   r2   rI     s    zCollectErrorRepr.toterminal)rz   r{   r|   rL   rD   r   rI   r1   r1   r1   r2   r     s   r   )ro   r?   c                 C   s*   t | ttfr&|  }| jj|d< |S d S )N$report_type)r   r   r   rt   r   rz   )ro   datar1   r1   r2   pytest_report_to_serializable  s
    r   )r   r?   c                 C   sN   d| v rJ| d dkrt | S | d dkr4t| S dsJJ d| d d S )Nr   r   r   Fz(Unknown report_type unserialize data: {})r   ry   r   r,   )r   r1   r1   r2   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< |D ]8}t|| tjrt|| ||< q|dkrd||< q|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   sH   t | }| D ] \}}t|drt |||< qt| j|d}|S )NrA   )typer   )dataclassesasdictitemsrJ   r   rz   )r   r   rE   r   
entry_datar1   r1   r2   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 r1   r1   r   r   r1   r2   
<listcomp>  s   zE_report_to_json.<locals>.serialize_repr_traceback.<locals>.<listcomp>reprentries)r   r   r   )r   r   r   r1   r2   serialize_repr_traceback  s
    


z1_report_to_json.<locals>.serialize_repr_traceback)	reprcrashr?   c                 S   s   | d urt | S d S d S r@   )r   r   )r   r1   r1   r2   serialize_repr_crash  s    
z-_report_to_json.<locals>.serialize_repr_crash)repr?   c                    s   | j d usJ tt| j } |j|j|jd}t|trvg |d< |jD ]&\}}}|d 	| ||f qLnd |d< |S )N)r   r   r:   chain)
r9   r   r   r   r   r:   r   r   r   r   )r   r9   r   Zrepr_tracebackZ
repr_crashdescription)r   r   r1   r2   serialize_exception_longrepr  s"    
z5_report_to_json.<locals>.serialize_exception_longreprrI   r   r   r9   r   N)r   r   r   r   rL   r   r   r   r   r5   rA   copyrJ   r9   r   r   PathLikeri   )ro   r   r.   rP   r1   )r   r   r   r2   rs     s,    





rs   )rv   r?   c                    s   fdd  fdd}t tttf  ddd}d rd	d v rd
d v r|d d
 }|d d	 }d d rg }d d D ]"\}}}||||||f qt|}	nt||d}	d d D ]}
|	j|
  q|	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 i |d }|d rXtf i |d }|d rpt|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)rv   r1   r2   deserialize_repr_entry%  s.    z8_report_kwargs_from_json.<locals>.deserialize_repr_entryc                    s(    fdd| d D | d< t f i | S )Nc                    s   g | ]} |qS r1   r1   r   r   r1   r2   r   A  s   zP_report_kwargs_from_json.<locals>.deserialize_repr_traceback.<locals>.<listcomp>r   r   )Zrepr_traceback_dictr   r1   r2   deserialize_repr_traceback@  s    

z<_report_kwargs_from_json.<locals>.deserialize_repr_tracebackZrepr_crash_dictc                 S   s   | d urt f i | S d S d S r@   r   r   r1   r1   r2   deserialize_repr_crashF  s    z8_report_kwargs_from_json.<locals>.deserialize_repr_crashr9   r   r   r   )r   r   r:   )r   r   rL   r   r   r   r   Z
addsection)rv   r   r   r   r   r   Zrepr_traceback_dataZrepr_crash_datar   Zexception_infosectionr1   )r   rv   r2   rw     sH    


	rw   );r   r   ior   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$   Ztyping_extensionsr%   Z_pytest.runnerr&   r3   r4   r5   rL   r   r   r   r   r   r   rs   rw   r1   r1   r1   r2   <module>   st    , 3	

I