3 \9ã@s°dZddlmZmZddlmZdZdZdZdZ dZ dZ ee ee ee Z dd „Z d d „Zd d d„Zdd„Zdd„Zdd„Zdd„ZeddƒZdd„Zdd„Zdd„ZdS)!zVarious utility functions.é)Ú namedtupleÚ OrderedDict)Ú commonprefixTéPé écCsBt|ƒ||}|tkr>d|d|…||t|ƒ|d…f}|S)Nz%s[%d chars]%s)ÚlenÚ_PLACEHOLDER_LEN)ÚsÚ prefixlenZ suffixlenÚskip©r ú%/usr/lib64/python3.6/unittest/util.pyÚ_shortens&rcsœttt|ƒƒ}ttt|ƒƒ}|tkr(|St|ƒ‰tˆƒ‰t|ˆtt}|t krxt ˆt|ƒ‰t‡‡fdd„|DƒƒSt ˆtt ƒ‰t‡‡fdd„|DƒƒS)Nc3s|]}ˆ|ˆd…VqdS)Nr )Ú.0r )Úprefixr r rú 'sz'_common_shorten_repr..c3s&|]}ˆt|ˆd…ttƒVqdS)N)rÚ _MIN_DIFF_LENÚ _MIN_END_LEN)rr )rr r rr*s) ÚtupleÚmapÚ safe_reprÚmaxrÚ _MAX_LENGTHrÚ_MIN_BEGIN_LENr Ú_MIN_COMMON_LENr)ÚargsÚmaxlenZ common_lenr )rr rÚ_common_shorten_reprs  rFc CsRy t|ƒ}Wntk r*tj|ƒ}YnX| s>t|ƒtkrB|S|dt…dS)Nz [truncated]...)ÚreprÚ ExceptionÚobjectÚ__repr__rr)ÚobjZshortÚresultr r rr-s rcCsd|j|jfS)Nz%s.%s)Ú __module__Ú __qualname__)Úclsr r rÚstrclass6sr(cCs*d}}g}g}�xyÌ||}||}||kr\|j|ƒ|d7}xœ|||krX|d7}qBWn‚||kr’|j|ƒ|d7}xf|||krŽ|d7}qxWnL|d7}zx|||kr´|d7}qžWWd|d7}x|||krÚ|d7}qÄWXWqtk �r|j||d…ƒ|j||d…ƒPYqXqW||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. réN)ÚappendÚ IndexErrorÚextend)ÚexpectedÚactualÚiÚjÚmissingZ unexpectedÚeÚar r rÚsorted_list_difference9s:   r4c CsLg}x>|rB|jƒ}y|j|ƒWqtk r>|j|ƒYqXqW||fS)z­Same 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.r1Úitemr r rÚunorderable_list_differencebsr9cCs||k||kS)z.Return -1 if x < y, 0 if x == y and 1 if x > yr )ÚxÚyr r rÚ three_way_cmpssr<ZMismatchzactual expected valuecCsDt|ƒt|ƒ}}t|ƒt|ƒ}}tƒ}g}x¢t|ƒD]–\}} | |krJq8d} } x.t||ƒD] } || | kr^| d7} ||| <q^Wx,t|ƒD] \} } | | krŒ| d7} ||| <qŒW| | kr8t| | | ƒ}|j|ƒq8Wxlt|ƒD]`\}} | |krîqÜd} x2t||ƒD]$} || | k�rþ| d7} ||| <�qþWtd| | ƒ}|j|ƒqÜW|S)zHReturns list of (cnt_act, cnt_exp, elem) triples where the counts differrr))Úlistrr!Ú enumerateÚrangeÚ _Mismatchr*)r.r-r ÚtÚmÚnZNULLr$r/ÚelemÚcnt_sÚcnt_tr0Z other_elemÚdiffr r rÚ_count_diff_all_purposeys<     rHcCs,tƒ}x |D]}|j|dƒd||<q W|S)z@Return dict of element counts, in the order they were first seenrr))rÚget)ÚiterableÚcrDr r rÚ_ordered_countœs rLc CsŽt|ƒt|ƒ}}g}x>|jƒD]2\}}|j|dƒ}||kr t|||ƒ}|j|ƒq Wx2|jƒD]&\}}||kr`td||ƒ}|j|ƒq`W|S)zHReturns list of (cnt_act, cnt_exp, elem) triples where the counts differr)rLÚitemsrIr@r*) r.r-r rAr$rDrErFrGr r rÚ_count_diff_hashable£s   rNN)F)Ú__doc__Ú collectionsrrZos.pathrZ __unittestrr rrrrrrrr(r4r9r<r@rHrLrNr r r rÚs*  ) #