o
    h)O                     @  sL  U d Z ddlm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ZddlmZ ddlmZ ddlmZ ddlmZ dZded< dZded< dZded< G dd deZ dmddZ!dnd d!Z"dod$d%Z#dpd)d*Z$dpd+d,Z%dpd-d.Z&dpd/d0Z'dqd2d3Z(dqd4d5Z)dqd6d7Z*dqd8d9Z+drd;d<Z,	=dsdtdCdDZ-	dudvdHdIZ.dudwdJdKZ/	dudxdMdNZ0	dudydPdQZ1	dudzdSdTZ2	dudzdUdVZ3	dudzdWdXZ4	dudzdYdZZ5	dudzd[d\Z6d{d`daZ7	dud|dcddZ8dvdedfZ9dud}didjZ:d~dkdlZ;dS )z"Utilities for assertion debugging.    )annotationsN)AbstractSet)Any)Callable)Iterable)Literal)Mapping)Protocol)Sequence)	normalize)outcomes)PrettyPrinter)saferepr)saferepr_unlimited)Configz2Callable[[str, object, object], str | None] | None_reprcomparez&Callable[[int, str, str], None] | None_assertion_passzConfig | None_configc                   @  s   e Zd Zd
dddZd	S )_HighlightFuncpythonsourcestrlexerLiteral['diff', 'python']returnc                 C  s   dS )z'Apply highlighting to the given source.N )selfr   r   r   r   N/var/www/html/zoom/venv/lib/python3.10/site-packages/_pytest/assertion/util.py__call__*   s    z_HighlightFunc.__call__N)r   )r   r   r   r   r   r   )__name__
__module____qualname__r   r   r   r   r   r   )   s    r   explanationr   r   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)   	list[str]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"   	raw_linesr'   valuesr   r   r   r$   =   s   
r$   r'   Sequence[str]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(   stackstackcntlinesindentr   r   r   r%   N   s,   	

,
r%   xr   boolc                 C  s   t | tjjot | t S N)
isinstancecollectionsabcr
   r   rA   r   r   r   
issequenceq      rH   c                 C  
   t | tS rC   )rD   r   rG   r   r   r   istextu      
