U
    k]e_                     @   s   d Z ddlmZmZ ddlmZ dZdZdZdZ	dZ
dZee	e e e e
  Zedks\tdd	 Zd
d ZdddZdd Zdd Zdd Zdd ZeddZdd Zdd ZdS )zVarious utility functions.    )
namedtupleCounter)commonprefixTP         c                 C   sB   t | | | }|tkr>d| d | || t | | d  f } | S )Nz%s[%d chars]%s)len_PLACEHOLDER_LEN)s	prefixlenZ	suffixlenskip r   #/usr/lib/python3.8/unittest/util.py_shorten   s    &r   c                     s   t tt| } ttt| }|tkr(| S t|  t t| t t  }|t	krtt t	 |  tk spt
t t| t  fdd| D S t tt	 t  fdd| D S )Nc                 3   s   | ]} |d   V  qd S Nr   .0r
   prefixr   r   r   	<genexpr>'   s     z'_common_shorten_repr.<locals>.<genexpr>c                 3   s&   | ]} t |d  tt V  qd S r   )r   _MIN_DIFF_LEN_MIN_END_LENr   r   r   r   r   *   s   )tuplemap	safe_reprmaxr   _MAX_LENGTHr   _MIN_BEGIN_LENr	   _MIN_COMMON_LENAssertionErrorr   )argsmaxlenZ
common_lenr   r   r   _common_shorten_repr   s*    
r"   Fc                 C   sP   zt | }W n tk
r*   t| }Y nX |r<t|tk r@|S |d t d S )Nz [truncated]...)repr	Exceptionobject__repr__r   r   )objZshortresultr   r   r   r   -   s    r   c                 C   s   d| j | jf S )Nz%s.%s)
__module____qualname__)clsr   r   r   strclass6   s    r,   c                 C   s  d }}g }g }z| | }|| }||k rT| | |d7 }| | |kr|d7 }q<nv||kr| | |d7 }|| |kr|d7 }qnnD|d7 }z| | |kr|d7 }qW 5 |d7 }|| |kr|d7 }qX W q tk
r   || |d  |||d  Y qY qX q||fS )ar  Finds elements in only one or the other of two, sorted input lists.

    Returns a two-element tuple of lists.    The first list contains those
    elements in the "expected" list but not in the "actual" list, and the
    second contains those elements in the "actual" list but not in the
    "expected" list.    Duplicate elements in either input list are ignored.
    r      N)append
IndexErrorextend)expectedactualijmissingZ
unexpectedear   r   r   sorted_list_difference9   s8    

r8   c                 C   sH   g }| r@|   }z|| W q tk
r<   || Y qX q||fS )zSame behavior as sorted_list_difference but
    for lists of unorderable items (like dicts).

    As it does a linear search per item (remove) it
    has O(n*n) performance.)popremove
ValueErrorr.   )r1   r2   r5   itemr   r   r   unorderable_list_differenceb   s    r=   c                 C   s   | |k| |k  S )z.Return -1 if x < y, 0 if x == y and 1 if x > yr   )xyr   r   r   three_way_cmps   s    r@   ZMismatchzactual expected valuec                 C   s,  t | t | }}t|t| }}t }g }t|D ]\}}	|	|krHq6d }
}t||D ] }|| |	krZ|
d7 }
|||< qZt|D ] \}}||	kr|d7 }|||< q|
|kr6t|
||	}|| q6t|D ]X\}}	|	|krqd}t||D ] }|| |	kr|d7 }|||< qtd||	}|| q|S )HReturns list of (cnt_act, cnt_exp, elem) triples where the counts differr   r-   )listr   r%   	enumeraterange	_Mismatchr.   )r2   r1   r
   tmnZNULLr(   r3   elemcnt_scnt_tr4   Z
other_elemdiffr   r   r   _count_diff_all_purposey   s<    


rM   c           	      C   s   t | t | }}g }| D ]2\}}||d}||krt|||}|| q| D ]&\}}||krZtd||}|| qZ|S )rA   r   )r   itemsgetrE   r.   )	r2   r1   r
   rF   r(   rI   rJ   rK   rL   r   r   r   _count_diff_hashable   s    rP   N)F)__doc__collectionsr   r   os.pathr   Z
__unittestr   r	   r   r   r   r   r   r   r"   r   r,   r8   r=   r@   rE   rM   rP   r   r   r   r   <module>   s4   

	)
#