o
    ZhSO                     @   s  U d Z ddl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ZddlmZ ddlmZ ddlmZ ddlmZ dZeeeeegee f  ed< dZ eee!eegdf  ed< dZ"ee ed< G dd deZ#dedefddZ$dede
e fddZ%dee de
e fdd Z&d!ede'fd"d#Z(d!ede'fd$d%Z)d!ede'fd&d'Z*d!ede'fd(d)Z+d*ede'fd+d,Z,d*ede'fd-d.Z-d*ede'fd/d0Z.d*ede'fd1d2Z/d*ede'fd3d4Z0	5d`d6ed7ed8ed9e'dee
e  f
d:d;Z1	dad7ed8ed<e#d=e!de
e f
d>d?Z2dad7ed8ed=e!de
e fd@dAZ3	dad7e	e d8e	e dBe#d=e!de
e f
dCdDZ4	dad7ee d8ee d<e#d=e!de
e f
dEdFZ5	dad7ee d8ee d<e#d=e!de
e f
dGdHZ6	dad7ee d8ee d<e#d=e!de
e f
dIdJZ7	dad7ee d8ee d<e#d=e!de
e f
dKdLZ8	dad7ee d8ee d<e#d=e!de
e f
dMdNZ9	dad7ee d8ee d<e#d=e!de
e f
dOdPZ:dQedRee dSee d<e#de
e f
dTdUZ;	dad7eeef d8eeef d<e#d=e!de
e f
dVdWZ<d7ed8ed<e#d=e!de
e f
dXdYZ=dadZed[ed=e!de
e fd\d]Z>de'fd^d_Z?dS )bz"Utilities for assertion debugging.    N)AbstractSet)Any)Callable)Iterable)List)Literal)Mapping)Optional)Protocol)Sequence)	normalize)outcomes)PrettyPrinter)saferepr)saferepr_unlimited)Config_reprcompare_assertion_pass_configc                   @   s(   e Zd Zd	deded defddZdS )
_HighlightFuncpythonsourcelexer)diffr   returnc                 C   s   dS )z'Apply highlighting to the given source.N )selfr   r   r   r   M/var/www/html/lang_env/lib/python3.10/site-packages/_pytest/assertion/util.py__call__)   s    z_HighlightFunc.__call__N)r   )__name__
__module____qualname__strr   r   r   r   r   r   r   (   s     r   explanationr   c                 C   s   t | }t|}d|S )a  Format an explanation.

    Normally all embedded newlines are escaped, however there are
    three exceptions: \n{, \n} and \n~.  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.
    
)_split_explanation_format_linesjoin)r#   linesresultr   r   r   format_explanation-   s   

r*   c                 C   s^   | pd d}|d g}|dd D ]}|r"|d dv r"|| q|d  d| 7  < q|S )	zReturn a list of individual lines in the explanation.

    This will return a list of lines split on '\n{', '\n}' and '\n~'.
    Any other newlines will be escaped and appear in the line as the
    literal '\n' characters.
     r$   r      N){}~>z\n)splitappend)r#   Z	raw_linesr(   valuesr   r   r   r%   <   s   
r%   r(   c                 C   sB  t | dd }dg}dg}| dd D ]}|drN|d r"d}nd}|t| |d  d7  < |d |dd	t|d   | |dd   q|d
rj|  |  ||d   |dd 7  < q|d dv srJ |d  d7  < |drt|nt|d }|d	| |dd   qt|dksJ |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.
    Nr,   r   r-   r1   zand   zwhere z +  r.   )r/   r0   r/   )list
startswithr3   lenpop)r(   r)   stackZstackcntlinesindentr   r   r   r&   M   s,   	

,
r&   xc                 C   s   t | tjjot | t S N)
isinstancecollectionsabcr   r"   r>   r   r   r   
issequencep      rD   c                 C   
   t | tS r?   )r@   r"   rC   r   r   r   istextt      
rG   c                 C   rF   r?   )r@   dictrC   r   r   r   isdictx   rH   rJ   c                 C   s   t | ttfS r?   )r@   set	frozensetrC   r   r   r   isset|   s   rM   objc                 C   s   t | tot| dd d uS )N_fields)r@   tuplegetattrrN   r   r   r   isnamedtuple   rE   rS   c                 C      t | dd d uS )N__dataclass_fields__rQ   rR   r   r   r   	isdatacls      rW   c                 C   rT   )N__attrs_attrs__rV   rR   r   r   r   isattrs   rX   rZ   c                 C   s*   z
t |  t|  W S  ty   Y dS w )NF)iterrG   	ExceptionrR   r   r   r   
isiterable   s   r]   c                 C   s@   t | jdrt | jjdr| jjj}t| rd|v S |dkS dS )a  Check if an instance of an object contains the default eq

    First, we check if the object's __eq__ attribute has __code__,
    if so, we check the equally of the method code filename (__code__.co_filename)
    to the default one generated by the dataclass and attr module
    for dataclasses the default co_filename is <string>, for attrs class, the __eq__ should contain "attrs eq generated"
    __code__co_filenamezattrs generated eqz<string>T)hasattr__eq__r^   r_   rZ   )rN   Zcode_filenamer   r   r   has_default_eq   s   
rb   Fopleftright	use_asciic                 C   s  |  tj}t|tot|totd|td|k}|dkr+t||d}t||d}ndt| d d }t|||d}t|||d}| d| d| }	| 	 j
}
d}z|d	krat|||
|}nr|d
krtt|rst|rst|||}n_|dkrt|rt|rdg}nO|dkrt|rt|rt|||
|}n;|dkrt|rt|rt|||
|}n'|dkrt|rt|rt|||
|}n|dkrt|rt|rt|||
|}W n tjy     ty   dtjj  dg}Y nw |sdS |d dkrdg|}|	g|S )z<Return specialised explanations for some operators/operands.ZNFDr,   )rf   A      )maxsizerf    Nz==znot inz!=Both sets are equalz>=z<=r0   <z?(pytest_assertion plugin: representation of details failed: {}.z+ Probably an object has a faulty __repr__.)r   r+   )Zget_verbosityr   ZVERBOSITY_ASSERTIONSr@   r"   r   r   r8   r   Zget_terminal_writer
_highlight_compare_eq_anyrG   _notin_textrM   _compare_gte_set_compare_lte_set_compare_gt_set_compare_lt_setr   ZExitr\   format_pytest_codeZExceptionInfoZfrom_currentZ_getreprcrash)configrc   rd   re   rf   verboseZ	left_reprZ
right_reprri   summaryhighlighterr#   r   r   r   assertrepr_compare   st   



r{   rz   rx   c           	      C   s6  g }t | rt |rt| ||}|S ddlm} t| |s"t||r:t| |r)| n|}t| |r2|n| }||}nKt| t|u rVt| sNt| sNt	| rVt
| |||}n/t| rft|rft| |||}nt| rvt|rvt| |||}nt| rt|rt| |||}t| rt|rt| |||}|| |S )Nr   )
ApproxBase)rG   
_diff_textZ_pytest.python_apir|   r@   Z_repr_comparetyperW   rZ   rS   _compare_eq_clsrD   _compare_eq_sequencerM   _compare_eq_setrJ   _compare_eq_dictr]   _compare_eq_iterableextend)	rd   re   rz   rx   r#   r|   Zapprox_sideZ
other_sideZexplr   r   r   rn      s6   
rn   c                 C   sT  ddl m} g }|dk r{d}ttt| t|D ]}| | || kr% nq|dkr?|d8 }d| g}| |d } ||d }t| t|kr{tt| D ]}| |  ||  kr[ nqM|dkr{|d8 }|d| d	g7 }| d|  } |d|  }d
}|  s| rtt| } tt|}|dg7 }|dd |||| |D 7 }|S )zReturn the explanation for the diff between text.

    Unless --verbose is used this will skip leading and trailing
    characters which are identical to keep the diff minimal.
    r   )ndiffr,   *   
   z@Skipping %s identical leading characters in diff, use -v to showNz	Skipping z6 identical trailing characters in diff, use -v to showTz;Strings contain only whitespace, escaping them using repr()c                 S   s   g | ]}| d qS )r$   )strip.0r;   r   r   r   
<listcomp>>  s    z_diff_text.<locals>.<listcomp>)	difflibr   rangeminr8   isspacereprr"   
splitlines)rd   re   rx   r   r#   ikeependsr   r   r   r}     sF   

r}   
highligherc              
   C   sv   |dkr
t  s
dgS dd l}t |  }t | }ddg}||ddd |||D dd	  |S )
Nr   zUse -v to get more diffr+   z
Full diff:r$   c                 s   s    | ]}|  V  qd S r?   )rstripr   r   r   r   	<genexpr>X  s
    
z'_compare_eq_iterable.<locals>.<genexpr>r   )r   )running_on_cir   r   pformatr   r   r'   r   )rd   re   r   rx   r   Zleft_formattingZright_formattingr#   r   r   r   r   E  s    

	r   c                 C   s8  t | to	t |t}g }t| }t|}tt||D ]=}| | || krX|r8| ||d  }	|||d  }
n| | }	|| }
|d| d|t|	 d|t|
   nq|r]|S || }|r|dkrpd}t| | }nd| }d}t|| }|dkr|| d|| g7 }|S |d	||||f g7 }|S )
Nr,   z	At index z diff:  != r   ZLeftZRightz contains one more item: z/%s contains %d more items, first extra item: %s)r@   bytesr8   r   r   r3   r   r   )rd   re   rz   rx   Zcomparing_bytesr#   Zlen_leftZ	len_rightr   Z
left_valueZright_valueZlen_diffZdir_with_moreextrar   r   r   r   b  sR   	

r   c                 C   s0   g }| td| || | td|| | |S )Nrd   re   )r   _set_one_sided_diffrd   re   rz   rx   r#   r   r   r   r     s   r   c                 C      t | ||}|sdgS |S Nrk   )rp   r   r   r   r   rr        rr   c                 C   r   r   )rq   r   r   r   r   rs     r   rs   c                 C   s   t d|| |S )Nre   r   rd   re   rz   rx   r   r   r   rp        rp   c                 C   s   t d| ||S )Nrd   r   r   r   r   r   rq     r   rq   posnset1set2c                 C   sB   g }|| }|r| d|  d |D ]}| |t| q|S )NzExtra items in the z set:)r3   r   )r   r   r   rz   r#   r   itemr   r   r   r     s   r   c                    s  g }t  }t }||} fdd|D }|r)|dk r)|dt| g7 }n|r;|dg7 }||t| 7 } fdd|D }	|	rj|dg7 }|	D ]}
||t|
 |
 id	 |t|
|
 i g7 }qN|| }t|}|r|d
||dkr~dndf  ||t fdd|D   || }t|}|r|d||dkrdndf  ||tfdd|D   |S )Nc                    s&   i | ]} | | kr| | qS r   r   r   krd   re   r   r   
<dictcomp>  s   & z$_compare_eq_dict.<locals>.<dictcomp>rh   ,Omitting %s identical items, use -vv to showzCommon items:c                    s    h | ]} | | kr|qS r   r   r   r   r   r   	<setcomp>  s     z#_compare_eq_dict.<locals>.<setcomp>zDiffering items:r   zLeft contains %d more item%s:r,   r+   r<   c                       i | ]}| | qS r   r   r   )rd   r   r   r         zRight contains %d more item%s:c                    r   r   r   r   )re   r   r   r     r   )	rK   intersectionr8   pprintr   r   r   r3   r   )rd   re   rz   rx   r#   Zset_leftZ	set_rightcommonsamer   r   Z
extra_leftZlen_extra_leftZextra_rightZlen_extra_rightr   r   r   r     sX   


r   c                    s  t | sg S t| rdd l}|| }dd |D }nt| r*| j}dd |D }n
t| r2| j}nJ d g }g }|D ]}	t| |	t||	krN|	|	 q<|	|	 q<g }
|sZ|r_|
dg7 }
|ro|dk ro|
	d	t
|  n|r|
d
g7 }
|
|t| 7 }
|r|
dg7 }
|
|t| 7 }
|D ]9}	t| |	}t||	}|
dd|	 d  |	 d|t| d|t| g7 }
|
 fddt||||D 7 }
q|
S )Nr   c                 S   s   g | ]}|j r|jqS r   )comparename)r   infor   r   r   r     s    z#_compare_eq_cls.<locals>.<listcomp>c                 S   s   g | ]
}t |d r|jqS )eq)rQ   r   )r   fieldr   r   r   r      s    Fr5   r+   rh   r   zMatching attributes:zDiffering attributes:z$Drill down into differing attribute :z: r   c                    s   g | ]} | qS r   r   r   r=   r   r   r   B  s    )rb   rW   dataclassesfieldsrZ   rY   rS   rO   rQ   r3   r8   r   r   r   r   rn   )rd   re   rz   rx   r   Z
all_fieldsZfields_to_checkr   r   r   r#   Z
field_leftZfield_rightr   r   r   r     sX   






&
r   termtextc           
      C   s   | | }|d | }||t|  d  }|| }t|||}dt| dd g}|D ]$}	|	dr2q*|	dr8q*|	drI|d|	dd    q*||	 q*|S )	Nz%s is contained here:r   )ri   ZSkippingz- z+ r5   rh   )findr8   r}   r   r7   r3   )
r   r   rx   indexheadtailZcorrect_textr   Znewdiffr;   r   r   r   ro   K  s   



ro   c                  C   s   ddg} t dd | D S )z0Check if we're currently running on a CI system.CIZBUILD_NUMBERc                 s   s    | ]}|t jv V  qd S r?   )osenviron)r   varr   r   r   r   a  s    z running_on_ci.<locals>.<genexpr>)any)Zenv_varsr   r   r   r   ^  s   r   )F)r   )@__doc__collections.abcrA   r   r   typingr   r   r   r   r   r   r   r	   r
   r   unicodedatar   ru   r   Z_pytest._codeZ_pytest._io.pprintr   Z_pytest._io.safereprr   r   Z_pytest.configr   r   r"   object__annotations__r   intr   r   r*   r%   r&   boolrD   rG   rJ   rM   rS   rW   rZ   r]   rb   r{   rn   r}   r   r   r   rr   rs   rp   rq   r   r   r   ro   r   r   r   r   r   <module>   st  "#


H
 %4
!
A




	



0
 7