o
    hS                     @  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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 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-G d$d% d%Z.dCd,d-Z/eG d.d/ d/e.Z0eG d0d1 d1e.Z1G d2d3 d3eZ2dDd7d8Z3dEd<d=Z4dFd>d?Z5dGdAdBZ6dS )H    )annotations)Iterable)Iterator)Mapping)SequenceN)StringIO)pprint)Any)cast)final)Literal)NoReturn)TYPE_CHECKING)ExceptionChainRepr)ExceptionInfo)ExceptionRepr)	ReprEntry)ReprEntryNative)ReprExceptionInfoReprFileLocation)ReprFuncArgs)
ReprLocalsReprTraceback)TerminalRepr)TerminalWriter)Config)	Collector)Item)fail)skip)Self)CallInfoc              
   C  s^   z| j W S  ty.   | j}dj|d d d  }d|d |d ||d  | _ }| Y S w )Nz{}.{}.{}version_info   z[{}] {} -- Python {} {}idsysplatform
executable)_workerinfocacheAttributeError
workerinfoformat)nodedvers r1   P/var/www/html/openai_agents/venv/lib/python3.10/site-packages/_pytest/reports.pygetworkerinfoline,   s   
r3   c                   @  s  e Zd ZU ded< ded< ded< ded< d	ed
< ded< dCddZer)dDddZdEddZdFddZe	dGddZ
e	dGd d!Ze	dGd"d#Ze	dGd$d%Ze	dHd'd(Ze	dHd)d*Ze	dHd+d,Ze	dGd-d.Ze	dHd/d0Ze	dId1d2ZdJd8d9ZdKd;d<ZedLd@dAZdBS )M
BaseReport
str | Nonewhen"tuple[str, int | None, str] | NonelocationONone | ExceptionInfo[BaseException] | tuple[str, int, str] | str | TerminalReprlongreprzlist[tuple[str, str]]sectionsstrnodeid&Literal['passed', 'failed', 'skipped']outcomekwr	   returnNonec                 K  s   | j | d S N)__dict__update)selfr@   r1   r1   r2   __init__B   s   zBaseReport.__init__keyc                 C  s   d S rC   r1   )rF   rH   r1   r1   r2   __getattr__G   s    zBaseReport.__getattr__outr   c                 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 )Nr-   
toterminalz<unprintable longrepr>)
hasattrr3   r-   liner:   r
   r   rK   r<   UnicodeEncodeError)rF   rJ   worker_infor:   longrepr_terminalr0   r1   r1   r2   rK   I   s    




