o
    hhQ                     @   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(Z1d+e2d,ee1 d-efd.d/Z3e#G d0d1 d1e1Z4e#G d2d3 d3e1Z5G d4d5 d5eZ6d6ee5e4f d-eee2ef  fd7d8Z7d9ee2ef d-eee5e4f  fd:d;Z8d6e1d-ee2ef fd<d=Z9d>ee2ef d-ee2ef fd?d@Z:dS )A    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y-   | j}d|d d d  }d|d |d ||d  | _ }| Y S w )Nz%s.%s.%sversion_info   z[{}] {} -- Python {} {}idsysplatform
executable)_workerinfocacheAttributeError
workerinfoformat)nodedvers r4   E/var/www/html/ai/venv/lib/python3.10/site-packages/_pytest/reports.pygetworkerinfoline,   s   
r6   _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< d	ed
dfddZerPded
efddZded
dfddZded
eeeef  fddZed
efddZed
efddZed
efddZed
efddZed
efddZed
efd d!Zed
efd"d#Zed
efd$d%Zed
efd&d'Zed
ee fd(d)Z d*e!fd+d,Z"d
e#eef fd-d.Z$e%d/e&e' d0e#ee(f d
e'fd1d2Z)dS )3r8   whenlocationNlongreprsectionsnodeid&Literal['passed', 'failed', 'skipped']outcomekwreturnc                 K   s   | j | d S N)__dict__update)selfrA   r4   r4   r5   __init__E   s   zBaseReport.__init__keyc                 C   s   d S rC   r4   )rF   rH   r4   r4   r5   __getattr__J   s   zBaseReport.__getattr__outc                 C   s   t | drt| j}|r|| | j}|d u rd S t |dr+tt|}|| d S zt|}W n t	y<   d}Y nw || d S )Nr0   
toterminalz<unprintable longrepr>)
hasattrr6   r0   liner<   r   r   rK   strUnicodeEncodeError)rF   rJ   worker_infor<   longrepr_terminalr3   r4   r4   r5   rK   M   s    




zBaseReport.toterminalprefixc                 c   s*    | j D ]\}}||r||fV  qd S rC   )r=   
startswith)rF   rR   namecontentr4   r4   r5   get_sectionsa   s   

zBaseReport.get_sectionsc                 C   s.   t  }t|}d|_| | | }| S )zRead-only property that returns the full string representation of
        ``longrepr``.

        .. versionadded:: 3.0
        F)r   r   	hasmarkuprK   getvaluestrip)rF   filetwexcr4   r4   r5   longreprtextf   s   
zBaseReport.longreprtextc                 C      d dd | dD S )z_Return captured log lines, if log capturing is enabled.

        .. versionadded:: 3.5
        
c                 s       | ]\}}|V  qd S rC   r4   .0rR   rU   r4   r4   r5   	<genexpr>z       
z$BaseReport.caplog.<locals>.<genexpr>zCaptured logjoinrV   rF   r4   r4   r5   caplogt      
zBaseReport.caplogc                 C   r^   )zbReturn captured text from stdout, if capturing is enabled.

        .. versionadded:: 3.0
         c                 s   r`   rC   r4   ra   r4   r4   r5   rc      rd   z'BaseReport.capstdout.<locals>.<genexpr>zCaptured stdoutre   rg   r4   r4   r5   	capstdout~   ri   zBaseReport.capstdoutc                 C   r^   )zbReturn captured text from stderr, if capturing is enabled.

        .. versionadded:: 3.0
        rj   c                 s   r`   rC   r4   ra   r4   r4   r5   rc      rd   z'BaseReport.capstderr.<locals>.<genexpr>zCaptured stderrre   rg   r4   r4   r5   	capstderr   ri   zBaseReport.capstderrc                 C   
   | j dkS )zWhether the outcome is passed.passedr@   rg   r4   r4   r5   rn         
zBaseReport.passedc                 C   rm   )zWhether the outcome is failed.failedro   rg   r4   r4   r5   rq      rp   zBaseReport.failedc                 C   rm   )zWhether the outcome is skipped.skippedro   rg   r4   r4   r5   rr      rp   zBaseReport.skippedc                 C   s   | j dd S )z3The path portion of the reported node, as a string.z::r   )r>   splitrg   r4   r4   r5   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.
        Tr4   rg   r4   r4   r5   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)r;   )rF   rt   linenodomainr4   r4   r5   	head_line   s   
