U
    42‹ik  ã                   @  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	dZ
dZdd
ddd
dœdd„Zdddœdd„Zd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é   i€  zuse '-vv' to showNz	list[str]r   z
int | None)ÚexplanationÚitemÚ
max_lengthÚreturnc                 C  s   t |ƒrt| ƒS | S )zGTruncate this assertion explanation if the given test item is eligible.)Ú_should_truncate_itemÚ_truncate_explanation)r   r   r	   © r   ú>/tmp/pip-unpacked-wheel-7n2p7kht/_pytest/assertion/truncate.pyÚtruncate_if_required   s    r   Úbool)r   r
   c                 C  s    | j  tj¡}|dk ot ¡  S )z9Whether or not this test item is eligible for truncation.é   )ÚconfigZget_verbosityr   ZVERBOSITY_ASSERTIONSr   Zrunning_on_ci)r   Úverboser   r   r   r      s    r   )Úinput_linesÚ	max_linesÚ	max_charsr
   c           	      C  sè   |dkrt }|dkrt}td | ¡ƒ}|d }|d }t| ƒ|krN||krN| S | d|… }d}td |¡ƒ|kr|t||ƒ}nd}t| ƒt|ƒ }|d r¶|d d |d< |r¾|d	7 }nd|d< |dd
|› d|d	krÖdnd› dt› f•S )a  Truncate given list of strings that makes up the assertion explanation.

    Truncates to either 8 lines, or 640 characters - whichever the input reaches
    first, taking the truncation explanation into account. The remaining lines
    will be replaced by a usage message.
    NÚ éF   r   TFéÿÿÿÿz...é   z...Full output truncated (z lineÚsz
 hidden), )ÚDEFAULT_MAX_LINESÚDEFAULT_MAX_CHARSÚ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   "   s>    ÿ
ÿþ ÿ
 ýr   Úint)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    f   s    
r    )N)NN)Ú__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    ÿ	  ýD