
][\5                 @   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 d   Z d S) zVarious utility functions.    )
namedtupleOrderedDict)commonprefixTP         c             C   sX   t  |   | | } | t k rT d |  d  |  | |  t  |   | d   f }  n  |  S)Nz%s[%d chars]%s)len_PLACEHOLDER_LEN)s	prefixlenZ	suffixlenskip r   #/usr/lib/python3.4/unittest/util.py_shorten   s    4r   c                 s   t  t t |    }  t t t |    } | t k r: |  St |     t     t |  t t } | t	 k r t t t	 |  t k  s t
  t   t |    t     f d d   |  D  St   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)N)r   _MIN_DIFF_LEN_MIN_END_LEN)r   r
   )r   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   r   _common_shorten_repr   s      r   Fc             C   sc   y t  |   } Wn! t k
 r3 t j |   } Yn X| sM t |  t k  rQ | 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____name__)clsr   r   r   strclass6   s    r)   c             C   sn  d } } g  } g  } xKy|  | } | | } | | k  rw | j  |  | d 7} x |  | | k rs | d 7} qV Wn | | k r | j  |  | d 7} x | | | k r | d 7} q Wn^ | d 7} z% x |  | | k r | d 7} q WWd | d 7} x | | | k r| d 7} q WXWq t k
 r`| j |  | d   | j | | d   PYq Xq | | 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   s:    






	r5   c             C   s\   g  } xI |  rQ |  j    } y | j |  Wq	 t k
 rM | j |  Yq	 Xq	 W| | 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+   )r.   r/   r2   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  } x t |  D] \ } }	 |	 | k rl qN n  d }
 } x> t | |  D]- } | | |	 k r |
 d 7}
 | | | <q q Wx= t |  D]/ \ } } | |	 k r | d 7} | | | <q q W|
 | k rN t |
 | |	  } | j |  qN qN Wx t |  D] \ } }	 |	 | k rTq6n  d } x> t | |  D]- } | | |	 k rj| d 7} | | | <qjqjWt d | |	  } | j |  q6W| S)zHReturns list of (cnt_act, cnt_exp, elem) triples where the counts differr   r*   )listr   r"   	enumeraterange	_Mismatchr+   )r/   r.   r
   tmnZNULLr%   r0   elemcnt_scnt_tr1   Z
other_elemdiffr   r   r   _count_diff_all_purposey   s<    	



rI   c             C   s8   t    } x( |  D]  } | j | d  d | | <q W| S)z@Return dict of element counts, in the order they were first seenr   r*   )r   get)iterablecrE   r   r   r   _ordered_count   s    	rM   c       	      C   s   t  |   t  |  } } g  } xZ | j   D]L \ } } | j | d  } | | k r, t | | |  } | j |  q, q, WxH | j   D]: \ } } | | k r t d | |  } | j |  q q W| S)zHReturns list of (cnt_act, cnt_exp, elem) triples where the counts differr   )rM   itemsrJ   rA   r+   )	r/   r.   r
   rB   r%   rE   rF   rG   rH   r   r   r   _count_diff_hashable   s    rO   N)__doc__collectionsr   r   os.pathr   Z
__unittestr   r	   r   r   r   r   r   r   r   r   r)   r5   r:   r=   rA   rI   rM   rO   r   r   r   r   <module>   s,   	)#