zBaseReport.head_lineconfigc                 C   s   |j j| |d\}}}|S )N)reportry   )hookpytest_report_teststatus)rF   ry   	_category_shortverboser4   r4   r5   _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_jsonrg   r4   r4   r5   _to_json   s   zBaseReport._to_jsoncls
reportdictc                 C   s   t |}| d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.
        Nr4   )_report_kwargs_from_json)r   r   kwargsr4   r4   r5   
_from_json   s   
zBaseReport._from_json)*__name__
__module____qualname__r   rN   __annotations__r   intr   r   BaseExceptionr   r	   r   rG   r   rI   r   rK   r   rV   propertyr]   rh   rk   rl   boolrn   rq   rr   rt   ru   rx   r!   r   r   r   classmethodr   r7   objectr   r4   r4   r4   r5   r8   ;   sL   
 			
(	type_namereport_classrB   c                 C   sj   d}t  }td|d td|  |d td| |d t||d td| |d td|d t| )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   RuntimeErrorrX   )r   r   r   urlr   r4   r4   r5   _report_unserialization_failure   s   r   c                   @   s   e Zd ZdZdZ					ddedeeee ef de	ee
f d	d
dedee eeeef eef dddeeeef  dedededeeeeef   ddfddZdefddZededddd f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.
    Fr4   r   Nr>   r;   keywordsr@   r?   r<   r:   z$Literal['setup', 'call', 'teardown']r=   durationstartstopuser_propertiesrB   c                 K   s^   || _ || _|| _|| _|| _|| _t|pg | _t|| _|| _	|	| _
|
| _| j| d S rC   )r>   r;   r   r@   r<   r:   listr   r=   r   r   r   rD   rE   )rF   r>   r;   r   r@   r<   r:   r=   r   r   r   r   extrar4   r4   r5   rG      s   
zTestReport.__init__c                 C   s   d | jj| j| j| jS )Nz <{} {!r} when={!r} outcome={!r}>)r/   	__class__r   r>   r:   r@   rg   r4   r4   r5   __repr__9  s   zTestReport.__repr__itemcallzCallInfo[None]c                 C   sd  |j }|dks	J |j}|j}|j}dd |jD }|j}g }	|js'd}
d}nct|ts1d}
|}nYt|jt	j
rqd}
| }|dusFJ d|jjrf| dd	 \}}|dusZJ t||d
 |jf}n$t|j|j|jf}nd}
|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 )   r4   rb   xr4   r4   r5   
<dictcomp>K  s    z1TestReport.from_item_and_call.<locals>.<dictcomp>rn   Nrq   rr   z=There should always be a traceback entry for skipping a test.   r   r   tbstyleauto)stylez	Captured  )r   )r:   r   r   r   r   excinfo
isinstancer   valuer$   	Exception_getreprcrash_use_item_location
reportinfoosrt   messagerN   pathrv   repr_failure_repr_failure_pyry   	getoption_report_sectionsappendr>   r;   r   )r   r   r   r:   r   r   r   r   r   r=   r@   r<   rr   rM   rwhenrH   rU   r4   r4   r5   from_item_and_call>  s^   


zTestReport.from_item_and_call)r4   r   r   r   N)r   r   r   __doc____test__rN   r   r   r   r
   r   r   r   r   r   r   floatr   rG   r   r   r#   r   r4   r4   r4   r5   r      sL    
	

<r   c                   @   s   e Zd ZdZdZ	ddedddedee e	ee
ef eef d	eeeeef   d
ee	eef  ddfddZedee	eee
 ef  fddZdefddZdS )CollectReportzSCollection report object.

    Reports can contain arbitrary extra attributes.
    r   r4   r>   r@   r?   r<   Nresultr=   rB   c                 K   s6   || _ || _|| _|pg | _t|| _| j| d S rC   )r>   r@   r<   r   r   r=   rD   rE   )rF   r>   r@   r<   r   r=   r   r4   r4   r5   rG     s   

zCollectReport.__init__c                 C   s   | j d | j fS rC   )rt   rg   r4   r4   r5   r;     s   zCollectReport.locationc                 C   s   d | jt| j| jS )Nz.<CollectReport {!r} lenresult={} outcome={!r}>)r/   r>   lenr   r@   rg   r4   r4   r5   r     s   zCollectReport.__repr__)r4   )r   r   r   r   r:   rN   r   r   r   r   r   r   r   r	   r#   r"   r   rG   r   r;   r   r4   r4   r4   r5   r     s0    


r   c                   @   s0   e Zd ZdeddfddZdeddfddZdS )	CollectErrorReprmsgrB   Nc                 C   s
   || _ d S rC   )r<   )rF   r   r4   r4   r5   rG     s   
