Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/_pytest/assertion/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/_pytest/assertion/__pycache__/util.cpython-37.pyc

B

C$�X	*�@s�dZddlZddlZddlZyddlmZWnek
rDeZYnXej	j
jZej	j
ZdZdd�Zdd�Zdd	�Zd
d�ZyeZWnek
r�eZYnXdd
�Zddd�Zddd�Zddd�Zddd�Zddd�Zd dd�ZdS)!z!Utilities for assertion debugging�N)�SequencecCs&yt|dd�Stk
r |SXdS)Nzutf-8�replace)�u�	TypeError)�s�r�G/opt/alt/python37/lib/python3.7/site-packages/_pytest/assertion/util.py�ecusr	cCs&t|�}t|�}t|�}td��|�S)a�This formats an explanation

    Normally all embedded newlines are escaped, however there are
    three exceptions: 
{, 
} and 
~.  The first two are intended
    cover nested explanations, see function and attribute explanations
    for examples (.visit_Call(), visit_Attribute()).  The last one is
    for when one explanation needs to span multiple lines, e.g. when
    displaying diffs.
    �
)r	�_split_explanation�
_format_linesr�join)�explanation�lines�resultrrr�format_explanations
rcCsf|p
td��d�}|dg}xD|dd�D]4}|rJ|ddkrJ|�|�q*|dd|7<q*W|S)	z�Return a list of individual lines in the explanation

    This will return a list of lines split on '
{', '
}' and '
~'.
    Any other newlines will be escaped and appear in the line as the
    literal '
' characters.
    �r
r�N)�{�}�~�>���z\n)r�split�append)rZ	raw_linesr�lrrrr.s
rcCs^|dd�}dg}dg}�x,|dd�D�]}|�d�r�|drJtd�}ntd�}|�t|��|dd7<|�d�|�td�td	�t|�d||dd��q(|�d
�r�|��|��||d|dd�7<q(|ddks�t�|dd7<|�d��rt|�n
t|�d}|�td	�||dd��q(Wt|�dk�sZt�|S)
a
Format the individual lines

    This will replace the '{', '}' and '~' characters of our mini
    formatting language with the proper 'where ...', 'and ...' and ' +
    ...' text, taking care of indentation along the way.

    Return a list of formatted lines.
    Nrrrrzand   zwhere z +z  r)rrr)�
startswithrr�len�pop�AssertionError)rr�stackZstackcnt�liner�indentrrrr?s,	


4
 "rcs�dt|�d}tjj|t|d�d�}tjj||t|�d�}td�t|�|t|�f}dd�}dd��dd�}	d	d�}
�fd
d�}|�d�}d
}
y�|dk�rV�|�r��|�r�t|||�}
n�||�r�||�r�t	|||�}
n>|
|�r�|
|�r�t
|||�}
n |	|��r|	|��rt|||�}
||��r�||��r�t|||�}|
d
k	�rP|
�
|�n|}
n*|dk�r��|��r��|��r�t|||�}
Wn,tk
�r�td�ttj���g}
YnX|
�s�d
S|g|
S)z;Return specialised explanations for some operators/operands�A�)�maxsizez%s %s %scSst|tttf�ot|t�S)N)�
isinstance�list�tupler�
basestring)�xrrr�<lambda>qsz$assertrepr_compare.<locals>.<lambda>cSs
t|t�S)N)r&r))r*rrrr+s�cSs
t|t�S)N)r&�dict)r*rrrr+tr,cSst|ttf�S)N)r&�set�	frozenset)r*rrrr+ur,cs,yt|��|�Stk
r&dSXdS)NF)�iterr)�obj)�istextrr�
isiterablews

z&assertrepr_compare.<locals>.isiterable�verboseNz==znot inzg(pytest_assertion plugin: representation of details failed.  Probably an object has a faulty __repr__.))r�py�io�saferepr�intrr	Z	getoption�
_diff_text�_compare_eq_sequence�_compare_eq_set�_compare_eq_dict�_compare_eq_iterable�extend�_notin_text�	Exception�_pytest�_codeZ
ExceptionInfo)�config�op�left�right�widthZ	left_reprZ
right_repr�summaryZ
issequenceZisdictZissetr3r4rZexplr)r2r�assertrepr_compareisF



