a
    ˆÏ?ehQ  ã                   @   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�rºd 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   úR/home/yuhw/wc/wire-cell-python/wcpy/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rœe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 )zÞReturn 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 )Ú
TestReportz�Basic 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}nÆt|tƒsbd}
|}n²t|jt	j
ƒrâd}
| ¡ }|dusŒJ dƒ‚|jjrÌ| ¡ dd	… \}}|dus´J ‚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 )z‹Create 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)Z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ƒrÆt| jdƒr¶t| jdƒr¶|| ƒ|d< qÐt| jƒ|d< n
| j|d< |D ]8}t|| tjƒrüt || ¡||< qÔ|dkrÔd||< qÔ|S )z´Return 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 rìd	ˆd v rìd
ˆd v rì|ˆd d
 ƒ}|ˆd d	 ƒ}ˆd d r¼g }ˆd d D ]"\}}}| ||ƒ||ƒ|f¡ qŽt|ƒ}	nt||d�}	ˆd d D ]}
|	j|
Ž  qÔ|	ˆd< ˆS )z­Return **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rŒd }d }d }|d r>t f i |d ¤Ž}|d rXtf i |d ¤Ž}|d rpt|d d ƒ}t|d ||||d d	�}n"|d
kr¢t|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