rK   c                 C  rJ   rC   )rD   dictrG   r   r   r   isdicty   rL   rN   c                 C  s   t | ttfS rC   )rD   set	frozensetrG   r   r   r   isset}   s   rQ   objc                 C  s   t | tot| dd d uS )N_fields)rD   tuplegetattrrR   r   r   r   isnamedtuple   rI   rW   c                 C     t | dd d uS )N__dataclass_fields__rU   rV   r   r   r   	isdatacls      r[   c                 C  rX   )N__attrs_attrs__rZ   rV   r   r   r   isattrs   r\   r^   c                 C  s*   z
t |  t|  W S  ty   Y dS w )NF)iterrK   	ExceptionrV   r   r   r   
isiterable   s   ra   objectc                 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__rc   rd   r^   )rR   code_filenamer   r   r   has_default_eq   s   
rh   Fopleftright	use_asciilist[str] | Nonec                 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   tjj  }d| ddg}Y nw |sdS |d dkrdg|}|	g|S )z<Return specialised explanations for some operators/operands.NFDr,   )rl   A      )maxsizerl    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+   )get_verbosityr   VERBOSITY_ASSERTIONSrD   r   r   r   r:   r   get_terminal_writer
_highlight_compare_eq_anyrK   _notin_textrQ   _compare_gte_set_compare_lte_set_compare_gt_set_compare_lt_setr   Exitr`   _pytest_codeExceptionInfofrom_current_getreprcrash)configri   rj   rk   rl   verbose	left_repr
right_reprrq   summaryhighlighterr"   
repr_crashr   r   r   assertrepr_compare   sr   




r   r   r   intc           	      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)rK   
_diff_text_pytest.python_apir   rD   _repr_comparetyper[   r^   rW   _compare_eq_clsrH   _compare_eq_sequencerQ   _compare_eq_setrN   _compare_eq_dictra   _compare_eq_iterableextend)	rj   rk   r   r   r"   r   approx_side
other_sideexplr   r   r   rz      s6   
rz   c                 C  sX  ddl m} g }|dk r}d}ttt| t|D ]}| | || kr% nq|dkrA|d8 }d| dg}| |d } ||d }t| t|kr}tt| D ]}| |  ||  kr] nqO|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 z5 identical leading characters in diff, use -v to showNz6 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minr:   isspacereprr   
splitlines)rj   rk   r   r   r"   ikeependsr   r   r   r     sF   


r   Iterable[Any]c              
   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 rC   )rstripr   r   r   r   	<genexpr>X  s
    
z'_compare_eq_iterable.<locals>.<genexpr>diff)r   )running_on_cir   r   pformatr   r   r&   r   )rj   rk   r   r   r   left_formattingright_formattingr"   r   r   r   r   E  s    

	r   Sequence[Any]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   LeftRightz contains one more item: z/%s contains %d more items, first extra item: %s)rD   bytesr:   r   r   r3   r   r   )rj   rk   r   r   comparing_bytesr"   len_left	len_rightr   
left_valueright_valuelen_diffdir_with_moreextrar   r   r   r   b  sR   	

r   AbstractSet[Any]c                 C  s0   g }| td| || | td|| | |S )Nrj   rk   )r   _set_one_sided_diffrj   rk   r   r   r"   r   r   r   r     s   r   c                 C     t | ||}|sdgS |S Nrs   )r|   r   r   r   r   r~        r~   c                 C  r   r   )r}   r   r   r   r   r     r   r   c                 C  s   t d|| |S )Nrk   r   rj   rk   r   r   r   r   r   r|        r|   c                 C  s   t d| ||S )Nrj   r   r   r   r   r   r}     r   r}   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   r   r"   r   itemr   r   r   r     s   r   Mapping[Any, Any]c                   s  g }t  }t }||} fdd|D }|r+|dk r+|dt| dg7 }n|r=|dg7 }||t| 7 } fdd|D }	|	rl|d	g7 }|	D ]}
||t|
 |
 id
 |t|
|
 i g7 }qP|| }t|}|r|d||dkrd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rj   rk   r   r   
<dictcomp>  s   & z$_compare_eq_dict.<locals>.<dictcomp>rp   	Omitting ! 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   )rj   r   r   r         zRight contains %d more item%s:c                   r   r   r   r   )rk   r   r   r     r   )	rO   intersectionr:   pprintr   r   r   r3   r   )rj   rk   r   r   r"   set_left	set_rightcommonsamer   r   
extra_leftlen_extra_leftextra_right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 }
|rq|dk rq|
	d	t
| d
 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)rU   r   )r   fieldr   r   r   r      s    Fr7   r+   rp   r   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    )rh   r[   dataclassesfieldsr^   r]   rW   rS   rU   r3   r:   r   r   r   r   rz   )rj   rk   r   r   r   
all_fieldsfields_to_checkr   r   r   r"   
field_leftfield_rightr   r   r   r     sX   






&
r   termtextc           
      C  s   | | }|d | }||t|  d  }|| }t|||}t| dd dg}|D ]$}	|	dr3q+|	dr9q+|	drJ|d|	dd    q+||	 q+|S )	Nr   )rq   z is contained here:Skippingz- z+ r7   rp   )findr:   r   r   r9   r3   )
r   r   r   indexheadtailcorrect_textr   newdiffr>   r   r   r   r{   K  s   



r{   c                  C  s   ddg} t dd | D S )z0Check if we're currently running on a CI system.CIBUILD_NUMBERc                 s  s    | ]}|t jv V  qd S rC   )osenviron)r   varr   r   r   r   a  s    z running_on_ci.<locals>.<genexpr>)any)env_varsr   r   r   r   ^  s   r   )r"   r   r   r   )r"   r   r   r*   )r'   r6   r   r*   )rA   r   r   rB   )rR   r   r   rB   )rR   rb   r   rB   )F)
ri   r   rj   r   rk   r   rl   rB   r   rm   )r   )
rj   r   rk   r   r   r   r   r   r   r*   )rj   r   rk   r   r   r   r   r*   )
rj   r   rk   r   r   r   r   r   r   r*   )
rj   r   rk   r   r   r   r   r   r   r*   )
rj   r   rk   r   r   r   r   r   r   r*   )
r   r   r   r   r   r   r   r   r   r*   )
rj   r   rk   r   r   r   r   r   r   r*   )r   r   r   r   r   r   r   r*   )r   rB   )<__doc__
__future__r   collections.abcrE   r   r   typingr   r   r   r   r   r   r	   r
   unicodedatar   r   r   _pytest._code_pytest._io.pprintr   _pytest._io.safereprr   r   _pytest.configr   r   __annotations__r   r   r   r)   r$   r%   rH   rK   rN   rQ   rW   r[   r^   ra   rh   r   rz   r   r   r   r   r~   r   r|   r}   r   r   r   r{   r   r   r   r   r   <module>   sz   



#







G%4!A
	
07