ϪfR ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z m Z m Z ddl mZddlmZddlmZddlmZmZmZddlmZddlmZdd lmZmZdd lmZdd l m!Z!d d d d dddZ"dZ#dZ$dZ%dZ&dZ'dZ(dejRfde(fdZ*dZ+GddZ,Gdde,ejZej\Z-de-ddfd Z/de-de!fd!Z0de-dejbfd"Z2d#Z3Gd$d%e4Z5de-dejlfd&Z7de fd'Z8y)(N)NoReturnOptionalType)plugin)app)defer)failurereflectusage)FilePath) namedModule)itrialrunner)DistTrialRunner) TestSuitedefaultbriefverbose)plainremacsrcgitbrcd}|j|t|z}|j|}|dk(s|dk(rt|d|||j d}i}|D]u}t|j dk(r |j d}t|dk7rt|d||d j ||dj <w|S) a  Accepts a single line in Emacs local variable declaration format and returns a dict of all the variables {name: value}. Raises ValueError if 'line' is in the wrong format. See http://www.gnu.org/software/emacs/manual/html_node/File-Variables.html z-*-z' not a valid local variable declaration;r:z contains invalid declaration )findlenrfind ValueErrorsplitstrip)lineparenstartenditems localVarsitemr"s 7/usr/lib/python3/dist-packages/twisted/scripts/trial.py_parseLocalVariablesr,'s E IIe s5z )E **U C {cRiD8#JKLL sO ! !# &EI7 tzz|  !  3 u:?x'EdXNO O&+Ahnn&6 %(.."# 7 ct|5}|j|jg}dddD]} t|cSiS#1swYxYw#t$rY+wxYw)z Accepts a filename and attempts to load the Emacs variable declarations from that file, simulating what Emacs does. See http://www.gnu.org/software/emacs/manual/html_node/File-Variables.html N)openreadliner,r!)filenameflinesr$s r+loadLocalVariablesr4@sq h-1qzz|,- '- - I--    s!A  A A A#"A#cbt|jdd}|gS|jdS)Nztest-case-name,)r4getr")r1 testCaseVars r+getTestModulesr9Qs6$X.223CTJK   S !!r-ctjj|}|jdxr%tjj |ddk(S)z Returns true if 'filename' looks like a file containing unit tests. False otherwise. Doesn't care whether filename exists. test_rz.py)ospathbasename startswithsplitext)r1r>s r+ isTestFilerAXsG ww)H   w ' TBGG,<,z&_checkKnownRunOrder..s=e=sz. See --help-orders for details) _runOrdersr UsageErrorjoin)r]s r+_checkKnownRunOrderrbs> Jyy=*== @   Lr-c eZdZUdZdZddggdgdgdgdgd gd gd gZd d ddeggdgdgdgZejeje e ejdejddejdddgZdZeej&ed<dZdZdZd Zd!Zd"Zd#Zd$Zd%Zd&Zd'Zd(Z d)Z!d*Z"d+Z#d,Z$y)- _BasicOptionszC Basic options shared between trial and its local workers. zutrial loads and executes a suite of unit tests, obtained from modules, packages and files listed on the command line.helph) no-recurseNzDon't recurse into packages)z help-ordersNz%Help on available test running orders)zhelp-reportersNz,Help on available output plugins (reporters))rterrorsez;realtime errors, print out tracebacks as soon as they occur)unclean-warningsNz'Turn dirty reactor errors into warnings)force-gcNz executablereplace)rexecutableNames r+ getSynopsisz_BasicOptions.getSynopsissu 55chhqkB  " "; /'..  0&&{B7N  F   r-cvd}t|dj|}td|jd|S)zx Return a L{FilePath} representing the directory into which coverage results should be written. coveragerrzSetting coverage directory to .)r childprintr=)rcoverdirresults r+rz_BasicOptions.coverdirs? $/0177A .v{{m1=> r-ctjdd|_tj|jj d|d<y)z Generate coverage information in the coverage file in the directory specified by the temp-directory option. rr)counttraceTrN)rTracer{rsettrace globaltracers r+ opt_coveragez_BasicOptions.opt_coverages6 kk3  T[[,,-Zr-cBtjj|s$tjj d|dytjj |}t|r|dj|y|djt|y)zG Filename to grep for test cases (-*- test-case-name). zFile z doesn't exist Nr~) r<r=isfilerstderrwriteabspathrAappendextendr9)rr1s r+opt_testmodulez_BasicOptions.opt_testmodulesvww~~h' JJ  uXL0@A B 77??8, h  M  * M !9 :r-c:ddlm}tj|y)z Print an insanely verbose log of everything that happens. Useful when debugging freezes or locks in complex code. r)spewerN)twisted.python.utilrrr)rrs r+opt_spewz_BasicOptions.opt_spew4s / Vr-cd}t|ttjD]\}\}}td|d|t j dy)NzTrial can attempt to run test cases and their methods in a few different orders. You can select any of the following options using --order=.   r)rsortedr_r(rexit)rsynopsisname description_s r+opt_help_ordersz_BasicOptions.opt_help_orders=sU 7  h&,Z-=-=-?&@ 2 "D"; %t[ 1 2  r-cd}t|tjtjD]$}td|j d|j &tjdy)NzTrial's output can be customized using plugins called Reporters. You can select any of the following reporters using --reporter= rrr) rrrErrFrGrrr)rrrHs r+opt_help_reportersz _BasicOptions.opt_help_reportersIsV 1  h""6#3#34 9A %D!-- 8 9  r-c6d|d<tjy)z/ Disable the garbage collector T disablegcN)gcdisablers r+ opt_disablegcz_BasicOptions.opt_disablegcTs![ r-cb t||d<y#t$rtjdwxYw)z Specify the format to display tracebacks with. Valid formats are 'plain', 'emacs', and 'cgitb' which uses the nicely verbose stdlib cgitb.text function tbformatz.tbformat must be 'plain', 'emacs', or 'cgitb'.N) TBFORMAT_MAPKeyErrorr r`)ropts r+ opt_tbformatz_BasicOptions.opt_tbformat[s:  U+C0D  U""#ST T Us .c tjt|t||d<y#ttf$rt j dwxYw)z- see sys.setrecursionlimit() recursionlimitz-argument to recursionlimit must be an integerN)rsetrecursionlimitintrRr!r r`)rargs r+opt_recursionlimitz _BasicOptions.opt_recursionlimitfsT .  ! !#c( +&)XD! ":& T""#RS S Ts /%Ac t||d<|ddkrtjd|ddk(r$ttjdz|d<yy#t$rtjdwxYw)Nrprz/Argument to --random must be a positive integerd)rr r`timer!)roptions r+ opt_randomz_BasicOptions.opt_randomqs 8 [DNH~!&&Eh1$!$TYY[3%6!7X% V""#TU U Vs AA9c||d<|jdD]F}|tjvrtjd|dt dtj|<Hy)zP Fake the lack of the specified modules, separated with commas. without-moduler6zModule 'z%' already imported, disabling anyway.)categoryN)r"rmoduleswarningswarnRuntimeWarning)rrmodules r+opt_without_modulez _BasicOptions.opt_without_module~sX"( ll3' 'F$ LRT+#'CKK   'r-c,|dj|yr})r)rargss r+ parseArgsz_BasicOptions.parseArgss W T"r-ctjtjD]C}|jd|j }|j |k(s.tj|cStjd)NrzVOnly pass names of Reporter plugins to --reporter. See --help-reporters for more info.) rrErrFrklassrGr namedAnyr r`)rrrHquals r+_loadReporterByNamez!_BasicOptions._loadReporterByNamesq""6#3#34 .AhhZq *DyyD ''-- .   r-c|j|d|d<d|vrd|d<|d|dtjdyy)Nrtrrr]rpz-You can't specify --random when using --order)rr r`rs r+ postOptionsz_BasicOptions.postOptionss^ 33D4DEZ T !(D  = $h)C""#RS S*D $r-)%__name__ __module__ __qualname____doc__longdescoptFlagsrb optParametersr CompletionsrDr_rI CompleteFiles CompletercompDatar{rrr__annotations__rrrrrrrrrrrrrrrrr-r+rdrds@  G  :FP N  !H4    /    T  !M2!u  'U'' 3'*u**A%eooM:   E  G  H %)FHU[[ !(%  $ ;.   U . 8 '#  Tr-rdceZdZdZgdgdgdgdgdgdgZgdgd gd gZejejgd e d  Z gdZ gdZ dZ dZdZy)ra Options to the trial command line tool. @ivar _workerFlags: List of flags which are accepted by trial distributed workers. This is used by C{_getWorkerArguments} to build the command line arguments. @type _workerFlags: C{list} @ivar _workerParameters: List of parameter which are accepted by trial distributed workers. This is used by C{_getWorkerArguments} to build the command line arguments. @type _workerParameters: C{list} )debugbziRun tests in a debugger. If that debugger is pdb, will load '.pdbrc' from current directory if it exists.)debug-stacktracesBz2Report Deferred creation and callback stack traces)nopmNzFdon't automatically jump into debugger for postmorteming of exceptions)dry-runnzdo everything but run the tests)profileNz#Run tests under the Python profiler) until-failureuzRepeat test until it fails)debuggerNpdbzBthe fully qualified name of a debugger to use if --debug is passed)rwlztest.logru)jobsjNzNumber of local workers to run)rrr)rrt)ry)rrlr)rreactorrc t|}|dkrtjd||d<y#t$rtjd|zwxYw)zN Number of local workers to run, a strictly positive integer. z,Expecting integer argument to jobs, got '%s'rz4Argument to jobs must be a strictly positive integerrN)rr!r r`)rnumbers r+opt_jobszOptions.opt_jobssf [F Q;""F V  "">G  s -"Acg}|jD].}|j|||s|jd|0|jD]6}|j||j d|t ||g8|S)zJ Return a list of options to pass to distributed workers. z--) _workerFlagsr7r_workerParametersrstr)rrrs r+_getWorkerArgumentszOptions._getWorkerArgumentss'' /Fxx+<KK"VH . /,, @Fxx+ r&]CV ,=>? @ r-ctj||dr(gd}|D]}||s tjd|z|dr&|dstjddt_yy)Nr)rrrz(You can't specify --%s when using --jobsrrz+You must specify --debug when using --nopm F)rdrr r`r DO_POST_MORTEM)r conflictsrs r+rzOptions.postOptionss|!!$' <AI# <**BVK  <=&&'WXX%*G " r-N)rrrrrrr rrDrIrrrrrrrr-r+rrs    <@<'H. 6= M!u  ***+FG' H9LG  +r-rconfigreturncv|drtj|ds|drtjdyy)NrrT)r startDebugModer setDebugging)rs r+_initialDebugSetupr  s7 g  g&!45 4 6r-cPt|}|d }|j|d|S)Nrgr~)recurse) _getLoader loadByNames)rloaderr s r+ _getSuiters3  F&&G   fWow  ??r-c,tj}|drDtjj |dfd|_t d|dzn|drt|d\}}||_|dstj|_ |S)Nrpc$jSrC)rp)rnrandomers r+z_getLoader..s(//"3r-z$Running tests shuffled with seed %d r]r) r TestLoaderrpRandomseedsorterrr_DestructiveTestSuite suiteFactory)rrrrrs @r+rrs    F h==? fX&'3  5x8HHI vg/ 6 / "$99 Mr-c~tj} tddD]b}t j j|s# t|}|5|jj|jdddd|S#t$rt dYwxYw#1swYxYw#t$rYwxYw)zR Wrap an instance of C{pdb.Pdb} with readline support and load any .rcs. r0zreadline module not available)z.pdbrcpdbrcN) rPdbr ImportErrorrr<r=existsr/rcLinesr readlinesrQ)dbgr=rcFiles r+ _wrappedPdbr%(s '')C/J$; 77>>$  ;d;KK&&v'7'7'9:;;; J / -./;;  s/ B  B0*B$ B! B!$B- 0 B<;B<ceZdZdZy)_DebuggerNotFoundzk A debugger import failed. Used to allow translating these errors into usage error messages. N)rrrrrr-r+r'r'?sr-r'ctj}|d|d|d|d|d|d|dd}|d rtjj|d <n|d r"t}|d |d <|j |d <nc|drNtjj |d <|d}|dk7r t j||d<n t|d<|d|d<|d|d<|di|S#t j$rt|dwxYw)z Return a trial runner class set up with the parameters extracted from C{config}. @return: A trial runner instance. rtrrirkrwrrrm)reporterFactorytracebackFormatrealTimeErrorsuncleanWarningsrwworkingDirectory exitFirstrmoder maxWorkersworkerArgumentsrrrz debugger could not be found.rrlforceGarbageCollectionr) r TrialRunnerDRY_RUNrrDEBUGr rModuleNotFoundr'r%)rclsrrs r+ _makeRunnerr8HsL!' 2 2C!*-!*- ,!"45)$"#34K( Di))11V #F^\"("<"<">  '?!--33DLj)H5 '.'7'7'AD$ $/=Z  +Y)/ ); %& ;;--+#,&CDs 'C%%"DcHttjdk(rtjjdt } |j t| t|}t|}|dr|j|}n|j|}|j r[tj"d|j j%}|j'dd|j)j*tj,|j/ y#t j$r&}ttjdd|d}~wwxYw#t$r/}ttjddt|d}~wwxYw) Nrz--helprz: rTF) show_missingsummaryr)rrrrr parseOptionsr error SystemExitr r8r'rrrunUntilFailurerunr{rresults write_resultsrr=r wasSuccessful)rue trialRunnerrjsuite testResultrAs r+r@r@tsR 388} ! YF1v5!&)  f E o 007  __U+  }} T--'')uv7H7M7M  HH))+ +,) ;;1CHHQK=2$/001 5CHHQK=3q6(3445s0D-# E)-E&!E!!E&) F!2*FF!)9rrOr<rrprrrrtypingrrrtwistedrtwisted.applicationrtwisted.internetrtwisted.pythonr r r twisted.python.filepathr twisted.python.reflectr twisted.trialrrtwisted.trial._dist.disttrialrtwisted.trial.unittestrrr,r4r9rArIrVrr_rbrdrReactorSelectionMixinr rrrr% Exceptionr'_Runnerr8r@rr-r+rUsQ   ++#"22,.(9,      2""UXB N  O  &~T~TBd+mU]]C,E,Ed+N!w!4!@g@)@ w 6#4#4 . ))FNN)X-X-r-