ML iv UdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z ddlmZddlmZddlmZdd lmZmZmZmZmZdd lmZddlZdd lmZdd lm Z m!Z!m"Z"m#Z#ejHjKe Z&d dgZ'de(d<GddeZ)GddeZ*ee)e*fZ+de(d<d8dZ,d9dZ-Gddej\Z/d:dZ0eGddZ1d;dZ2dd"Z6d?d#Z7d?d$Z8d@d%Z9dAd&Z:ejvd'(dBd)Zt5|}'|j}(t[|(|d=|D]!\})}t[|j9d||)#t7}*|D]&\}+},|+|*vr |d>|+d?|*jA|+(|(_.|_/|'_0|_1jd-jdzt5-jzdz _3|_4|_5| _6| _7| _8| xsg_9| _:|_;y#1swY xYw#1swY xYw#1swY xYwcc}wcc}wcc}w#tF$r||"d*YwxYwcc}$wcc}$w)AzParse and prepare a single case from suite with test case descriptions. This method is part of the setup phase, just before the test case is run. cltjjdjd|dy)N:: Fpytrace)pytestfailfileline)msgcases r$ _case_failz#parse_test_case.._case_failRs* tyyk499+Ru5uEr#r__main__Ncjjzdz }tjjd|d|dy)Nr;r<Fr=)rBr?r@rA)rC item_abs_linerDitems r$ _item_failz#parse_test_case.._item_fail[s= II 1A5M KK499+Q}oRu=u Mr#>rAfixtureoutfile outfile-re rM>rArMrOrNbuiltinsutf8encodingz builtins.pyitypingz typing.pyi _typeshedz _typeshed.pyiz stale[0-9]*$stale,zrechecked[0-9]*$ recheckedztargets[0-9]*$targetsdeletez(.*)\.([0-9]+)$zInvalid delete section rIzCan't delete during step z out[0-9]*$Tversion >==>=z5Only >= and == version checks are currently supportedc32K|]}t|ywN)int).0xs r$ z"parse_test_case..s'O1A'Osr.z is not a valid python versionr`z. always true since minimum runtime version is r_z/ always false since minimum runtime version is zFOnly minor or patch version checks are currently supported with "==": \outout1F triggered zInvalid section header [z ] in case z*Required output section not found in case zStale modules after pass z& must be a subset of rechecked modulesmainzDuplicated filename z$. Did you include it multiple times?)rCrreturnr )<parse_test_datadatanamesuite base_path native_sepr/r'r3 posixpathrequired_out_sectionappendidargexpand_variablesr7recompilerstripSdirnamerAopenreadmatchrclensetr1stripgroup setdefaultadd startswithtuple ValueErrorrPYTHON3_VERSIONsys version_infosepnormalize_output fix_win_pathkeysissubset expand_errorsinputoutputoutput_inline_startoutput2rB last_linefiles output_filesexpected_stale_modulesexpected_rechecked_modules deleted_pathsrkexpected_fine_grained_targets test_modules).rD test_itemsrtr3out_section_missingrrrrr stale_modulesrechecked_modulesrkrZrrE first_itemrLcontentsr'mpathfsrc_pathpassnumtmodules reprocessedmnumfullargs version_checkrz compare_op version_strr\rB tmp_output section_strrr file_path seen_filesrAr5rKs.` @r$parse_test_caser9s !DII6J $$I zzww||~~**99#%E9;LF$&G)+M)+M-/I$&G LF #1 %D: #12oX N 77B B88' ''' $))(<=H 488,Dww)###$7$ABww-- dH-.L(##T2::hoo6G+N$OPI%##T8$45 WW "88' ''3TXX>Eef- J d9n=qvvxHI J J WW 88' ''BGGOODII6AHh0 HA d9l;QVVXFG H H WW #88' ''BGGOODII6AHh0 KA d9o>IJ K K XXotww /77g-a3twws7|~7N3OGQ; ;#xx/ceX[I\5]Aaggi5]G%,M' " XX)477 377k1as4773{CSCU;V7WGQ; ;#xx/ceX[I\5]Aaggi5]G)0 g & XX' 177i/aSYAQ9R5SGQ; ; $ 0"$((..Y\J]6^Qqwwy6^K*GG  WW 88' ''+TXX6Ay4TXXLABaggaj/CQw6se<= 1771:.D  $ $S#% 0 4 4T : XXmTWW -xxxx~~c* M T>>),!$QqJ!5"#Z["%ab'KU"''O 8I8I#8N'O"O"T)"h&>&>>&#&%'UV^VnVnUo p),(8(8G(C #t+"X%=%==&#&%'VW_WoWoVp q !3w<3!3&"hithw x),(8(83w<(HG(S 3 T4AEK.t4K K77;;$&4+@+@AK!L,t"4!LJ!L77e#tww&'8'F!$''#e*,"78G"Q;&;'1GG$&+# WW #(8 I''txxq ^RHK 1+j V W_oXb? }MN %%' d + +*7w)? g & } $,,!'*334Eg4NO 27);ab c df+ OOE%($? 8hnnT*FI>?Ja :  -dV3WX Yt  DJDK2DDLYY*S^;a?DNDJ$D"/D&7D#&D_"DN)0D&$DE J J  H H  K K 6^ 6^ 7_8&U"k_4R#STU&L!LsT)i10)i>)j j3jj"6!j''k(k1i; >j j 'j?>j?c6eZdZUdZded<ded<ded<ded<d ed <d Zd Zd ed<ded<ded<ded<d ed<ded<ded<ded<ded<ded< d"fd Zd#dZd#dZ d#dZ d$dZ d% d&d Z d'd!Z xZS)(r8zNHolds parsed data-driven test cases, and handles directory setup and teardown.DataFileCollectorparent list[str]rrrcrzdict[int, list[str]]rrmrzlist[tuple[str, str]]rrzdict[int, set[str]]rrrboolrrz$list[tuple[str, str | Pattern[str]]]rrrkc Ht|tsJt | ||||_||_||_||_||_|dk(rtjdk7s|dk(rtjdk(rd} | |_ | |_ | |_ | |_d|_d|_y)Nwindowswin32posixT) isinstancersuperr-rsrA writescache only_whenrrplatformskipxfailrqrBold_cwdtmpdir)selfrrsrArrrrrrrrrqrB __class__s r$r-zDataDrivenTestCase.__init__s &"3444 v&  &" 0  !cllg&=  CLLG$;D    #' "& r#cx|jrtjn5|jr)|jtjj|j t }|Jd|j}|j |j|y#t$r|jjdd}|r|jJtjj!|tjj#|j}t%d|j&d|tjj)|s8|j*sJtjj!|j*|}t-j.|j|wxYw)NzShould not happen--save-failures-tozCopying data from test z to )rr?r add_markermark getparentDataSuiteCollectorobjsetuprun_case Exceptionconfig getoptionrr/r'r3basenameprintrrisabsrshutilcopytree)rrrssave_dir target_dirs r$runtestzDataDrivenTestCase.runtest8s8 99 KKM ZZ OOFKK-- . 23!6#66!    NN4  #';;#8#89Mt#TH{{...WW\\(BGG4D4DT[[4QR / {$zlKLww}}Z0<<'r_traceback_filter tracebackgetreprrArB)rexcinforexcreprs r$ repr_failurezDataDrivenTestCase.repr_failures gmmZ 0 oo'G  v{{'<'< =gmmF[F[oo'G $ = =g FG ooGo4G {!DII;c';;r#c|jS)axReturn a list of descriptions of file operations for each incremental step. The first list item corresponds to the first incremental step, the second for the second step, etc. Each operation can either be a file modification/creation (UpdateFile) or deletion (DeleteFile). Defaults to having two steps if there aern't any operations. )rrs r$ find_stepszDataDrivenTestCase.find_stepsszzr#)rrrs DataSuiterArrrrrrrrrrr str | NonerrrrrqrrBrcroNoneror)roztuple[str, int, str]rb)r z#pytest.ExceptionInfo[BaseException]r Any | Noneror)rozlist[list[FileOperation]])rrr __doc__r!rArBr-rrrrr r  __classcell__rs@r$r8r8s8X    !! D D ! // 33#77N66&& '! ' '  '  ' ' ' ' ' ' ' ' '  'D2"LH/QU<:99r#N)rorc)rrr rr!propertyrr"r#r$rrs4 G O O IM ::r#rc ndd|zdzg|jdz}g}g}d}d}d}d}|t|krA||j} ||jdr| j drt|r7t |}t |}|jt||||dz||}| dd }d}d |vr+||jd dzd}|d|jd }g}n||jd r|j||ddnT||jd s|j||n+||jd r|j||dd|dz }|t|krA|r:t |}t |}|jt||||dz|dz |S)z>Parse a list of lines that represent a sequence of test items.rmz[case ]rPNr[rGr,rlz\[z--z----rI) r1rrrendswithcollapse_line_continuation strip_listrxrindex) raw_datarrlinesretrqryrzii0ss r$rprpsD3& '(..*> >ECDBC A B c%j. !HNN  8  s # 31$7!$' 8BT261=>B1RBCby#*,-"((3-(D 1X  ' KKa %q$$T* KKa ! 1X  ( KKa % Q- c%j.2 )$/$ 8BT261q59: Jr#cg}|D](}|jtjdd|*|r#|ddk(r|j|r |ddk(r|S)zReturn a stripped copy of l. Strip whitespace at the end of all lines, and strip all empty lines from the end of the array. z\s+$rmr,)rxr|rr2)lrr)s r$r"r"s_A ) Q'() "   "  Hr#c g}d}|D]`}tjdd|}|r#|dxxtjdd|z cc<n|j||jd}b|S)NFz\\$rmr,z^ +rh)r|rrxr )r+r,contr)sss r$r!r!skA D   VVFB "  bERVVE2r* *E HHRLzz$   Hr#c.|jdtS)Nz)replaceroot_dir)r)s r$r{r{ s 99Xx ((r#c 8tt|D]}||jdddD]}tjd|j }|s*|j ddk(rd}n-|j ddk(rd}n|j dd k(rd }|j d }|j d }|jd d}| |j|d|dzdd||j|d|dzd|dd| y)zTransform comments such as '# E: message' or '# E:3: message' in input. The result is lines like 'fnam:line: error: message'. z # rGNz*^([ENW]):((?P\d+):)? (?P.*)$EerrorNnoteWwarningcolmessagez\##r;r<) rrr1r|searchrrr1rx) rrfnamr'possible_err_commentrseverityr:r;s r$rrs)3u: R$)!HNN5$9!"$= R  =?S?Y?Y?[A771:$&HWWQZ3&%HWWQZ3&(Hggen''),!//%5;MMTF!AE7"XJb "JKMMTF!AE7!C58*Bwi"PQ# RRr#c|jttjdd}tjd|}|s|S|j \}}}dj |jdd|xsd|S)z`Changes Windows paths to Linux paths in error messages. E.g. foo\bar.py -> foo/bar.py. rhr+z^([\S/]+):(\d+:)?(\s+.*)z{}:{}{}rm)r1r2r|rgroupsformat)rBrr4linenor;s r$rr,sr <<("2"24"= >D ,d3A  $%HHJ!&' 0 0s ;V\r7SSr#ctjd|}|s|Sdj|d|jd|j dj dd||j ddS)zChanges filename paths to Linux paths in Cobertura output files. E.g. filename="pkg\subpkg\a.py" -> filename="pkg/subpkg/a.py". z&&111N N r#z(?P[a-zA-Z_0-9]+)(?P-writescache)?(?P-only_when_cache|-only_when_nocache)?(?P-skip_path_normalization)?(-(?Pposix|windows))?(?P-skip)?(?P-xfail)?rrc#Kt|d5}|j}dddtjdtjtj z}t |}t|jddz}t}|D]D} t|}tj| } | std| | jd } | |vr&td j| |j|t j#|||t%| |j&t)| jd | jd | jd t)| jdt)| jd| jd || ||jddzz }|j+| hGy#1swYxYww)zIterate over raw test cases in file, at collection time, ignoring sub items. The collection phase is slow, so any heavy processing should be deferred to after uninteresting tests are filtered (when using -k PATTERN switch). zutf-8rSNz^\[case ([^]+)]+)\][ \t]*$\n)flagsrPrGzInvalid testcase id rrz1Found a duplicate test name "{}" in {} on line {}rrrrrskip_path_normalization) rrsrArrrrrrrrrqrB)rrr|r1DOTALL MULTILINEiternextrTr_case_name_pattern fullmatch RuntimeErrorrrCrrr8readd_test_name_suffixtest_name_suffixrupdate) rrsrArrqcases cases_iterline_no test_namescase_idrrrs r$split_test_casesrzs dW %vvx HH4d"))bllBZ [EeJ:$$T*Q.GJ"J  ( ( 1!5g[AB Bwwv : CJJ&++w  !,,%dE,B,BCQWW]34ggk*WWZ(aggfo&qwww'(!")B!CC-   4::d#a'' 4&!=" sG*GF>A#5 6 CTYYu-.r#)rrrrrror)roIterator[DataDrivenTestCase]r)rrror) rrr rr! classmethodrerrrrrrrs@r$rrsY  '25   /r#ctjd|}|r&|jd}|dt| |z|zS||zS)Nz-[-A-Za-z0-9]+$r)r|r=rr)rrsuffixr magic_suffixs r$rrrrsO $d+Awwqz (s<(()F2\AAf}r#cZd|jjvxsd|jvS)N incremental)rrlowerrA)testcases r$is_incrementalrs( HMM//1 1 S]hmm5SSr#ctd|jDry|jD]5\}}tjj |j ds5yy)Nc3HK|]}tjd|yw)z # flags[2-9]:N)r|r)rdrBs r$rfz#has_stable_flags.. s G288$d + Gs "Fz mypy.ini.T)anyrrr/r'rr)rr4rs r$has_stable_flagsrsT G GG&nn( 77  H % 0 0 = r#cFeZdZUded<eZeZdZdZ dZ ddZ e d dZ y) rrrFrmcy)zSetup fixtures (ad-hoc)Nr"rs r$rzDataSuite.setup9sr#ctrb)NotImplementedError)rrs r$rzDataSuite.run_case<s!!r#Nr)rr8ror)rrr r!rrtrr}rwrursrrrr"r#r$rr(s@ I#K J&""r#)r4rror)rDr8ror)r'rror)r$rrrrrozlist[TestItem])r+rror)r)rror)rrrrr>rror)rBrror)rKr ror)rZr ror)rz pytest.Configror)rfr rrrrobjectror)rrrsrrArror)rrrrrror)rr8ror)Jr __future__rr/os.pathrvr|rrrabcrcollections.abcr dataclassesrpathlibrrrUr r r r r typing_extensionsrr(r?rNrmypy.test.configrrrrr'normpathr2rr!rr&r)r7rItemr8rrrpr"r!r{rrrHrLr[hookimplr`rgr}rorzClassrr Collectorrrrrrrr"r#r$rsM"  $!::5 VV 77  F # $V_U, "*j"89 z9y%xffR :: :,*Z $  )R: T ((>$' '  RZZ," ,"&/,"7:,"!,"^ M M* ,/((,/^ T""r#