o bR@slddlZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddlmZmZmZddlmZddlmZddlmZmZmZd d d d d d d Zd dZddZddZddZddZddZ dej!fde fdZ"ddZ#GdddZ$Gd d!d!e$ej%e j&Z%d"d#Z'd$d%Z(d&d'Z)d(d)Z*Gd*d+d+e+Z,d,d-Z-d.d/Z.dS)0N)plugin)app)defer)failurereflectusage)FilePath) namedModule)itrialreporterrunnerdefaultbriefverbose)plainr emacsrcgitbrcCsd}||t|}||}|dks|dkrt|d|||d}i}|D]+}t|dkr7q,|d}t|dkrKt|d||d ||d<q,|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 localVarsitemrr%7/usr/lib/python3/dist-packages/twisted/scripts/trial.py_parseLocalVariables#s   r'c Csft|}||g}Wdn1swY|D]}zt|WSty0YqwiS)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)filenameflinesrr%r%r&loadLocalVariables<s  r-cCs&t|dd}|durgS|dS)Nztest-case-name,)r-getr)r* testCaseVarr%r%r&getTestModulesMs r1cCs*tj|}|dotj|ddkS)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)r*r5r%r%r& isTestFileTs r8cCstddttjDS)NcSsg|]}|jqSr%)longOpt).0pr%r%r& ^sz#_reporterAction..)r CompleteListr getPluginsr IReporterr%r%r%r&_reporterAction]sr@c Csbt|dd}|durt||}t|dd}|dur|jSzt|dWSttfy0YdSw)aH Try to find the source line of the given test thing. @param testThing: the test item to attempt to inspect @type testThing: an L{TestCase}, test method, or module, though only the former two have a chance to succeed @rtype: int @return: the starting source line, or -1 if one couldn't be found _testMethodNameN__code__rr)getattrco_firstlinenoinspectgetsourcelinesOSError TypeError) testThingmethodcoder%r%r&_maybeFindSourceLineas   rLzCalphabetical order for test methods, arbitrary order for test caseszDattempt to run test cases and methods in the order they were defined) alphabetical toptobottomcCs,|tvrtddddtDf|S)ai Check that the given order is a known test running order. Does nothing else, since looking up the appropriate callable to sort the tests should be done when it actually will be used, as the default argument will not be coerced by this function. @param order: one of the known orders in C{_runOrders} @return: the order unmodified z9--order must be one of: %s. See --help-orders for detailsz, css|]}t|VqdSN)repr)r:orderr%r%r& sz&_checkKnownRunOrder..) _runOrdersr UsageErrorjoin)rQr%r%r&_checkKnownRunOrders rVc @s0eZdZdZdZddggdgdgdgdgd gd gd gZd d ddeggdgdgdgZej e e e ej ddejdddej ddddgdZejZdZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Z d6d7Z!d8d9Z"d:d;Z#dS)< _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.   r)rsortedrSr"ruexit)rrsynopsisname description_r%r%r&opt_help_orders<s z_BasicOptions.opt_help_orderscCs>d}t|ttjD] }td|jd|jq tddS)NzTrial's output can be customized using plugins called Reporters. You can select any of the following reporters using --reporter= rrr) rrr>r r?r9rrur)rrrr;r%r%r&opt_help_reportersHs z _BasicOptions.opt_help_reporterscCsd|d<tdS)z/ Disable the garbage collector T disablegcN)gcdisablerqr%r%r& opt_disablegcSs z_BasicOptions.opt_disablegccCs,z t||d<WdStytdw)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_MAPKeyErrorrrT)rroptr%r%r& opt_tbformatZs   z_BasicOptions.opt_tbformatc Cs@z tt|Wnttfytdwt||d<dS)z- see sys.setrecursionlimit() z-argument to recursionlimit must be an integerrecursionlimitN)rusetrecursionlimitintrHrrrT)rrargr%r%r&opt_recursionlimites  z _BasicOptions.opt_recursionlimitcCshzt||d<Wn tytdw|ddkr td|ddkr2ttd|d<dSdS)Nrcz/Argument to --random must be a positive integerrd)rrrrTtime)rroptionr%r%r& opt_randomps    z_BasicOptions.opt_randomcCsD||d<|dD]}|tjvrtjd|ftddtj|<q dS)zP Fake the lack of the specified modules, separated with commas. without-moduler.z/Module '%s' already imported, disabling anyway.)categoryN)rrumoduleswarningswarnRuntimeWarning)rrrmoduler%r%r&opt_without_module}s  z _BasicOptions.opt_without_modulecGs|d|dSrm)r)rrargsr%r%r& parseArgssz_BasicOptions.parseArgscCsFttjD]}|jd|j}|j|krt|Sqt d)Nr~zVOnly pass names of Reporter plugins to --reporter. See --help-reporters for more info.) rr>r r?rklassr9rnamedAnyrrT)rrrr;qualr%r%r&_loadReporterByNames z!_BasicOptions._loadReporterByNamecCsL||d|d<d|vrd|d<|ddur"|ddur$tddSdS)Nr rr rQrcz-You can't specify --random when using --order)rrrTrqr%r%r& postOptionss  z_BasicOptions.postOptions)$__name__ __module__ __qualname____doc__longdescoptFlagsrV optParametersr Completionsr=rSr@ CompleteFiles CompletercompDatar TreeReporterfallbackReporterrrpr|rrrrrrrrrrrrrrr%r%r%r&rWsl           rWc@seZdZdZgdgdgdgdgdgdgZgdgd gd gZejegd e d d Z gdZ gdZ e jZdZdZddZddZddZdS)roa 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)rilztest.logrg)jobsjNzNumber of local workers to run)rrr)rr )rk)rr_r})rreactorrNcCsHzt|}Wntytd|w|dkrtd||d<dS)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)rrrrT)rrnumberr%r%r&opt_jobss   zOptions.opt_jobscCspg}|jD]}||dur||r|d|q|jD]}||dur5|d|t||gq|S)zJ Return a list of options to pass to distributed workers. Nz--) _workerFlagsr/r_workerParametersrstr)rrrrr%r%r&_getWorkerArgumentss  zOptions._getWorkerArgumentscCsbt||drgd}|D] }||rtd|q|dr/|ds*tddt_dSdS)Nr)rrrr`z(You can't specify --%s when using --jobsrrz+You must specify --debug when using --nopm F)rWrrrTrDO_POST_MORTEM)rr conflictsrr%r%r&rs   zOptions.postOptions)rrrrrrrrr=r@rrrr rrextrarrrrr%r%r%r&ros4  rocCs2|drt|ds|drtddSdS)NrrT)rstartDebugModer setDebugging)configr%r%r&_initialDebugSetups rcCs$t|}|d }|j|d|dS)NrZrn)recurse) _getLoader loadByNames)rloaderrr%r%r& _getSuites rcsxt}|dr#t|dfdd|_td|dn|dr2t|d\}}||_|ds:tj|_ |S)NrccsSrO)rc)rarandomerr%r&!sz_getLoader..z$Running tests shuffled with seed %d rQr) r TestLoaderrcRandomseedsorterrrSDestructiveTestSuite suiteFactory)rrrrr%rr&rsrc Cst}ztdWn tytdYnwdD]2}tj|rLzt|}Wn t y1Yqw||j | Wdn1sGwYq|S)zR Wrap an instance of C{pdb.Pdb} with readline support and load any .rcs. r)zreadline module not available)z.pdbrcpdbrcN) rPdbr ImportErrorrr3r4existsr(rGrcLinesr readlines)dbgr4rcFiler%r%r& _wrappedPdb+s$      rc@seZdZdZdS)_DebuggerNotFoundzk A debugger import failed. Used to allow translating these errors into usage error messages. N)rrrrr%r%r%r&rBsrcCs tj}|d|d|d|d|d|dd}|dr#tjj|d <n[|d r        rc Csttjdkr tjdt}z|Wntjy/}z ttjdd|d}~wwt |zt |}Wnt yT}zttjddt |d}~wwt |}|drc||}n||}|jrtd|j}|jdd|jdt| dS)Nrz--helprz: rF) show_missingsummaryr)rrurvrro parseOptionsrerror SystemExitrrrrrrunUntilFailurerunrrresults write_resultsrr4r wasSuccessful)rue trialRunnerr]suite test_resultrr%r%r&r{s6        r)/rrEr3rrcrurrtwistedrtwisted.applicationrtwisted.internetrtwisted.pythonrrrtwisted.python.filepathrtwisted.python.reflectr twisted.trialr r r rr'r-r1r8r@rLrrSrVrWroReactorSelectionMixinrrrr Exceptionrrrr%r%r%r&s^       ! k 0