zCollectErrorRepr.__init__rJ   c                 C   s   |j | jdd d S )NT)red)rM   r<   )rF   rJ   r4   r4   r5   rK     s   zCollectErrorRepr.toterminal)r   r   r   rN   rG   r   rK   r4   r4   r4   r5   r     s    r   rz   c                 C   s*   t | ttfr|  }| jj|d< |S d S )N$report_type)r   r   r   r   r   r   )rz   datar4   r4   r5   pytest_report_to_serializable  s
   r   r   c                 C   sJ   d| v r#| d dkrt | S | d dkrt| S J d| d d S )Nr   r   r   Fz(Unknown report_type unserialize data: {})r   r   r   r/   )r   r4   r4   r5   pytest_report_from_serializable  s   

r   c                    s  dt ttf dtttf fdddtdtttf ffdddtt dttttf  fd	d
 dt	dtttf f fdd}| j
 }t| jdrgt| jdr_t| jdr_|| |d< nt| j|d< n| j|d< |D ]}t|| tjrt|| ||< qn|dkrd||< qn|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).
    entryrB   c                 S   sH   t | }| D ]\}}t|drt |||< q	t| j|d}|S )NrD   )typer   )dataclassesasdictitemsrL   r   r   )r   r   rH   r   
entry_datar4   r4   r5   serialize_repr_entry  s   

z-_report_to_json.<locals>.serialize_repr_entryreprtracebackc                    s&   t | } fdd| jD |d< |S )Nc                       g | ]} |qS r4   r4   r   r   r4   r5   
<listcomp>      zE_report_to_json.<locals>.serialize_repr_traceback.<locals>.<listcomp>reprentries)r   r   r   )r   r   r   r4   r5   serialize_repr_traceback  s
   


z1_report_to_json.<locals>.serialize_repr_traceback	reprcrashc                 S   s   | d ur	t | S d S rC   )r   r   )r   r4   r4   r5   serialize_repr_crash  s   
z-_report_to_json.<locals>.serialize_repr_crashrepc                    s   | j d usJ tt| j } |j|j|jd}t|tr<g |d< |jD ]\}}}|d 	| ||f q&|S d |d< |S )N)r   r   r=   chain)
r<   r   r   r   r   r=   r   r   r   r   )r   r<   r   repr_traceback
repr_crashdescription)r   r   r4   r5   serialize_exception_longrepr  s$   
	z5_report_to_json.<locals>.serialize_exception_longreprrK   r<   r   N)r   r   r   r   rN   r   r   r   r   r8   rD   copyrL   r<   r   r   PathLikert   )rz   r   r1   rT   r4   )r   r   r   r5   r     s6   




 

r   r   c                    s   fdd  fdd}dt tttf  fdd}d rvd	d v rvd
d v rv|d d
 }|d d	 }d d r^g }d d D ]\}}}||||||f qGt|}	nt||d}	d d D ]}
|	j|
  qj|	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rGd }d }d }|d rt di |d }|d r,tdi |d }|d r8t|d d }t|d ||||d d	}|S |d
krSt|d }|S t|t  |S )Nr   r   r   reprfuncargsreprfileloc
reprlocalslinesr   )r   r   r   r   r   r   r4   )r   r   r   r   r   r   r   )r   r   
entry_typer   r   r   	reprentry)r   r4   r5   deserialize_repr_entry%  s2   z8_report_kwargs_from_json.<locals>.deserialize_repr_entryc                    s(    fdd| d D | d< t di | S )Nc                    r   r4   r4   r   r   r4   r5   r   A  r   zP_report_kwargs_from_json.<locals>.deserialize_repr_traceback.<locals>.<listcomp>r   r4   r   )repr_traceback_dictr   r4   r5   deserialize_repr_traceback@  s   

z<_report_kwargs_from_json.<locals>.deserialize_repr_tracebackrepr_crash_dictc                 S   s   | d urt di | S d S )Nr4   r   )r   r4   r4   r5   deserialize_repr_crashF  s   z8_report_kwargs_from_json.<locals>.deserialize_repr_crashr<   r   r   r   )r   r   r=   )r   r   rN   r   r   r   r   
addsection)r   r   r   r   r   r   repr_traceback_datarepr_crash_datar   exception_infosectionr4   )r   r   r5   r     sD   
	r   );r   r   ior   r   typingr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   _pytest._code.coder   r   r   r   r   r   r   r   r   r   r   _pytest._ior   _pytest.compatr    _pytest.configr!   _pytest.nodesr"   r#   _pytest.outcomesr$   typing_extensionsr%   _pytest.runnerr&   r6   r7   r8   rN   r   r   r   r   r   r   r   r   r4   r4   r4   r5   <module>   s     +
 3



&I