o
    v&iQP                     @  sT  U d 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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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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"drdsd!d"Z#dtd$d%Z$dud'd(Z%dvd+d,Z&dwd0d1Z'dwd2d3Z(dwd4d5Z)dwd6d7Z*dxd9d:Z+dxd;d<Z,dxd=d>Z-dxd?d@Z.dydBdCZ/	Ddzd{dJdKZ0	d|d}dOdPZ1	d|d~dQdRZ2	d|ddTdUZ3	d|ddWdXZ4	d|ddZd[Z5	d|dd\d]Z6	d|dd^d_Z7	d|dd`daZ8	d|ddbdcZ9ddgdhZ:	d|ddjdkZ;d}dldmZ<d|ddpdqZ=dS )z"Utilities for assertion debugging.    )annotationsN)Callable)Iterable)Mapping)Sequence)Set)Any)Literal)Protocol)	normalize)outcomes)PrettyPrinter)saferepr)saferepr_unlimited)running_on_ci)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   \/var/www/html/karishye-ai-python/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   r   r   r   r   r   r   c                 C  s   | S )zDummy highlighter that returns the text unprocessed.

    Needed for _notin_text, as the diff gets post-processed to only show the "+" part.
    r   )r   r   r   r   r   dummy_highlighter.   s   r%   explanationc                 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_explanation6   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(   E   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.
    Nr0   r   r1   r5   zand   zwhere z +  r2   )r3   r4   r3   )list
startswithr7   lenpop)r+   r,   stackstackcntlinesindentr   r   r   r)   V   s,   	

,
r)   xr   boolc                 C  s   t | tjjot | t S N)
isinstancecollectionsabcr   r   rE   r   r   r   
issequencey      rL   c                 C  
   t | tS rG   )rH   r   rK   r   r   r   istext}      
