o
    Ú­jYF  ã                   @   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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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< 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+d,„Z*d&ede#fd-d.„Z+d&ede#fd/d0„Z,	1dOd2ed3ed4ed5e#dee
e  f
d6d7„Z-dPd3ed4ed8ede
e fd9d:„Z.dPd3ed4ed8ede
e fd;d<„Z/de
e ddfd=d>„Z0	dPd3e	e d4e	e d8ede
e fd?d@„Z1	dPd3ee d4ee d8ede
e fdAdB„Z2	dPd3ee d4ee d8ede
e fdCdD„Z3	dPd3eeef d4eeef d8ede
e fdEdF„Z4d3ed4ed8ede
e fdGdH„Z5dPdIedJed8ede
e fdKdL„Z6de#fdMdN„Z7dS )Qz"Utilities for assertion debugging.é    N)ÚAbstractSet)ÚAny)ÚCallable)ÚIterable)ÚList)ÚMapping)ÚOptional)ÚSequence)Ú	normalize)Úoutcomes)Ú_pformat_dispatch)Úsaferepr)Úsaferepr_unlimited)ÚConfigÚ_reprcompareÚ_assertion_passÚ_configÚexplanationÚreturnc                 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Úresult© r   úS/var/www/html/CropPilot/venv/lib/python3.10/site-packages/_pytest/assertion/util.pyÚ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 )	zãReturn 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   3   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¡rƒt|ƒnt|ƒd }| d	| |dd…  ¡ qt|ƒdksŸJ ‚|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    r$   zand   zwhere z +ú  r!   )r"   r#   r"   )ÚlistÚ
startswithr&   ÚlenÚpop)r   r   ÚstackÚstackcntÚlineÚsÚindentr   r   r   r   D   s,   	

,
r   Úxc                 C   s   t | tjjƒot | tƒ S ©N)Ú
isinstanceÚcollectionsÚabcr	   Ústr©r3   r   r   r   Ú
issequenceg   ó   r:   c                 C   ó
   t | tƒS r4   )r5   r8   r9   r   r   r   Úistextk   ó   
r=   c                 C   r<   r4   )r5   Údictr9   r   r   r   Úisdicto   r>   r@   c                 C   s   t | ttfƒS r4   )r5   ÚsetÚ	frozensetr9   r   r   r   Úissets   s   rC   Úobjc                 C   s   t | tƒot| dd ƒd uS )NÚ_fields)r5   ÚtupleÚgetattr©rD   r   r   r   Úisnamedtuplew   r;   rI   c                 C   ó   t | dd ƒd uS )NÚ__dataclass_fields__©rG   rH   r   r   r   Ú	isdatacls{   ó   rM   c                 C   rJ   )NÚ__attrs_attrs__rL   rH   r   r   r   Úisattrs   rN   rP   c                 C   s*   z
t | ƒ t| ƒ W S  ty   Y dS w )NF)Úiterr=   Ú	ExceptionrH   r   r   r   Ú
isiterableƒ   s   ÿrS   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__rT   rU   rP   )rD   Úcode_filenamer   r   r   Úhas_default_eq‹   s   
rY   FÚopÚleftÚrightÚ	use_asciic                 C   s*  |   d¡}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|› �}	d	}
z|d
krZt|||ƒ}
n|dkrlt|ƒrlt|ƒrlt	|||ƒ}
W n t
jyv   ‚  ty‹   d tjj ¡  ¡ ¡dg}
Y nw |
s�d	S |	g|
 S )z<Return specialised explanations for some operators/operands.ÚverboseÚNFDr   )r]   éA   é   )Úmaxsizer]   ú Nz==znot inz?(pytest_assertion plugin: representation of details failed: {}.z+ Probably an object has a faulty __repr__.))Ú	getoptionr5   r8   r
   r   r,   r   Ú_compare_eq_anyr=   Ú_notin_textr   ÚExitrR   ÚformatÚ_pytestÚ_codeÚExceptionInfoÚfrom_currentÚ_getreprcrash)ÚconfigrZ   r[   r\   r]   r^   Ú	left_reprÚ
