f_dZddlmZmZddlmZdZdZdZdZ dZ dZ ee eze zeze zz Z dZ d Zdd Zd Zd ZdZdZeddZdZdZdS)zVarious utility functions.) namedtupleCounter) commonprefixTP ct||z |z }|tkr(d|d|||t||z dfz}|S)Nz%s[%d chars]%s)len_PLACEHOLDER_LEN)s prefixlen suffixlenskips 4/opt/alt/python311/lib64/python3.11/unittest/util.py_shortenrsW q66I  )D  *9* tQs1vv 7I7J7J5KL L Hcttt|}ttt|}|t kr|St |t t |z tztzz }|tkr2tt|tfd|DSttttfd|DS)Nc32K|]}|dzVdSN.0r prefixr s r z'_common_shorten_repr..'s0::Va m+::::::rc3dK|]*}t|dttzV+dSr)r _MIN_DIFF_LEN _MIN_END_LENrs rrz'_common_shorten_repr..*sP  (1YZZ=-NNN      r) tuplemap safe_reprmaxr _MAX_LENGTHr_MIN_BEGIN_LENr _MIN_COMMON_LENr)argsmaxlen common_lenrr s @@r_common_shorten_reprr(s Y%% & &D S$ F  $  FF I9$~58HHJJO##&.*==:::::T:::::: fno > >F            rFc t|}n*#t$rt|}YnwxYw|rt |t kr|S|dt dzS)Nz [truncated]...)repr Exceptionobject__repr__r r")objshortresults rr r -sv&c &&&%%& CKK+-- ,;, "3 33s $99c$|jd|jS)N.) __module__ __qualname__)clss rstrclassr66snnnc&6&6 77rcdx}}g}g} ||}||}||kr8|||dz }|||kr|dz }|||kn||kr8|||dz }|||kr|dz }|||knm|dz } |||kr|dz }|||k|dz }|||kr|dz }|||kn'#|dz }|||kr|dz }|||kwxYwnJ#t$r=|||d|||dYnwxYwG||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. rTN)append IndexErrorextend)expectedactualijmissing unexpectedeas rsorted_list_differencerD9s IAGJ  Aq A1uuq!!!QqkQ&&FAqkQ&&Q!!!$$$QQi1nnFAQi1nnQ"1+**Q#1+**FA )q..Q!)q..FA )q..Q!)q......    NN8ABB< ( ( (   fQRRj ) ) ) E /6 J s+BDC:#D$DDAE  E cg}|rR|} ||n%#t$r||YnwxYw|R||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 ValueErrorr9)r<r=r@items runorderable_list_differencerJbs G !||~~ ! MM$     ! ! ! NN4  ! ! F?s0AAc||k||kz S)z.Return -1 if x < y, 0 if x == y and 1 if x > yr)xys r three_way_cmprNss Ea!e rMismatchzactual expected valuect|t|}}t|t|}}t}g}t|D]\}} | |ur dx} } t ||D]} || | kr | dz } ||| <t|D]\} } | | kr | dz } ||| <| | kr&t | | | }||t|D][\}} | |ur d} t ||D]} || | kr | dz } ||| <t d| | }||\|S)HReturns list of (cnt_act, cnt_exp, elem) triples where the counts differrr8)listr r, enumeraterange _Mismatchr9)r=r<r tmnNULLr0r>elemcnt_scnt_tr? other_elemdiffs r_count_diff_all_purposer_ys <<hqA q663q66qA 88D FQ<<  4 4<< q!  Att|| !&q\\  MAzT!! ! E>>UE400D MM$   Q<<  4 4<< q!  Att|| !E4(( d Mrct|t|}}g}|D]G\}}||d}||kr&t|||}||H|D]/\}}||vr&td||}||0|S)rQr)ritemsgetrUr9) r=r<r rVr0rZr[r\r^s r_count_diff_hashablercs 6??GH--qA Fwwyy  edA E>>UE400D MM$   wwyy  e q==Qt,,D MM$    MrN)F)__doc__ collectionsrros.pathr __unittestr"r r#rr$rrr(r r6rDrJrNrUr_rcrrrrhs( ++++++++    !11OC !#/01       *4444888&&&R" Jz#: ; ; !!!Fr