rIFcCs�ddlm}g}t|tjj�r:tt|�dd���dd�}t|tjj�rdtt|�dd���dd�}|�sTd}x0t	t
t|�t|���D]}||||kr�Pq�W|dkr�|d8}td	�|g}||d
�}||d
�}t|�t|�k�rTx*t	t|��D]}||||kr�Pq�W|dk�rT|d8}|td�|g7}|d
|�}|d
|�}d}|d
d�||�|�|�|��D�7}|S)aReturn the explanation for the diff between text or bytes

    Unless --verbose is used this will skip leading and trailing
    characters which are identical to keep the diff minimal.

    If the input are bytes they will be safely converted to text.
    r)�ndiffrrz\nr
�*�
z@Skipping %s identical leading characters in diff, use -v to showNzASkipping %s identical trailing characters in diff, use -v to showTcSsg|]}|�d��qS)r
)�strip)�.0r!rrr�
<listcomp>�sz_diff_text.<locals>.<listcomp>)
�difflibrJr&r5�builtin�bytesr�reprr�range�minr�
splitlines)rErFr4rJr�i�keependsrrrr9�s@


r9cCs�|std�gSddl}y*t�|���}t�|���}td�g}WnBtk
r�tdd�|D��}tdd�|D��}td�g}YnX|�dd�|�||�D��|S)	NzUse -v to get the full diffrz
Full diff:css|]}t|�VqdS)N)rS)rNr*rrr�	<genexpr>�sz'_compare_eq_iterable.<locals>.<genexpr>css|]}t|�VqdS)N)rS)rNr*rrrrY�sz2Full diff (fallback to calling repr on each item):css|]}|��VqdS)N)rM)rNr!rrrrY�s)	rrP�pprint�pformatrVr@�sortedr>rJ)rErFr4rPZleft_formattingZright_formattingrrrrr=�s
r=cCs�g}xPttt|�t|���D]6}||||kr|td�|||||fg7}PqWt|�t|�kr�|td�tj�|t|��g7}n2t|�t|�kr�|td�tj�|t|��g7}|S)NzAt index %s diff: %r != %rz.Left contains more items, first extra item: %sz/Right contains more items, first extra item: %s)rTrUrrr5r6r7)rErFr4rrWrrrr:�sr:cCs|g}||}||}|rF|�td��x|D]}|�tj�|��q,W|rx|�td��x|D]}|�tj�|��q^W|S)NzExtra items in the left set:zExtra items in the right set:)rrr5r6r7)rErFr4rZ	diff_leftZ
diff_right�itemrrrr;�s

r;c
stg}t���t���}t��fdd�|D��}|rN|sN|td�t|�g7}n$|rr|td�g7}|t�|���7}t��fdd�|D��}|r�|td�g7}x>|D]6}|tj	�
|�|i�dtj	�
|�|i�g7}q�Wt��t��}|�r&|�td��|�t�t�fd	d�|D������t��t��}	|	�rp|�td
��|�t�t�fdd�|	D������|S)Nc3s*|]"}�|�|kr|�|fVqdS)Nr)rN�k)rErFrrrYsz#_compare_eq_dict.<locals>.<genexpr>z+Omitting %s identical items, use -v to showz
Common items:c3s"|]}�|�|kr|VqdS)Nr)rNr^)rErFrrrY	szDiffering items:z != zLeft contains more items:c3s|]}|�|fVqdS)Nr)rNr^)rErrrYszRight contains more items:c3s|]}|�|fVqdS)Nr)rNr^)rFrrrYs)
r.�intersectionr-rrrZr[rVr5r6r7rr>)
rErFr4r�commonZsame�diffr^Z
extra_leftZextra_rightr)rErFrr<�s4
r<c
Cs�|�|�}|d|�}||t|�d�}||}t|||�}td�tjj|dd�g}x`|D]X}	|	�td��rrq^|	�td��r�q^|	�td��r�|�td�|	dd��q^|�|	�q^W|S)	Nz%s is contained here:rK)r%ZSkippingz- z+ z  r$)	�findrr9rr5r6r7rr)
Zterm�textr4�index�head�tailZcorrect_textraZnewdiffr!rrrr?s

r?)F)F)F)F)F)F)�__doc__rZZ
_pytest._coderAr5�collectionsr�ImportErrorr'rQ�builtinsrZBuiltinAssertionErrorZ_totextrZ_reprcomparer	rrrr)�	NameError�strrIr9r=r:r;r<r?rrrr�<module>s2

$
7
*