right_reprrb   Úsummaryr   r   r   r   Úassertrepr_compare    sF   

ÿýþ€ÿüÿ
rr   r^   c                 C   s,  g }t | ƒrt |ƒrt| ||ƒ}|S ddlm} t| |ƒs"t||ƒr:t| |ƒr)| n|}t| |ƒr2|n| }| |¡}nGt| ƒt|ƒkrUt| ƒsNt| ƒsNt	| ƒrUt
| ||ƒ}n,t| ƒrdt|ƒrdt| ||ƒ}nt| ƒrst|ƒrst| ||ƒ}nt| ƒr�t|ƒr�t| ||ƒ}t| ƒr”t|ƒr”t| ||ƒ}| |¡ |S )Nr   )Ú
ApproxBase)r=   Ú
_diff_textÚ_pytest.python_apirs   r5   Ú_repr_compareÚtyperM   rP   rI   Ú_compare_eq_clsr:   Ú_compare_eq_sequencerC   Ú_compare_eq_setr@   Ú_compare_eq_dictrS   Ú_compare_eq_iterableÚextend)r[   r\   r^   r   rs   Úapprox_sideÚ
other_sideÚexplr   r   r   re   Ô   s6   åÿÿÿ
re   c                 C   sR  ddl m} g }|dk rzd}ttt| ƒt|ƒƒƒD ]}| | || kr% nq|dkr?|d8 }d| g}| |d… } ||d… }t| ƒt|ƒkrztt| ƒƒD ]}| |  ||  kr[ nqM|dkrz|d8 }|d |¡g7 }| d| … } |d| … }d	}|  ¡ s„| ¡ r•tt| ƒƒ} tt|ƒƒ}|d
g7 }|dd„ || 	|¡|  	|¡ƒD ƒ7 }|S )zµReturn 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 showNzASkipping {} 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©Ú.0r0   r   r   r   Ú
<listcomp>   s    ÿÿz_diff_text.<locals>.<listcomp>)
Údifflibr�   ÚrangeÚminr,   rh   ÚisspaceÚreprr8   Ú
splitlines)r[   r\   r^   r�   r   ÚiÚkeependsr   r   r   rt   ÷   sH   ÿÿÿþ
þrt   c                 C   sŒ   | d dd… }|dv r!d| d dd…  | d< |g|  | dd…< | d dd… }|dv rD| d dd… d | d< | |g | dd…< dS dS )	z6Move opening/closing parenthesis/bracket to own lines.r   Nr   )ú(ú[r    rc   r$   )ú)ú]r!   ú,r   )r   ÚopeningÚclosingr   r   r   Ú _surrounding_parens_on_own_lines'  s   þr—   c           	      C   s®   |dkr
t ƒ s
dgS dd l}t | ¡ ¡ }t |¡ ¡ }t|ƒ}t|ƒ}||kr4t| ƒ ¡ }t|ƒ ¡ }|dks<|dkrDt|ƒ t|ƒ dg}| dd„ | 	||¡D ƒ¡ |S )Nr   zUse -v to get more diffr   z
Full diff:c                 s   s   � | ]}|  ¡ V  qd S r4   )Úrstripr…   r   r   r   Ú	<genexpr>L  s   € 
ÿz'_compare_eq_iterable.<locals>.<genexpr>)
Úrunning_on_cirˆ   ÚpprintÚpformatr�   r,   r   r—   r}   r�   )	r[   r\   r^   rˆ   Úleft_formattingÚright_formattingÚ
lines_leftÚlines_rightr   r   r   r   r|   3  s$   

ÿr|   c                 C   s   t | tƒo	t |tƒ}g }t| ƒ}t|ƒ}tt||ƒƒD ]5}| | || krP|r8| ||d … }|||d … }	n| | }|| }	|d|› d|›d|	›�g7 } nq|rU|S || }
|
rŽ|
dkrhd}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)r5   Úbytesr,   r‰   rŠ   r   )r[   r\   r^   Úcomparing_bytesr   Úlen_leftÚ	len_rightrŽ   Ú
left_valueÚright_valueÚlen_diffÚdir_with_moreÚextrar   r   r   ry   R  sB   	ïüÿÿry   c                 C   sd   g }| | }||  }|r|  d¡ |D ]	}|  t|ƒ¡ q|r0|  d¡ |D ]	}|  t|ƒ¡ q&|S )NzExtra items in the left set:zExtra items in the right set:)r&   r   )r[   r\   r^   r   Ú	diff_leftÚ
diff_rightÚitemr   r   r   rz   ‡  s   

rz   c                    st  g }t ˆ ƒ}t ˆƒ}| |¡}‡ ‡fdd„|D ƒ}|r)|dk r)|dt|ƒ g7 }n|r9|dg7 }|t |¡ ¡ 7 }‡ ‡fdd„|D ƒ}|rd|dg7 }|D ]}	|t|	ˆ |	 iƒd	 t|	ˆ|	 iƒ g7 }qL|| }
t|
ƒ}|rŽ| d
||dkrxdndf ¡ | t ‡ fdd„|
D ƒ¡ ¡ ¡ || }t|ƒ}|r¸| d||dkr¢dndf ¡ | t ‡fdd„|D ƒ¡ ¡ ¡ |S )Nc                    s&   i | ]}ˆ | ˆ| kr|ˆ | “qS r   r   ©r†   Úk©r[   r\   r   r   Ú
<dictcomp>Ÿ  s   & z$_compare_eq_dict.<locals>.<dictcomp>ra   ú,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   r1   c                    ó   i | ]}|ˆ | “qS r   r   r°   )r[   r   r   r³   ²  ó    zRight contains %d more item%s:c                    r¶   r   r   r°   )r\   r   r   r³   ¼  r·   )	rA   Úintersectionr,   r›   rœ   r�   r   r&   r}   )r[   r\   r^   r   Úset_leftÚ	set_rightÚcommonÚsameÚdiffr±   Ú
extra_leftÚlen_extra_leftÚextra_rightÚlen_extra_rightr   r²   r   r{   ˜  sL   


,ÿÿÿÿÿÿ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 ]*}t| |ƒ}
t||ƒ}|	dd| dˆ ||
|f 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)rG   rÃ   )r†   Úfieldr   r   r   r‡   Ë  s    Fr)   r   ra   r´   zMatching attributes:zDiffering attributes:z'Drill down into differing attribute %s:z%s%s: %r != %rc                    s   g | ]}ˆ | ‘qS r   r   r…   ©r2   r   r   r‡   í  s    ÿÿ)rY   rM   ÚdataclassesÚfieldsrP   rO   rI   rE   rG   r&   r,   r›   rœ   r�   re   )r[   r\   r^   rÈ   Ú
all_fieldsÚfields_to_checkr¼   r½   rÆ   r   Ú
field_leftÚfield_rightr   rÇ   r   rx   Á  sT   





