B
    `p                 @   s   d Z ddl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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.
    N)List)Optional)Item   i  zuse '-vv' to show)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   b/home/kop/projects/devel/pgwui/test_venv/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verbose_running_on_ci)r   r   r   r   r   r
      s    
r
   )r	   c              C   s   ddg} t dd | D S )z0Check if we're currently running on a CI system.CIZBUILD_NUMBERc             s   s   | ]}|t jkV  qd S )N)osenviron).0varr   r   r   	<genexpr>$   s    z!_running_on_ci.<locals>.<genexpr>)any)Zenv_varsr   r   r   r   !   s    r   )input_lines	max_lines	max_charsr	   c             C   s   |dkrt }|dkrt}td| }t| |kr>||kr>| S | d| }t||}|d d |d< t| t| }|d7 }d}|dkr|d| d7 }n|d| d	7 }|d
t 7 }|dt|g |S )zTruncate given list of strings that makes up the assertion explanation.

    Truncates to either 8 lines, or 640 characters - whichever the input reaches
    first. The remaining lines will be replaced by a usage message.
    N z...   z...Full output truncatedz (z line hidden)z lines hidden)z, )DEFAULT_MAX_LINESDEFAULT_MAX_CHARSlenjoin_truncate_by_char_count	USAGE_MSGextendstr)r   r   r   Zinput_char_countZtruncated_explanationZtruncated_line_countmsgr   r   r   r   '   s&    
r   )r   r   r	   c             C   s   t d| |kr| S d}x2t| D ]&\}}|t | |kr>P |t |7 }q$W | d | }| | }|rz|| }|d | }|| |S )Nr   r   )r#   r$   	enumerateappend)r   r   Ziterated_char_countZiterated_indexZ
input_lineZtruncated_resultZ
final_lineZfinal_line_truncate_pointr   r   r   r%   Q   s    
r%   )N)NN)__doc__r   typingr   r   Z_pytest.nodesr   r!   r"   r&   r(   intr   boolr
   r   r   r%   r   r   r   r   <module>   s    &