o [d_@sdZddlmZmZddlmZdZdZdZdZ dZ dZ ee ee ee Z e dks.Jdd Z d d Zdd dZddZddZddZddZeddZddZddZdS)zVarious utility functions.) namedtupleCounter) commonprefixTP cCsBt|||}|tkrd|d|||t||df}|S)Nz%s[%d chars]%s)len_PLACEHOLDER_LEN)s prefixlen suffixlenskipr$/usr/lib/python3.10/unittest/util.py_shortens&rcsttt|}ttt|}|tkr|St|tt|tt}|t krJttt |tks8Jt t|tfdd|DSt tt tfdd|DS)Nc3s |] }|dVqdSNr.0r prefixr rr 'sz'_common_shorten_repr..c3s(|]}t|dttVqdSr)r _MIN_DIFF_LEN _MIN_END_LENrrrrr*s ) tuplemap safe_reprmaxr _MAX_LENGTHr_MIN_BEGIN_LENr _MIN_COMMON_LENr)argsmaxlen common_lenrrr_common_shorten_reprs*   r#FcCsNzt|}Wntyt|}Ynw|rt|tkr|S|dtdS)Nz [truncated]...)repr Exceptionobject__repr__rr)objshortresultrrrr-s  rcCsd|j|jfS)Nz%s.%s) __module__ __qualname__)clsrrrstrclass6sr.cCs^d}}g}g} z||}||}||kr0|||d7}|||kr/|d7}|||ks%n^||krN|||d7}|||krM|d7}|||ksCn@|d7}z&|||krc|d7}|||ksYW|d7}|||krx|d7}|||ksnn|d7}|||kr|d7}|||kswWnty|||d|||dY||fSwq )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. rTN)append IndexErrorextend)expectedactualijmissing unexpectedearrrsorted_list_difference9sX            r;cCsHg}|r |}z||Wnty||Ynw|s||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.)popremove ValueErrorr0)r3r4r7itemrrrunorderable_list_differencebs r@cCs||k||kS)z.Return -1 if x < y, 0 if x == y and 1 if x > yr)xyrrr three_way_cmpssrCMismatchzactual expected valuecCs,t|t|}}t|t|}}t}g}t|D]G\}} | |ur$qd} } t||D]} || | kr=| d7} ||| <q-t|D]\} } | | krR| d7} ||| <qB| | krbt| | | }||qt|D],\}} | |urpqgd} t||D]} || | kr| d7} ||| <qwtd| | }||qg|S)HReturns list of (cnt_act, cnt_exp, elem) triples where the counts differrr/)listrr& enumeraterange _Mismatchr0)r4r3r tmnNULLr*r5elemcnt_scnt_tr6 other_elemdiffrrr_count_diff_all_purposeysD      rSc Cst|t|}}g}|D]\}}||d}||kr(t|||}||q|D]\}}||vr@td||}||q-|S)rEr)ritemsgetrIr0) r4r3r rJr*rNrOrPrRrrr_count_diff_hashables     rVN)F)__doc__ collectionsrros.pathr __unittestrr rrrrrr#rr.r;r@rCrIrSrVrrrrs6     )  #