3 ^9c@sdZddlmZmZddlmZdZdZdZdZ dZ dZ ee ee ee Z dd Z d d Zd d dZddZddZddZddZeddZddZddZddZdS)!zVarious utility functions.) namedtuple OrderedDict) commonprefixTiPi icCsBt|||}|tkr>d|d|||t||df}|S)Nz%s[%d chars]%s)len_PLACEHOLDER_LEN)s prefixlenZ suffixlenZskipr%/usr/lib64/python3.6/unittest/util.py_shortens&r csttt|}ttt|}|tkr(|St|tt|tt}|t krxt t|tfdd|DSt tt tfdd|DS)Nc3s|]}|dVqdSNrZ.0rZprefixrrr 'sz'_common_shorten_repr..c3s&|]}t|dttVqdSr )r _MIN_DIFF_LEN _MIN_END_LENr r rr r*s) ZtupleZmap safe_reprZmaxr _MAX_LENGTHr_MIN_BEGIN_LENr_MIN_COMMON_LENr )ZargsZmaxlenZ common_lenrr r _common_shorten_reprs  rFc CsRy t|}Wntk r*tj|}YnX| s>t|tkrB|S|dtdS)Nz [truncated]...)ZreprZ ExceptionobjectZ__repr__rr)ZobjZshortresultrrr r-s rcCsd|j|jfS)Nz%s.%s)Z __module__Z __qualname__)Zclsrrr strclass6srcCs*d}}g}g}xy||}||}||kr\|j||d7}x|||krX|d7}qBWn||kr|j||d7}xf|||kr|d7}qxWnL|d7}zx|||kr|d7}qWWd|d7}x|||kr|d7}qWXWqtk r|j||d|j||dPYqXqW||fS)arFinds 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. rN)appendZ IndexErrorZextend)expectedactualijmissingZ unexpectedZeZarrr sorted_list_difference9s:   r c CsLg}x>|rB|j}y|j|Wqtk r>|j|YqXqW||fS)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.)ZpopZremoveZ ValueErrorr)rrrZitemrrr unorderable_list_differencebsr!cCs||k||kS)z.Return -1 if x < y, 0 if x == y and 1 if x > yr)ZxZyrrr three_way_cmpssr"ZMismatchzactual expected valuecCsDt|t|}}t|t|}}t}g}xt|D]\}} | |krJq8d} } x.t||D] } || | kr^| d7} ||| <q^Wx,t|D] \} } | | kr| d7} ||| <qW| | kr8t| | | }|j|q8Wxlt|D]`\}} | |krqd} x2t||D]$} || | kr| d7} ||| <qWtd| | }|j|qW|S)HReturns list of (cnt_act, cnt_exp, elem) triples where the counts differrr)ZlistrrZ enumerateZrange _Mismatchr)rrrtZmZnZNULLrrelemcnt_scnt_trZ other_elemdiffrrr _count_diff_all_purposeys<     r*cCs,t}x |D]}|j|dd||<q W|S)z@Return dict of element counts, in the order they were first seenrr)rget)ZiterableZcr&rrr _ordered_counts r,c Cst|t|}}g}x>|jD]2\}}|j|d}||kr t|||}|j|q Wx2|jD]&\}}||kr`td||}|j|q`W|S)r#r)r,Zitemsr+r$r) rrrr%rr&r'r(r)rrr _count_diff_hashables   r-N)F)Z__doc__Z collectionsrrZos.pathrZ __unittestrrrrrrr rrrr r!r"r$r*r,r-rrrr Zs*  ) #