rO   c                 C  rN   rG   )rH   dictrK   r   r   r   isdict   rP   rR   c                 C  s   t | ttB S rG   )rH   set	frozensetrK   r   r   r   isset   s   rU   objc                 C  s   t | tot| dd d uS )N_fields)rH   tuplegetattrrV   r   r   r   isnamedtuple   rM   r[   c                 C     t | dd d uS )N__dataclass_fields__rY   rZ   r   r   r   	isdatacls      r_   c                 C  r\   )N__attrs_attrs__r^   rZ   r   r   r   isattrs   r`   rb   c                 C  s*   z
t |  t|  W S  ty   Y dS w )NF)iterrO   	ExceptionrZ   r   r   r   
isiterable   s   re   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 z<string>T)hasattr__eq__rg   rh   rb   )rV   code_filenamer   r   r   has_default_eq   s   
rl   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.NFDr0   )rp   A      )maxsizerp    Nz==znot inz!=Both sets are equalz>=z<=r4   <z<(pytest_assertion plugin: representation of details failed: .z+ Probably an object has a faulty __repr__.)r   r/   )get_verbosityr   VERBOSITY_ASSERTIONSrH   r   r   r   r>   r   get_terminal_writer
_highlight_compare_eq_anyrO   _notin_textrU   _compare_gte_set_compare_lte_set_compare_gt_set_compare_lt_setr   Exitrd   _pytest_codeExceptionInfofrom_current_getreprcrash)configrm   rn   ro   rp   verbose	left_repr
right_reprru   summaryhighlighterr&   
repr_crashr   r   r   assertrepr_compare   sr   




r   r   r   intc           	      C  s8  g }t | rt |rt| |||}|S ddlm} t| |s#t||r;t| |r*| n|}t| |r3|n| }||}nKt| t|u rWt| sOt| sOt	| rWt
| |||}n/t| rgt|rgt| |||}nt| rwt|rwt| |||}nt| rt|rt| |||}t| rt|rt| |||}|| |S )Nr   )
ApproxBase)rO   
_diff_text_pytest.python_apir   rH   _repr_comparetyper_   rb   r[   _compare_eq_clsrL   _compare_eq_sequencerU   _compare_eq_setrR   _compare_eq_dictre   _compare_eq_iterableextend)	rn   ro   r   r   r&   r   approx_side
other_sideexplr   r   r   r~      s6   
r~   c                 C  sl  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 ||
|| 
|D dd
  |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   )ndiffr0   *   
   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()r'   c                 s  s    | ]}| d V  qdS )r'   N)strip.0rB   r   r   r   	<genexpr>J  s
    
z_diff_text.<locals>.<genexpr>diffr   )difflibr   rangeminr>   isspacereprr   r   r*   
splitlines)rn   ro   r   r   r   r&   ikeependsr   r   r   r     sR   



	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 rG   )rstripr   r   r   r   r   g  s
    
z'_compare_eq_iterable.<locals>.<genexpr>r   r   )r   r   r   pformatr   r   r*   r   )rn   ro   r   r   r   left_formattingright_formattingr&   r   r   r   r   T  s    

	r   Sequence[Any]c                 C  s>  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	| d
|| g7 }|S )Nr0   z	At index z diff:  != r   LeftRightz contains one more item: z
 contains z more items, first extra item: )rH   bytesr>   r   r   r7   r   r   )rn   ro   r   r   comparing_bytesr&   len_left	len_rightr   
left_valueright_valuelen_diffdir_with_moreextrar   r   r   r   q  sN   	

r   AbstractSet[Any]c                 C  s0   g }| td| || | td|| | |S )Nrn   ro   )r   _set_one_sided_diffrn   ro   r   r   r&   r   r   r   r     s   r   c                 C     t | ||}|sdgS |S Nrw   )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 )Nro   r   rn   ro   r   r   r   r   r   r        r   c                 C  s   t d| ||S )Nrn   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:)r7   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|dkrdnd d ||t fdd|D   || }t|}|r|d| d|dkrdnd d ||tfdd|D   |S )Nc                   s&   i | ]} | | kr| | qS r   r   r   krn   ro   r   r   
<dictcomp>  s   & z$_compare_eq_dict.<locals>.<dictcomp>rt   	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 z
 more itemr0   r/   rC   :c                      i | ]}| | qS r   r   r   )rn   r   r   r         zRight contains c                   r   r   r   r   )ro   r   r   r     r   )	rS   intersectionr>   pprintr   r   r   r7   r   )rn   ro   r   r   r&   set_left	set_rightcommonsamer   r   
extra_leftlen_extra_leftextra_rightlen_extra_rightr   r   r   r     sP   


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   
<listcomp>)  s    z#_compare_eq_cls.<locals>.<listcomp>c                 S  s   g | ]
}t |d r|jqS )eq)rY   r   )r   fieldr   r   r   r   ,  s    Fr;   r/   rt   r   r   zMatching attributes:zDiffering attributes:z$Drill down into differing attribute r   z: r   c                   s   g | ]} | qS r   r   r   rD   r   r   r   N  s    )rl   r_   dataclassesfieldsrb   ra   r[   rW   rY   r7   r>   r   r   r   r   r~   )rn   ro   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|}t| dd dg}|D ]$}	|	dr4q,|	dr:q,|	drK|d|	dd    q,||	 q,|S )	Nr   )ru   z is contained here:Skippingz- z+ r;   rt   )findr>   r   r%   r   r=   r7   )
r   r   r   indexheadtailcorrect_textr   newdiffrB   r   r   r   r   W  s   



r   r    r!   )r&   r   r   r   )r&   r   r   r.   )r+   r:   r   r.   )rE   r   r   rF   )rV   r   r   rF   )rV   rf   r   rF   )F)
rm   r   rn   r   ro   r   rp   rF   r   rq   )r   )
rn   r   ro   r   r   r   r   r   r   r.   )
rn   r   ro   r   r   r   r   r   r   r.   )
rn   r   ro   r   r   r   r   r   r   r.   )
rn   r   ro   r   r   r   r   r   r   r.   )
rn   r   ro   r   r   r   r   r   r   r.   )
r   r   r   r   r   r   r   r   r   r.   )
rn   r   ro   r   r   r   r   r   r   r.   )r   r   r   r   r   r   r   r.   )>__doc__
__future__r   collections.abcrI   r   r   r   r   r   AbstractSetr   typingr   r	   r
   unicodedatar   r   r   _pytest._code_pytest._io.pprintr   _pytest._io.safereprr   r   _pytest.compatr   _pytest.configr   r   __annotations__r   r   r   r%   r-   r(   r)   rL   rO   rR   rU   r[   r_   rb   re   rl   r   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s|   



#







G&;!@
	
.7