B
    ”Ü‡\/  ã               @   st   d Z ddlmZ ddlmZ ddlmZ ddlZddlZdZdZdZ	dd	d
„Z
dd„ Zdd„ Zddd„Z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.
é    )Úabsolute_import)Údivision)Úprint_functionNé   i€  zuse '-vv' to showc             C   s   t |ƒrt| ƒS | S )zQ
    Truncate this assertion explanation if the given test item is eligible.
    )Ú_should_truncate_itemÚ_truncate_explanation)ZexplanationÚitemZ
max_length© r	   ú9lib/python3.7/site-packages/_pytest/assertion/truncate.pyÚtruncate_if_required   s    r   c             C   s   | j jj}|dk otƒ  S )zC
    Whether or not this test item is eligible for truncation.
    é   )ZconfigZoptionÚverboseÚ_running_on_ci)r   r   r	   r	   r
   r      s    
r   c              C   s   ddg} t dd„ | D ƒƒS )z0Check if we're currently running on a CI system.Z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   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 |¡7 }n|d |¡7 }|d	 t¡7 }| t 	d¡t 	|¡g¡ |S )
zç
    Truncate 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 ({} line hidden)z ({} lines hidden)z, {})
ÚDEFAULT_MAX_LINESÚDEFAULT_MAX_CHARSÚlenÚjoinÚ_truncate_by_char_countÚformatÚ	USAGE_MSGÚextendÚsixZ	text_type)Úinput_linesZ	max_linesÚ	max_charsZinput_char_countZtruncated_explanationZtruncated_line_countÚmsgr	   r	   r
   r   +   s&    
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   R   s    
r   )N)NN)Ú__doc__Z
__future__r   r   r   r   r    r   r   r   r   r   r   r   r   r	   r	   r	   r
   Ú<module>   s   
	
'