zBaseReport.toterminalprefixIterator[tuple[str, str]]c                 c  s*    | j D ]\}}||r||fV  qd S rC   )r;   
startswith)rF   rQ   namecontentr1   r1   r2   get_sections]   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excr1   r1   r2   longreprtextb   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   r1   .0rQ   rU   r1   r1   r2   	<genexpr>v       
z$BaseReport.caplog.<locals>.<genexpr>zCaptured logjoinrV   rF   r1   r1   r2   caplogp      
zBaseReport.caplogc                 C  r^   )zbReturn captured text from stdout, if capturing is enabled.

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

        .. versionadded:: 3.0
        rj   c                 s  r`   rC   r1   ra   r1   r1   r2   rc      rd   z'BaseReport.capstderr.<locals>.<genexpr>zCaptured stderrre   rg   r1   r1   r2   	capstderr   ri   zBaseReport.capstderrboolc                 C  
   | j dkS )zWhether the outcome is passed.passedr?   rg   r1   r1   r2   ro         
zBaseReport.passedc                 C  rn   )zWhether the outcome is failed.failedrp   rg   r1   r1   r2   rr      rq   zBaseReport.failedc                 C  rn   )zWhether the outcome is skipped.skippedrp   rg   r1   r1   r2   rs      rq   zBaseReport.skippedc                 C  s   | j dd S )z3The path portion of the reported node, as a string.z::r   )r=   splitrg   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   rg   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   )rF   ru   linenodomainr1   r1   r2   	head_line   s   
zBaseReport.head_lineconfigr   default_markupMapping[str, bool]tuple[str, Mapping[str, bool]]c                 C  sv   |j j| |d\}}}t|tr||fS t|tr1t|dkr1|\}}t|tr1t|tr1||fS td|d d S )N)reportrz      zSpytest_report_teststatus() hook (from a plugin) returned an invalid verbose value: z8.
Expected either a string or a tuple of (word, markup).)hookpytest_report_teststatus
isinstancer<   r   lenr   r    )rF   rz   r{   	_category_shortverbosewordmarkupr1   r1   r2   _get_verbose_word_with_markup   s   
z(BaseReport._get_verbose_word_with_markupdict[str, Any]c                 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   r1   r1   r2   _to_json   s   zBaseReport._to_json
reportdictdict[str, object]r"   c                 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.
        Nr1   )_report_kwargs_from_json)clsr   kwargsr1   r1   r2   
_from_json   s   
zBaseReport._from_jsonN)r@   r	   rA   rB   )rH   r<   rA   r	   rJ   r   rA   rB   )rQ   r<   rA   rR   rA   r<   )rA   rm   )rA   r5   )rz   r   r{   r|   rA   r}   )rA   r   )r   r   rA   r"   )__name__
__module____qualname____annotations__rG   r   rI   rK   rV   propertyr]   rh   rk   rl   ro   rr   rs   ru   rv   ry   r   r   classmethodr   r1   r1   r1   r2   r4   8   sH   
 



			


r4   	type_namer<   report_classtype[BaseReport]rA   r   c                 C  sp   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: zreport_name: zPlease report this bug at )r   r   RuntimeErrorrX   )r   r   r   urlr   r1   r1   r2   _report_unserialization_failure   s   r   c                   @  sL   e Zd ZU dZdZded< 					d'd(ddZd)dd Ze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.
    Fr<   wasxfailr1   r   Nr=   r8   tuple[str, int | None, str]keywordsMapping[str, Any]r?   r>   r:   r9   r6   $Literal['setup', 'call', 'teardown']r;   Iterable[tuple[str, str]]durationfloatstartstopuser_properties#Iterable[tuple[str, object]] | NonerA   rB   c                 K  s^   || _ || _|| _|| _|| _|| _t|pg | _t|| _|| _	|	| _
|
| _| j| d S rC   )r=   r8   r   r?   r:   r6   listr   r;   r   r   r   rD   rE   )rF   r=   r8   r   r?   r:   r6   r;   r   r   r   r   extrar1   r1   r2   rG     s   
zTestReport.__init__c              	   C  s(   d| j j d| jd| jd| jd	S )N< z when=	 outcome=>)	__class__r   r=   r6   r?   rg   r1   r1   r2   __repr__J  s   (zTestReport.__repr__itemr   call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 )   r1   rb   xr1   r1   r2   
<dictcomp>Z  s    z1TestReport.from_item_and_call.<locals>.<dictcomp>ro   Nrr   rs   z=There should always be a traceback entry for skipping a test.r   r   r   tbstyleauto)stylez	Captured r   )r   )r6   r   r   r   r   excinfor   r   valuer!   	Exception_getreprcrash_use_item_location
reportinfoosru   messager<   pathrw   repr_failure_repr_failure_pyrz   	getoption_report_sectionsappendr=   r8   r   )r   r   r   r6   r   r   r   r   r   r;   r?   r:   rr   rM   rwhenrH   rU   r1   r1   r2   from_item_and_callM  s^   


zTestReport.from_item_and_call)r1   r   r   r   N)r=   r<   r8   r   r   r   r?   r>   r:   r9   r6   r   r;   r   r   r   r   r   r   r   r   r   rA   rB   r   )r   r   r   r   rA   r   )
r   r   r   __doc____test__r   rG   r   r   r   r1   r1   r1   r2   r      s   
 
>r   c                   @  s:   e Zd ZdZdZ	ddddZedddZdddZdS )CollectReportzSCollection report object.

    Reports can contain arbitrary extra attributes.
    r   r1   r=   r<   r?   r>   r:   r9   resultlist[Item | Collector] | Noner;   r   rA   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   r1   r1   r2   rG     s   

zCollectReport.__init__r7   c                 C  s   | j d | j fS rC   )ru   rg   r1   r1   r2   r8     s   zCollectReport.locationc                 C  s"   d| j dt| j d| jdS )Nz<CollectReport z lenresult=r   r   )r=   r   r   r?   rg   r1   r1   r2   r     s   "zCollectReport.__repr__N)r1   )r=   r<   r?   r>   r:   r9   r   r   r;   r   rA   rB   )rA   r7   r   )	r   r   r   r   r6   rG   r   r8   r   r1   r1   r1   r2   r     s    !r   c                   @  s    e Zd ZdddZdd	d
ZdS )CollectErrorReprmsgr<   rA   rB   c                 C  s
   || _ d S rC   )r:   )rF   r   r1   r1   r2   rG     s   
zCollectErrorRepr.__init__rJ   r   c                 C  s   |j | jdd d S )NT)red)rM   r:   )rF   rJ   r1   r1   r2   rK     s   zCollectErrorRepr.toterminalN)r   r<   rA   rB   r   )r   r   r   rG   rK   r1   r1   r1   r2   r     s    
r   r~   CollectReport | TestReportdict[str, Any] | Nonec                 C  s*   t | ttfr|  }| jj|d< |S d S )N$report_type)r   r   r   r   r   r   )r~   datar1   r1   r2   pytest_report_to_serializable  s
   r   r   r   !CollectReport | TestReport | Nonec                 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   r1   r1   r2   pytest_report_from_serializable  s   

r   c                   s   ddddfd	d
ddd d fdd}| j  }t| jdr?t| jdr7t| jdr7|| |d< nt| j|d< n| j|d< |D ]}t|| tjrZt|| ||< qF|dkrbd||< qF|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).
    entryReprEntry | ReprEntryNativerA   r   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_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                      g | ]} |qS r1   r1   r   r   r1   r2   
<listcomp>      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	reprcrashReprFileLocation | Noner   c                 S  s   | d ur	t | S d S rC   )r   r   )r   r1   r1   r2   serialize_repr_crash  s   
z-_report_to_json.<locals>.serialize_repr_crashrepr4   c                   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   r1   r2   serialize_exception_longrepr  s$   
	z5_report_to_json.<locals>.serialize_exception_longreprrK   r:   r   N)r   r   rA   r   )r   r   rA   r   )r   r   rA   r   )r   r4   rA   r   )	rD   copyrL   r:   r<   r   r   PathLikeru   )r~   r   r.   rT   r1   )r   r   r   r2   r     s&   




r   r   c                   s   fdd  fdd}ddd}d	 rnd
d	 v rndd	 v rn|d	 d }|d	 d
 }d	 d rVg }d	 d D ]\}}}| |||||f q?t|}	nt||d}	d	 d D ]}
|	j|
  qb|	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   r1   )r   r   r   r   r   r   r   )r   r   
entry_typer   r   r   	reprentry)r   r1   r2   deserialize_repr_entry4  s2   z8_report_kwargs_from_json.<locals>.deserialize_repr_entryc                   s(    fdd| d D | d< t di | S )Nc                   r   r1   r1   r   r  r1   r2   r   P  r   zP_report_kwargs_from_json.<locals>.deserialize_repr_traceback.<locals>.<listcomp>r   r1   r   )repr_traceback_dictr  r1   r2   deserialize_repr_tracebackO  s   

z<_report_kwargs_from_json.<locals>.deserialize_repr_tracebackrepr_crash_dictr   c                 S  s   | d urt di | S d S )Nr1   r   )r  r1   r1   r2   deserialize_repr_crashU  s   z8_report_kwargs_from_json.<locals>.deserialize_repr_crashr:   r   r   r   )r   r   r;   N)r  r   )r   r   r   
addsection)r   r  r  r   r   r   repr_traceback_datarepr_crash_datar   exception_infosectionr1   )r  r   r2   r   -  sF   

r   )r   r<   r   r   rA   r   )r~   r   rA   r   )r   r   rA   r   )r~   r4   rA   r   )r   r   rA   r   )7
__future__r   collections.abcr   r   r   r   r   ior   r   r   typingr	   r
   r   r   r   r   _pytest._code.coder   r   r   r   r   r   r   r   r   r   r   _pytest._ior   _pytest.configr   _pytest.nodesr   r   _pytest.outcomesr    r!   typing_extensionsr"   _pytest.runnerr#   r3   r4   r   r   r   r   r   r   r   r   r1   r1   r1   r2   <module>   sb    
9 3


I