a
    *ñ»j=  ã                   @  s�   d Z ddlmZ ddlmZ ddlmZ ddlmZ dZ	e	d Z
dZd	d
d	dœdd„Zd
ddœdd„Zd	ddd	dœdd„Zd	dd	dœdd„ZdS )zÑUtilities for truncating assertion output.

Current default behaviour is to truncate assertion explanations at
terminal lines, unless running with an assertions verbosity level of at least 2 or running on CI.
é    )Úannotations)Úutil)ÚConfig)ÚItemé   éP   zuse '-vv' to showz	list[str]r   )ÚexplanationÚitemÚreturnc                 C  s$   t |ƒ\}}}|r t| ||d�S | S )zGTruncate this assertion explanation if the given test item is eligible.)Ú	max_linesÚ	max_chars)Ú_get_truncation_parametersÚ_truncate_explanation)r   r	   Úshould_truncater   r   © r   ú@E:\soccer\ml_env\Lib\site-packages\_pytest/assertion/truncate.pyÚtruncate_if_required   s    ýr   ztuple[bool, int, int])r	   r
   c                 C  s~   | j  d¡}t|dur|ntƒ}| j  d¡}t|dur:|ntƒ}| j  tj¡}|dk o^t 	¡  }|or|dkpr|dk}|||fS )zgReturn the truncation parameters related to the given item, as (should truncate, max lines, max chars).Ztruncation_limit_linesNZtruncation_limit_charsé   r   )
ÚconfigZgetiniÚintÚDEFAULT_MAX_LINESÚDEFAULT_MAX_CHARSZget_verbosityr   ZVERBOSITY_ASSERTIONSr   Zrunning_on_ci)r	   r   r   Úverboser   r   r   r   r      s    r   r   )Úinput_linesr   r   r
   c           	      C  sö   t d | ¡ƒ}|d }|d }t | ƒ|kr6||kr6| S |dkrL| d|… }n| }d}t d |¡ƒ|krz|dkrzt||ƒ}nd}|| krŠ|S t | ƒt |ƒ }|d rÀ|d d	 |d< |rÈ|d
7 }nd	|d< g |¢d‘d|› d|d
krædnd› dt› �‘S )a  Truncate given list of strings that makes up the assertion explanation.

    Truncates to either max_lines, or max_chars - whichever the input reaches
    first, taking the truncation explanation into account. The remaining lines
    will be replaced by a usage message.
    Ú éF   r   r   NTFéÿÿÿÿz...é   z...Full output truncated (z lineÚsz
 hidden), )ÚlenÚjoinÚ_truncate_by_char_countÚ	USAGE_MSG)	r   r   r   Zinput_char_countZtolerable_max_charsZtolerable_max_linesZtruncated_explanationZtruncated_charZtruncated_line_countr   r   r   r   4   sJ    ÿ
ÿþÿ
ÿþÿÿýr   )r   r   r
   c                 C  sp   d}t | ƒD ](\}}|t|ƒ |kr( q6|t|ƒ7 }q| d |… }| | }|rb|| }|d |… }| |¡ |S )Nr   )Ú	enumerater   Úappend)r   r   Ziterated_char_countZiterated_indexZ
input_lineZtruncated_resultZ
final_lineZfinal_line_truncate_pointr   r   r   r!   z   s    
r!   N)Ú__doc__Ú
__future__r   Z_pytest.assertionr   Z_pytest.configr   Z_pytest.nodesr   r   r   r"   r   r   r   r!   r   r   r   r   Ú<module>   s   F