B
    ”Ü‡\á'  ã            	   @   s,  d 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„ Zdd„ Zedddd„ ƒZedddd„ ƒZdd„ Zdd„ Zedddd„ ƒZdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zeeed-ƒed-ƒeeed.ƒed/ƒd0œZd1S )2z/ support for skip/xfail functions and markers. é    )Úabsolute_import)Údivision)Úprint_function)Úhookimpl)ÚMarkEvaluator)Úfail)Úskip)Úxfailc             C   s4   |   d¡}|jdddddd | jdd	dd
d d S )NZgeneralz
--runxfailÚ
store_trueÚrunxfailFz'run tests even if they are marked xfail)ÚactionÚdestÚdefaultÚhelpÚxfail_strictz\default for the strict parameter of xfail markers when not given explicitly (default: False)Úbool)r   Útype)ZgetgroupZ	addoptionZaddini)ÚparserÚgroup© r   ú/lib/python3.7/site-packages/_pytest/skipping.pyÚpytest_addoption   s    
r   c                sp   | j jrHdd l‰ˆj‰ | j ‡ ‡fdd„¡ dd„ }tj|_tˆd|ƒ |  dd¡ |  dd	¡ |  dd
¡ d S )Nr   c                  s   t ˆdˆ ƒS )Nr	   )Úsetattrr   )ÚoldÚpytestr   r   Ú<lambda>&   s    z"pytest_configure.<locals>.<lambda>c              _   s   d S )Nr   )ÚargsÚkwargsr   r   r   Únop(   s    zpytest_configure.<locals>.nopr	   Zmarkersz‘skip(reason=None): skip the given test function with an optional reason. Example: skip(reason="no way of currently testing this") skips the test.a   skipif(condition): skip the given test function if eval(condition) results in a True value.  Evaluation happens within the module global context. Example: skipif('sys.platform == "win32"') skips the test if we are on the win32 platform. see https://docs.pytest.org/en/latest/skipping.htmlaÓ  xfail(condition, reason=None, run=True, raises=None, strict=False): mark the test function as an expected failure if eval(condition) has a True value. Optionally specify a reason for better reporting and run=False if you don't even want to execute the test function. If only specific exception(s) are expected, you can list them in raises, and if the test fails in other ways, it will be reported as a true failure. See https://docs.pytest.org/en/latest/skipping.html)	Úoptionr   r   r	   Z_cleanupÚappendÚ	Exceptionr   Zaddinivalue_line)Úconfigr   r   )r   r   r   Úpytest_configure    s     r#   T)Ztryfirstc             C   s–   d| _ t| dƒ}| ¡ r*d| _ t| ¡ ƒ xR| jddD ]B}d| _ d|jkr\t|jd ƒ q8|jrrt|jd ƒ q8tdƒ q8W t| d	ƒ| _t	| ƒ d S )
NFZskipifTr   )ÚnameÚreasonr   zunconditional skipr	   )
Ú_skipped_by_markr   Úistruer   ÚgetexplanationZiter_markersr   r   Ú
_evalxfailÚcheck_xfail_no_run)ÚitemZeval_skipifZ	skip_infor   r   r   Úpytest_runtest_setupH   s    

r,   )Zhookwrapperc             c   s(   t | ƒ d V }|jd k}|r$t| ƒ d S )N)r*   ÚexcinfoÚcheck_strict_xfail)Ú
pyfuncitemÚoutcomeÚpassedr   r   r   Úpytest_pyfunc_call^   s
    
r2   c             C   s8   | j jjs4| j}| ¡ r4| dd¡s4td| ¡  ƒ dS )zcheck xfail(run=False)ÚrunTz	[NOTRUN] N)r"   r   r   r)   r'   Úgetr	   r(   )r+   Ú	evalxfailr   r   r   r*   g   s
    
