a
    /§»a<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�rºd 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`   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   úI/home/yuhw/wc/pochoir/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< 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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 ).r5   ÚwhenÚlocationNÚlongreprÚsectionsÚnodeid)Ú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   )rA   rC   r1   r1   r2   Ú__getattr__J   s    zBaseReport.__getattr__©Úoutr=   c                 C   s~   t | dƒr| t| jƒ¡ | j}|d u r,d S t |dƒrLtt|ƒ}| |¡ n.zt|ƒ}W n t	yn   d}Y n0 | |¡ d S )Nr-   Ú
toterminalz<unprintable longrepr>)
ÚhasattrÚliner3   r-   r9   r   r   rG   ÚstrÚUnicodeEncodeError)rA   rF   r9   Zlongrepr_terminalr0   r1   r1   r2   rG   M   s    



zBaseReport.toterminal)Úprefixr=   c                 c   s(   | j D ]\}}| |¡r||fV  qd S r>   )r:   Ú
startswith)rA   rL   ÚnameÚcontentr1   r1   r2   Ú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	hasmarkuprG   ÚgetvalueÚstrip)rA   ÚfileZtwÚexcr1   r1   r2   Ú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 r>   r1   ©Ú.0rL   rO   r1   r1   r2   Ú	<genexpr>x   s   z$BaseReport.caplog.<locals>.<genexpr>zCaptured log©ÚjoinrP   ©rA   r1   r1   r2   Ú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 r>   r1   rX   r1   r1   r2   rZ   ‚   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
        r_   c                 s   s   | ]\}}|V  qd S r>   r1   rX   r1   r1   r2   rZ   Œ   s   z'BaseReport.capstderr.<locals>.<genexpr>zCaptured stderrr[   r]   r1   r1   r2   Ú	capstderr†   s    
ÿzBaseReport.capstderrc                 C   s
   | j dkS )NÚpassed©Úoutcome©Úxr1   r1   r2   Ú<lambda>�   ó    zBaseReport.<lambda>c                 C   s
   | j dkS )NÚfailedrc   re   r1   r1   r2   rg   ‘   rh   c                 C   s
   | j dkS )NÚskippedrc   re   r1   r1   r2   rg   ’   rh   c                 C   s   | j  d¡d S )Nz::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   )rA   rl   ÚlinenoÚdomainr1   r1   r2   Ú	head_line¤   s    
zBaseReport.head_line)Úconfigc                 C   s   |j j| |d�\}}}|S )N)Úreportrq   )ÚhookZpytest_report_teststatus)rA   rq   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)rx   ry   Úkwargsr1   r1   r2   Ú
_from_jsonÉ   s    
zBaseReport._from_json)*Ú__name__Ú
__module__Ú__qualname__r   rJ   Ú__annotations__r   Úintr   r   ÚBaseExceptionr   r
   r   rB   r   rD   r   rG   r	   rP   ÚpropertyrV   r^   r`   ra   rb   ri   rj   rl   Úboolrm   rp   r    ru   r   rw   Úclassmethodr   r4   Úobjectr|   r1   r1   r1   r2   r5   <   sB   
ÿ			
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   ÚRuntimeErrorrR   )r‡   rˆ   ry   Ú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 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).Fr1   r   Nz&Literal['passed', 'failed', 'skipped']z$Literal['setup', 'call', 'teardown'])	r;   r8   rd   r9   r7   r:   ÚdurationÚuser_propertiesr=   c
                 K   sR   || _ || _|| _|| _|| _|| _t|	p,g ƒ| _t|ƒ| _|| _	| j
 |
