B
    sd                 @   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 )zUtilities 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   I/home/dcms/DCMS/lib/python3.7/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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rd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   TFz...   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   !   s2    

r   )r   r   r
   c             C   sr   d}x2t | D ]&\}}|t| |kr(P |t|7 }qW | d | }| | }|rd|| }|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    ?