r*   c             C   sJ   | j }| ¡ rF| j d¡}| d|¡}|rF| ` | ¡ }td| dd dS )z3check xfail(strict=True) for the given PASSING testr   Ústrictz[XPASS(strict)] F)ZpytraceN)r)   r'   r"   Úgetinir4   r(   r   )r/   r5   Ústrict_defaultÚis_strict_xfailÚexplanationr   r   r   r.   p   s    r.   c             c   sª  d V }|  ¡ }t| dd ƒ}t| dƒrv|jdkrvddlm} | jrPd | j¡|_nd|_|ƒ rdd|_	nd	|_	|j|_
n0| jjjr„n"|jr°|j tj¡r°d
|jjj |_
d|_	nö|rV|jsV| ¡ rV| ¡ rV|jr| |jj¡rðd|_	nd|_	| ¡ |_
nR|jdkr¦| j d¡}| d|¡}| ¡ }|rHd|_	d |¡|_nd	|_	||_
nPt| ddƒr¦|jr¦t|jƒtkr¦|j\}	}
}| jd d… \}	}
|	|
|f|_d S )Nr)   Ú_unexpectedsuccessÚcallr   )Ú)_is_unittest_unexpected_success_a_failurezUnexpected success: {}zUnexpected successÚfailedr1   zreason: Úskippedr   r6   z[XPASS(strict)] {}r&   Fé   )Z
get_resultÚgetattrÚhasattrÚwhenZ_pytest.compatr=   r;   ÚformatÚlongreprr0   Úwasxfailr"   r   r   r-   Zerrisinstancer	   r!   ÚvalueÚmsgr?   Zwasvalidr'   Zinvalidraiser(   r7   r4   r   ÚtupleÚlocation)r+   r<   r0   Úrepr5   r=   r8   r9   r:   ÚfilenameÚliner%   r   r   r   Úpytest_runtest_makereport|   sL    
"rN   c             C   s"   t | dƒr| jrdS | jrdS d S )NrF   )ÚxfailedÚxZXFAIL)ÚxpassedÚXZXPASS)rB   r?   r1   )Úreportr   r   r   Úpytest_report_teststatus´   s
    
rT   c             C   sl   | }|j sd S g }x(|j D ]}t |dd„ ¡}|| |ƒ qW |rh|j dd¡ x|D ]}|j |¡ qTW d S )Nc             S   s   d S )Nr   )ÚtrÚlinesr   r   r   r   Æ   s    z)pytest_terminal_summary.<locals>.<lambda>ú=zshort test summary info)ZreportcharsÚREPORTCHAR_ACTIONSr4   Z_twÚseprM   )ÚterminalreporterrU   rV   Úcharr   rM   r   r   r   Úpytest_terminal_summary¿   s    
r\   c             C   sL   | j  |¡}|rHx6|D ].}t| |ƒ}| j |j¡}| d||f ¡ qW d S )Nz%s %s)Ústatsr4   Ú_get_report_strr"   Úcwd_relative_nodeidÚnodeidr    )rZ   rV   Ústatr>   rK   Úverbose_wordÚposr   r   r   Úshow_simpleÏ   s    

rd   c             C   sh   | j  d¡}|rdxR|D ]J}t| |ƒ}| j |j¡}|j}| d||f ¡ |r| dt|ƒ ¡ qW d S )NrO   z%s %sz  )	r]   r4   r^   r"   r_   r`   rF   r    Ústr)rZ   rV   rO   rK   rb   rc   r%   r   r   r   Úshow_xfailedØ   s    

rf   c             C   sT   | j  d¡}|rPx>|D ]6}t| |ƒ}| j |j¡}|j}| d|||f ¡ qW d S )NrQ   z%s %s %s)r]   r4   r^   r"   r_   r`   rF   r    )rZ   rV   rQ   rK   rb   rc   r%   r   r   r   Úshow_xpassedä   s    

rg   c             C   s¬   i }xt| D ]l}|j }t|ƒdks,t||fƒ‚t|di ƒ}|jdkrdd|krdd|krd|d d |d f}| |g ¡ |¡ q
W g }x(| ¡ D ]\}}| t|ƒf| ¡ qˆW |S )Né   ÚkeywordsZsetupr   Z
pytestmarkr   r@   )rE   ÚlenÚAssertionErrorrA   rC   Ú
setdefaultr    Úitems)r?   ÚdZeventÚkeyri   ÚvaluesZeventsr   r   r   Úfolded_skipsî   s    

rq   c       
   	   C   sž   | }|j  dg ¡}|ršt| |d d}t|ƒ}|ršxf|D ]^\}}}}	|	 d¡rZ|	dd … }	|d k	r€| d||||d |	f ¡ q8| d||||	f ¡ q8W d S )	Nr?   r   )rS   z	Skipped: é	   z%s [%d] %s:%d: %sé   z%s [%d] %s: %s)r]   r4   r^   rq   Ú
startswithr    )
rZ   rV   rU   r?   rb   ZfskipsZnumÚfspathÚlinenor%   r   r   r   Úshow_skipped  s    
rw   c                s   ‡ fdd„}|S )Nc                s   t | |ˆ ƒS )N)rd   )rZ   rV   )ra   r   r   Úshow_  s    zshower.<locals>.show_r   )ra   rx   r   )ra   r   Úshower  s    ry   c             C   s   | j jj|| j d\}}}|S )N)rS   r"   )r"   ÚhookrT   )rZ   rS   Z	_categoryZ_shortÚverboser   r   r   r^     s    r^   r>   r1   Úerror)rP   rR   ÚfÚFÚsÚSÚpÚEN)Ú__doc__Z
__future__r   r   r   Z_pytest.configr   Z_pytest.mark.evaluater   Z_pytest.outcomesr   r   r	   r   r#   r,   r2   r*   r.   rN   rT   r\   rd   rf   rg   rq   rw   ry   r^   rX   r   r   r   r   Ú<module>   s@   (		8	