ý

þrx   Ú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‚   )rb   ÚSkippingz- z+ r)   ra   )Úfindr,   rt   r   r+   r&   )
rÎ   rÏ   r^   ÚindexÚheadÚtailÚcorrect_textr½   Únewdiffr0   r   r   r   rf   ô  s   



rf   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 r4   )ÚosÚenviron)r†   Úvarr   r   r   r™   
  s   € z running_on_ci.<locals>.<genexpr>)Úany)Úenv_varsr   r   r   rš     s   rš   )F)r   )8Ú__doc__Úcollections.abcr6   rÙ   r›   Útypingr   r   r   r   r   r   r   r	   Úunicodedatar
   Ú_pytest._coderi   r   Ú_pytest._io.safereprr   r   r   Ú_pytest.configr   r   r8   ÚobjectÚ__annotations__r   Úintr   r   r   r   Úboolr:   r=   r@   rC   rI   rM   rP   rS   rY   rr   re   rt   r—   r|   ry   rz   r{   rx   rf   rš   r   r   r   r   Ú<module>   sÀ    "#ÿ
þÿÿÿÿÿ

þ 4 #0ÿÿÿÿ
þ ÿÿÿÿ
þ6ÿÿÿÿ
þÿ
ÿ
ÿÿ
þ) 3