a
    ˆÏ?e  ã                   @   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ee eee ee d
œdd„Zeedœdd„Zdee ee ee ee dœdd„Zee eee dœdd„Zd	S )z±Utilities for truncating assertion output.

Current default behaviour is to truncate assertion explanations at
~8 terminal lines, unless running in "-vv" mode or running on CI.
é    )ÚList)ÚOptional)Úutil)ÚItemé   i€  zuse '-vv' to showN)Ú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   ú]/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/_pytest/assertion/truncate.pyÚtruncate_if_required   s    r   )r   r
   c                 C   s   | j jj}|dk ot ¡  S )z9Whether or not this test item is eligible for truncation.é   )ÚconfigÚoptionÚverboser   Zrunning_on_ci)r   r   r   r   r   r      s    
r   )Úinput_linesÚ	max_linesÚ	max_charsr
   c           	      C   sè   |du rt }|du 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› �g 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   !   sD    ÿ
ÿþÿ
ÿÿþ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    d   s    
r    )N)NN)Ú__doc__Útypingr   r   Z_pytest.assertionr   Z_pytest.nodesr   r   r   r!   ÚstrÚintr   Úboolr   r   r    r   r   r   r   Ú<module>   s,    ÿþ	  ýüC