¡ d S r>   )r;   r8   Úkeywordsrd   r9   r7   Úlistr�   r:   rŽ   r?   r@   )rA   r;   r8   r�   rd   r9   r7   r:   rŽ   r�   Úextrar1   r1   r2   rB   ì   s    
zTestReport.__init__rQ   c                 C   s   d  | jj| j| j| j¡S )Nz <{} {!r} when={!r} outcome={!r}>)r,   Ú	__class__r}   r;   r7   rd   r]   r1   r1   r2   Ú__repr__  s    ÿzTestReport.__repr__zCallInfo[None])ÚitemÚcallr=   c                 C   s  |j }|dksJ ‚|j}dd„ |jD ƒ}|j}g }|jsBd}d}	nvt|tƒsVd}|}	nbt|jtjƒr†d}| 	¡ }
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.Úcollectc                 S   s   i | ]
}|d “qS )é   r1   ©rY   rf   r1   r1   r2   Ú
<dictcomp>+  rh   z1TestReport.from_item_and_call.<locals>.<dictcomp>rb   Nri   rj   r–   ZtbstyleÚauto)Ústylez	Captured ú )r�   )r7   rŽ   r�   ÚexcinfoÚ
isinstancer   Úvaluer#   Ú	ExceptionZ_getreprcrashrJ   Úpathrn   ÚmessageZrepr_failureZ_repr_failure_pyrq   Z	getoptionZ_report_sectionsÚappendr;   r8   r�   )rx   r•   r–   r7   rŽ   r�   rž   r:   rd   r9   ÚrZrwhenrC   rO   r1   r1   r2   Úfrom_item_and_call$  sH    ú

ÿ÷zTestReport.from_item_and_call)r1   r   N)r}   r~   r   Ú__doc__Z__test__rJ   r   r   r�   r   r   r‚   r   r   Úfloatr†   rB   r”   r…   r"   r¦   r1   r1   r1   r2   r�   å   s*      ôÿò3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—   r1   z&Literal['passed', 'skipped', 'failed']N)r;   rd   Úresultr:   r=   c                 K   s6   || _ || _|| _|pg | _t|ƒ| _| j |¡ d S r>   )r;   rd   r9   rª   r‘   r:   r?   r@   )rA   r;   rd   r9   rª   r:   r’   r1   r1   r2   rB   \  s    


zCollectReport.__init__c                 C   s   | j d | j fS r>   )rl   r]   r1   r1   r2   r8   z  s    zCollectReport.locationrQ   c                 C   s   d  | jt| jƒ| j¡S )Nz.<CollectReport {!r} lenresult={} outcome={!r}>)r,   r;   Úlenrª   rd   r]   r1   r1   r2   r”   ~  s    ÿzCollectReport.__repr__)r1   )r}   r~   r   r§   r7   rJ   r   r
   r   r"   r!   r   r   rB   rƒ   r8   r”   r1   r1   r1   r2   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 r>   )r9   )rA   r­   r1   r1   r2   rB   …  s    zCollectErrorRepr.__init__rE   c                 C   s   |j | jdd� d S )NT)Zred)rI   r9   )rA   rF   r1   r1   r2   rG   ˆ  s    zCollectErrorRepr.toterminal)r}   r~   r   rJ   rB   r   rG   r1   r1   r1   r2   r¬   „  s   r¬   )rr   r=   c                 C   s*   t | ttfƒr&|  ¡ }| jj|d< |S d S )Nú$report_type)rŸ   r�   r©   rw   r“   r}   )rr   Ú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�   r|   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 ]>}t|| tjjtfƒ�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 )Nr?   )Útyper¯   )ÚattrÚasdictÚitemsrH   r³   r}   )r²   r¯   rC   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_longreprrG   r¹   r¾   r9   rª   N)r   r   r   r   rJ   r   r   r   r   r5   r?   ÚcopyrH   r9   rŸ   Úpyr¢   Úlocalr   )rr   rÃ   r.   rN   r1   )r¿   r¸   r½   r2   rv   ¥  s,    

þ
þ
ÿ

rv   )ry   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 ]}
|	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)ry   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»     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_crash  s    z8_report_kwargs_from_json.<locals>.deserialize_repr_crashr9   r¾   r¹   rÁ   r:   )r   r   rJ   r   r¤   r   r   Z
addsection)ry   rÍ   rÏ   r¹   r¾   rÁ   Zrepr_traceback_dataZrepr_crash_datarÂ   Zexception_infoÚsectionr1   )rË   ry   r2   rz   î  sB    ÿ
þ
ý
ÿÿþýÿ	þ
rz   )<Ú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&   r3   r4   r5   rJ   rŒ   r�   r©   r¬   r°   r±   rv   rz   r1   r1   r1   r2   Ú<module>   sr    þp-	
þ
þI