ML i%?~ddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z m Z ddlm Z ddlmZmZmZddlmZeZddlZddlmZddlZddlmZddlmZdd lmZdd lm Z m!Z!dd l"m#Z#m$Z$m%Z%m&Z&ejNjPZ(d Z)d(d Z* d)dZ+dejXdd d*dZ-dd d+dZ.d,dZ/d-dZ0d.dZ1d/dZ2ejfd0dZ4d1dZ5d2dZ6d3d4dZ7d5dZ8d6d7dZ9d8dZ:d9d Z; d:d!Zd=d$Z? d> d?d%Z@d@d&ZAdAdBd'ZBy)C) annotationsN)IterableIterator)Pattern)IOAnyCallable)TestCase)defaults)process_options)Options)test_data_prefix test_temp_dir)DataDrivenTestCase DeleteFile UpdateFilefix_cobertura_filenamecd}tj|ddgz\}}}|dk7rVtjj |tj j |t jddyy)NTz--show-tracebackz--no-silence-site-packagesrzSample check failedF)reasonpytrace)apirunsysstdoutwritestderrpytestfail)args__tracebackhide__outvalerrvalstatuss W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mypy/test/helpers.pyrun_mypyr&&sj!WWT-?A],^%^_FFF {     0%@ctjd||}|j}d}d}g}g}|D]}|j||jf|j||j f|j|j z}|j |j z}|j|j|f|j|j |f||fS)Nr)difflibSequenceMatcherget_matching_blocksappendabsize) leftrightseqblocksij left_ranges right_rangesblocks r% diff_rangesr91s  ! !$e 4C  $ $ &F A AKL *Auww<(QL) GGejj  GGejj  EGGQ<(UWWaL) *  $$r')colouroutputindentct|D]\}}|dzdk(}||d|d}t|D]\} } |r3| dk\r.| t|dz kr| dk(r|jd|zdz;|s|r|j||jd|z| z|s$|r|jd|jd|jd y) Nr:r z... zz (diff) ) enumeratelenr) rangescontentr;r<r=r4 line_range is_matchinglinesr5lines r%render_diff_rangerKJs#6* :!eqj  1 1 6 ' GAtFE Q&6LLv!786 V$ LLv, -LL+ Y' LL + r'F) tracebackc *t|}||k7rt||\}}tjj dtj dk7rdnd}t |||tjj dtj dk7rdnd}t |||tjj dtd tt||Dtt|t|}d |cxkrt|kr?nnz-assert_string_arrays_equal..s K91fq!AFQ KsrzUpdate the test output using --update-data (implies -n0; you can additionally use the -k selector to update only specific tests) )r)clean_upr9rrrplatformrKnextrCzipmaxrDMIN_LINE_LENGTH_FOR_ALIGNMENTshow_align_messagerr) expectedactualmsgrLexpected_ranges actual_rangesredgreen first_diffs r%assert_string_arrays_equalrcmsEf F6)4Xv)F& 'LLG3j/8C@ %!llg5 4->  K #h*? @ K H s6{ +  (S[ ( $ %)F F6*%&*GG x 3VJ5G H  f   C+5r'c t|}tt|jdh}t||dj dj |dj ||y)N__main__zEActual modules ({}) do not match expected modules ({}) for "[{} ...]", )sortedset differencercformatjoin)namer[r\expected_normalizedactual_normalizeds r%assert_module_equivalenceros` *s6{55zlCD PXX II' ($))4G*H$ r'c |t||djdj|dj||y)z6Compare actual and expected targets (order sensitive).zEActual targets ({}) do not match expected targets ({}) for "[{} ...]"rfN)rcrjrk)rlr[r\s r%assert_target_equivalencerqs7 PXX IIf tyy2D r'c >t|dkryd}tjjdd}|dd|ddk(r|dd}|dd}d}|dd|ddk(r|r d |z}d |z}t t|t|}d }||kDrd }tjjd |d||d tjjd |d||d tjjdt t |t t|t|D]S}|||dz|||dzk7r!tjjdn!tjjdUtjjd y)aQAlign s1 and s2 so that the their first difference is highlighted. For example, if s1 is 'foobar' and s2 is 'fobar', display the following lines: E: foobar A: fobar ^ If s1 and s2 are long, only display a fragment of the strings around the first difference. If s1 is very short, do nothing. NHz$Alignment of first line difference: F Tz...z E: rBz A: z r?^rA)rDrrrrXrangemin)s1s2maxwtruncmax_lenextrar5s r%rZrZs  2w{ DJJ<= E Sb'RW  W W Sb'RW   RZ RZ#b'3r7#G E~JJuRYKwb12JJuRYKwb12JJW 3tSR#b'23 4" a!a%=Bq1q5M ) JJ  S !  JJ  S ! " JJTr'cg}tj}|dz}|D]}tj}|}||jtjdfD],}|dk7s |dk7s|dk7s|dk7s|j|d}.t j dd|}|j|d}|j t j d d||S) zRemove common directory prefix from all strings in a. This uses a naive string replace; it seems to work well enough. Also remove trailing carriage returns. z /driver.py/z//\z\\rwz +$z driver.pyz\r$)osgetcwdsepreplaceresubr,)r-respwddriversprefixssps r%rTrTs C ))+C < F  + 44 'ACxAI!t)V ZZ2& 'VVE2r " ZZ , 266&"b)* + Jr'c#Ktjj}dtjvs2dtjvs tjjdd d|t_y#|t_wxYww)zTemporary insert current directory into sys.path. This can be used by test cases that do runtime imports, for example by the stubgen tests. rw.rN)rpathcopyinsert) old_sys_paths r%local_sys_path_setrsT88==?L #((NcSXXo 2  <sA#B&A6* B6 BBctjd|x}r4tdt|j dft j St j S)Nzpython3([0-9]+)\.test$r@r?)rsearchrXintgroupr PYTHON3_VERSION_MIN)rms r%testfile_pyversionrsK II/ 66q6As1771:')E)EFF+++r'cvg}|D]1}|j|jtjd3|S)z@Translate an array of error messages to use / as path separator.r)r,rrr)messagesr-rs r%normalize_error_messagesr s8 A ) 2663'() Hr'ctj}d} |y#t$rEt|dz||ztjz }|dkrtj|YnwxYw[)aRetry callback with exponential backoff when it raises OSError. If the function still generates an error after max_wait seconds, propagate the exception. This can be effective against random file system operation failures on Windows. g{Gz?Nr:)timeOSErrorrzsleep)funcmax_waitt0 wait_times r%retry_on_errorrsn BI  " F  "IM2=499;+FGID  JJy !  " s!A A/.A/ct|trk|jddkDrWdg}|jdD]"}|j t d|zdd$|dxxdz cc<dj |St |S)NrBr?z'''\"r:z''') isinstancestrcountsplitr,reprrk)objbitsrJs r% good_reprr-s~#s 99T?Q 9D $ 4 Dt,Qr23 4 H H99T? " 9r'cld}||k7r-t|jt|t|y)NT)AssertionErrorrjr)r-r.fmtr!s r% assert_equalr9s2AvSZZ ! ilCDDr'cdt|vr,t|jddjdSt|ddS)Nrrz'>)rrrstrip)ts r%typenamer?s@ c!f}1v||C $++D111va|r'c|d}t||k7r,tdtt|dt|y)NTz Invalid type z , expected )typerr)typvaluer!s r% assert_typerFs@ E{c}Xd5k-B,C;xX[}o^__r'ct}tjd|tj}|dkDr.tjd|d|tj}|r|}|rY|j dj }|j dt|d\}}|r td d |vr)d |_ n!g}t}d|_ d |_ d |_ td |Drt|j|_|j j#d r |j j#d |_|S)z4Parse comments like '# flags: --foo' in a test case.z# flags: (.*)$)flagsr?z# flagsz: (.*)$z--no-site-packagesF)require_targetsz9Specifying targets via the flags pragma is not supported.z--show-error-codesTc3JK|]}|jdddk7yw)=rz--python-versionN)r)rRflags r%rSz parse_options..hs# J4::c?1 !3 3 Js!#z--mypy-verbose)r rr MULTILINErrr,r RuntimeErrorhide_error_codes error_summaryforce_union_syntaxallrfilepython_versionconfig getoption verbosity) program_texttestcaseincremental_stepoptionsrflags2 flag_listtargetss r% parse_optionsrLs#iG II& BLL IE!W%5$6g> TVT`T`a E KKN((* -.*9eL Z[ [ y 0'+G $ ) %#' %)" J JJ!3HMM!B  !12$OO556FG Nr'cz|Dcgc](}|jdjD]}|*c}}Scc}}w)zDReturns a single list of string lines from the byte streams in args.utf8)decode splitlines)streamsstreamrs r% split_linesrqs4# P&V]]6-B-M-M-O PA PA PP Ps-7cd}tjj|r"tj|jdz}tjj |}tj |dt|dd5}|j|ddd|rtj|||fyy#1swY&xYw)Nr?T)exist_okwzutf-8encoding)times) rrisfilestatst_mtimedirnamemakedirsopenrutime)rF target_pathnew_timedirtargets r%write_and_fudge_mtimervsH ww~~k"77;'0014 ''//+ &CKKd# k3 1V W Xx$89s B??Ccv|D]}t|tr!t|j|j4t j j|j r=|j jdsJtj|j |j tfdy)Ntmpc.tjSrP)rremove)rsr%z)perform_file_operations..sryyr') rrrrFrrrisdir startswithshutilrmtreer) operationsoprs @r%perform_file_operationsrs 8 b* % !"**bnn =ww}}RWW%ww))%000 bgg&ww67 8r'c |jD]\}}|j|}tjj |s4t dj ||jr d|zdt|d5}|j}dddt|tr-|jt dj ||tjtjjt }|j"rV|j$j&r5tjj(dk(r|Dcgc] }t+|}}t-|}t/|j|dj ||jrd|zndy#1swY$xYwcc}w) Nz0Expected file {} was not produced by test case{}z on step %drwrrzCOutput file {} did not match its expected output pattern --- {} ---rz2Output file {} did not match its expected output{}) output_files removeprefixrrexistsrrjoutput2rreadrr fullmatchnormalize_file_outputrabspathrnormalize_outputsuite native_seprrrrc) rstep strip_prefixrexpected_content output_fileactual_output_contentnormalized_outputrJs r%check_test_output_filesrs#+"7"7#   .ww~~d# BII(2B2B-$. HJ  $ ( 7K$/$4$4$6 ! 7 & 0))*?@L X__/  2 ! , , . 0N   $ $~~((RWW[[D-@N_$`d%;D%A$`!$` 89J K "  ' ' )  @ G Gh.>.>md*B  ;#  7 7&%asF8G8G c 2tjd}|Dcgc]}|j|d}}tjj }|Dcgc]2}tj dtj|zdzd|4}}ttjd|}|Dcgc]2}tj dtj|zdzd|4}}|Dcgc]}|j d|}}|Scc}wcc}wcc}wcc}w)z%Normalize file output for comparison.z\d{10}z$PWDz\bz$VERSION base_versionz $TIMESTAMP) rcompilermypyversion __version__rescapegetattr)rFcurrent_abs_pathtimestamp_regexxresultrrs r%r r sjj+O;B Caaii(&1 CF Cll&&GQW XAbffURYYw//%7QG XF X4<<ALV\ ]QRbffURYY|44ur@s"  .$$ % <]] {{!"A% %%%8%:jj  !           HLQ",",!*",14",DH", ",J 1h.     , ". E ` ""!3"GJ" "JQ :*8$BD&  & (+& ;>&  & R r'