Ϫf߄fUdZgdZddlZddlZddlZddlZddlZddlZddlZ ddl Z ddl m Z ddl mZddlmZmZmZmZmZmZmZddlmZddlmZdd lmZmZmZmZdd lm Z dd l!m"Z"m#Z#m$Z$m%Z%m&Z&dd l'mZm(Z(dd l)m*Z*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1m2Z2ddl3m4Z4ddl5m6Z6edZ7GddeZ8dZ9dZ:dZ;dZdZ?Gdde4Z@d ZAGd!d"e4ZBGd#d$e4ZCee%je%je jee jfZGeeHd%<d&eGd'eIfd(ZJd)eKd'eee jfd*ZLee/Gd+d,ZMGd-d.eMZNeGd/d0ZOd1ZPe d2eId'ed3fd4ZQe d5eId'ed3fd6ZRGd7d8eZSeGd9d:ZTy);zK A miscellany of code used to run Trial tests. Maintainer: Jonathan Lange ) TestSuiteDestructiveTestSuite ErrorHolder LoggedSuite TestHolder TestLoader TrialRunner TrialSuitefilenameToModule isPackageisPackageDirectory isTestCasenamesamefile NOT_IN_TESTN)contextmanager)SourceFileLoader)Callable GeneratorListOptionalTextIOTypeUnion) implementer)define) ParamSpecProtocol TypeAlias TypeGuard)defer)failurefilepathlogmodulesreflect)unittestutil) _ForceGarbageCollectionDecorator _iterateTests) _logObserver) ITestCase)UncleanWarningsReporterWrapper _ExitWrapper)r)itrial_PcVeZdZdeeefdej dejdefdZy) _DebuggerfargskwargsreturncyN)selfr4r5r6s 6/usr/lib/python3/dist-packages/twisted/trial/runner.pyruncallz_Debugger.runcall? N) __name__ __module__ __qualname__rr1objectr5r6r=r:r?r<r3r3>s8 "f*% .0gg AC  r?r3ct|tjsytjj tjj |jd}|dk(S)z>Given an object return True if the object looks like a packageFr__init__) isinstancetypes ModuleTypeospathsplitextbasename__file__)modulerLs r<r r EsL fe.. /ww 0 0 AB1EH z !!r?cd}|D]H}d|z}tjjtjj||sF|cSy)z Is the directory at path 'dirname' a Python package directory? Returns the name of the __init__ file (it may have a weird extension) if dirname is a package directory. Otherwise, returns False c>tjjSr9) importlib machinery all_suffixesr:r?r< _getSuffixesz(isPackageDirectory.._getSuffixesTs""//11r?rEF)rIrJexistsjoin)dirnamerTextinitFiles r<r r MsM2~# 77>>"'',,w9 :O r?ctjj|tjj|k(S)z A hacky implementation of C{os.path.samefile}. Used by L{filenameToModule} when the platform doesn't provide C{os.path.samefile}. Do not use this. )rIrJabspath) filename1 filename2s r<rr^s) 77??9 %)C CCr?cH|}dtjcxkrdkrTnnQtjj |s2tjj tj |}tjj|st|dtj|} tj|}t|dd t||Stjj|j ddz}ttjd t"}tjj%|r1|||s(tj&|j(=t||}|S#ttf$rt||cYSwxYw) aV Given a filename, do whatever possible to return a module object matching that file. If the file in question is a module in Python path, properly import and return that module. Otherwise, load the source manually. @param fn: A filename. @return: A module object. @raise ValueError: If C{fn} does not exist. ))r_ z doesn't exist) moduleNamerMNrz.pyr)sys version_inforIrJisabsrVgetcwdrU ValueErrorr&filenameToModuleNamenamedAnyAttributeError_importFromFilegetattrrKrMrisfiler%r@)fnoldFnrbretretFilesames r<r r fs? E !!+G+BGGMM"4EWW\\"))+r * 77>>" E9N344--b1J:z* sJ%-rj99ggs||,Q/%7G 277J 1D ww~~b$r7"3 KK %bZ8 J!  ':rj99:s3FF! F!ct|}|sBtjjtjj |dd}|t j vrt j |Stjj||}|s t|tjj|}|jj||t j |<|S)Nr)_resolveDirectoryrIrJrKsplitrcr%rQr(spec_from_file_location SyntaxErrormodule_from_specloader exec_module)rnrbspecrNs r<rkrks 2 B WW%%bggmmB&7&;> 1 1*b AD "o ^^ , ,T 2FKKF#$CKK  Mr?ctjj|r=t|}|r"tjj ||}|St |d|S)Nz is not a package directory)rIrJisdirr rVrg)rnrYs r<rurusT ww}}R%b) b(+B Iv%@AB B Ir?ct|j|jt|k7r@t |jD](}t|j|t|k(s&|cS|jS)z Find the attribute name on the method's class which refers to the method. For some methods, notably decorators which have not had __name__ set correctly: getattr(method.im_class, method.__name__) != method )rlim_classr@rCdir)methodaliass r<_getMethodNameInClassrs_v:fD) Evvx8FB   ??r?ceZdZdZdZy)rzQ A test suite which remove the tests once run, to minimize memory usage. c|jr?|jr |S|jjd}|||jr?|S)zn Almost the same as L{TestSuite.run}, but with C{self._tests} being empty at the end. r)_tests shouldStoppop)r;resulttests r<runzDestructiveTestSuite.runsI kk   ;;??1%D L kk  r?N)r@rArB__doc__rr:r?r<rrs  r?rz c"eZdZdZfdZxZS)rz[ Any errors logged in this suite will be reported to the L{TestResult} object. ct}|jt| ||j |j D]!}|j tt|#|jy)z Run the suite, storing all errors in C{result}. If an error is logged while no tests are running, then it will be added as an error to C{result}. @param result: A L{TestResult} object. N) r+_addsuperr_remove getErrorsaddErrorrr flushErrors)r;robservererror __class__s r<rzLoggedSuite.runsb    F'') z"TrialSuite._bail..s1::dCSr?mktemp) twisted.internetrr!DeferredaddSystemEventTriggerfireSystemEventr'TestCase_wait)r;rrs @r<_bailzTrialSuite._bailsN, NN %%gz;ST + (#))!,r?c| tj|||jy#|jwxYwr9)rrrr;rs r<rzTrialSuite.run s(  MM$ ' JJLDJJLs);)r:F)r@rArBrrErrrrs@r<r r s " -r?r _Loadablethingr7ct|tjr|jSt|tj tj fr |jSt|rtj|Std|)z @param thing: an object from modules (instance of PythonModule, PythonAttribute), a TestCase subclass, or an instance of a TestCase. z Cannot name ) rFpyunitridr%PythonAttribute PythonModulerr r&qual TypeError)rs r<rrsn %)xxz%'1173G3GHIzz%||E"" l5), --r?objcV t|tjS#t$rYywxYw)z @return: C{True} if C{obj} is a class that contains test cases, C{False} otherwise. Used to find all the tests in a module. F) issubclassrrr)rs r<r r 0s* #v// s  ((c8eZdZdZdZdZdZdZdZdZ dZ y) rz Placeholder for a L{TestCase} inside a reporter. As far as a L{TestResult} is concerned, this looks exactly like a unit test. Nc||_y)zM @param description: A string to be displayed L{TestResult}. N description)r;rs r<rEzTestHolder.__init__Ds 'r?c$|j|Sr9rrs r<__call__zTestHolder.__call__Jsxxr?c|jSr9rr;s r<rz TestHolder.idMr?cy)Nrr:rs r<countTestCaseszTestHolder.countTestCasesPsr?cj|j||j||j|y)z This test is just a placeholder. Run the test successfully. @param result: The C{TestResult} to store the results in. @type result: L{twisted.trial.itrial.IReporter}. N) startTest addSuccessstopTestrs r<rzTestHolder.runSs, $r?c|jSr9rrs r<shortDescriptionzTestHolder.shortDescription^rr?) r@rArBrfailureExceptionrErrrrrr:r?r<rr;s- '     r?rc4eZdZdZfdZdefdZdZxZS)ra Used to insert arbitrary errors into a test suite run. Provides enough methods to look like a C{TestCase}, however, when it is run, it simply adds an error to the C{TestResult}. The most common use-case is for when a module fails to import. cXt||tj||_y)a+ @param description: A string used by C{TestResult}s to identify this error. Generally, this is the name of a module that failed to import. @param error: The error to be added to the result. Can be an `exc_info` tuple or a L{twisted.python.failure.Failure}. N)rrEr(excInfoOrFailureToExcInfor)r;rrrs r<rEzErrorHolder.__init__js$ %33E: r?r7cTdj|j|jdS)Nz)r/)formatrrrs r<__repr__zErrorHolder.__repr__us):AA    JJqM  r?c|j||j||j|j|y)z Run the test, reporting the error. @param result: The C{TestResult} to store the results in. @type result: L{twisted.trial.itrial.IReporter}. N)rrrrrs r<rzErrorHolder.run{s0 djj)r?) r@rArBrrEstrrrrrs@r<rrbs ; # r?rceZdZUdZdZdZeZeee d<e Z e e gefe d<dZdZddZd ZeZd ZeZd Zd Zdd ZdZddZddZeZddeededefdZ dZ!ddZ"y)ra4 I find tests inside function, modules, files -- whatever -- then return them wrapped inside a Test (either a L{TestSuite} or a L{TestCase}). @ivar methodPrefix: A string prefix. C{TestLoader} will assume that all the methods in a class that begin with C{methodPrefix} are test cases. @ivar modulePrefix: A string prefix. Every module in a package that begins with C{modulePrefix} is considered a module full of tests. @ivar forceGarbageCollection: A flag applied to each C{TestCase} loaded. See L{unittest.TestCase} for more information. @ivar sorter: A key function used to sort C{TestCase}s, test classes, modules and packages. @ivar suiteFactory: A callable which is passed a list of tests (which themselves may be suites of tests). Must return a test suite. rtest_ suiteFactorysorterc0t||jS)zt Sort the given things using L{sorter}. @param xs: A list of test cases, class or modules. )key)sortedr)r;xss r<sortzTestLoader.sorts bdkk**r?cg}tj|D]"\}}t|s|j|$|j |S)z-Given a module, return all Trial test classes)inspect getmembersr rr)r;rNclassesrvals r<findTestClasseszTestLoader.findTestClassessI ++F3 $ID##s# $yy!!r?ctj|vr"tj|} t |n|}dx}x}}t|D]\}} tj|}|}n|Ntj"|}|j%dt'dj%|j(dzd} |D]} |t+|| }} |j/|||| S#t $r|j ||cYSwxYw#t $rtjd} | j| j} | j| jjj} | tjk7r|dk(rtj d|dYYwxYw#t,$rt-|dwxYw) a Find and load tests, given C{name}. @param _name: The qualified name of the thing to load. @param recurse: A boolean. If True, inspect modules within packages within the given package (and so on), otherwise, only inspect modules in the package itself. @return: If C{name} is a filename, return the module. If C{name} is a fully-qualified Python name, return the object it refers to. recurseNz The module z does not exist..r/)parentqualNamer)rIsepr&rh __import__ ImportErrorloadFile_qualNameWalker namedModulercexc_infotb_nexttb_framef_code co_filenamerMModuleNotFoundrirvlenr@rlrj loadAnything) r;_namerrrr remaining searchName remainingNametbfilenameWhereHappenedparts r< findByNamezTestLoader.findByNames 66U?//6D = 4 D#'''fy)8)>! W %J  W))*5* ! WF ;""4(C 3CIIcll,C(Dq(H(JKI <! 6"73#5  6  G!  w =}}UG}<< =. W\\^A&jj,Bjj,)+ (:(:(F(F% )G,<,<<?!00;tfDT1UVV#% WB < D6)9!:; ; t|tr tj|}tj|stjdyi}d}||d<tj|fi|S#t$r!t |t jcYSwxYw)z Return a suite of tests for all the doctests defined in C{module}. @param module: A module object or a module name. z&trial only supports doctesting modulesNczt|d|j|_|jj|_y)z Save C{test.globs} and replace it with a copy so that if necessary, the original will be available for the next test run. _savedGlobalsN)rlglobsr3copy)rs r< saveGlobalsz,TestLoader.loadDoctests..saveGlobalss/ ") !KD ++002DJr?setUp)rFrr&rir'rr"r(rismodulewarningswarndoctest DocTestSuite)r;rN extraArgsr6s r<rzTestLoader.loadDoctestsps fc " > ))&1' MMB C   3) '##F8i88%! >"67??+<== >sA22'BBNc:t|tjr/t|r|j ||S|j |St|t r+t|tjr|j|St|tjr^t|t rNt|tjr4|d}||}t||jj|k(sJ|St|tr|St!d|)a Load absolutely anything (as long as that anything is a module, package, class, or method (with associated parent class and qualname). @param obj: The object to load. @param recurse: A boolean. If True, inspect modules within packages within the given package (and so on), otherwise, only inspect modules in the package itself. @param parent: If C{obj} is a method, this is the parent class of the method. C{qualName} is also required. @param qualName: If C{obj} is a method, this a list containing is the qualified name of the method. C{parent} is also required. @return: A C{TestCase} or C{TestSuite}. rrtz"don't know how to make test from: )rFrGrHr r0loadTestsFromModulerrrrloadTestsFromTestCase FunctionTyperl_testMethodName__func__rr)r;rrrrrinsts r<rzTestLoader.loadAnythings c5++ ,~''W'==++C0 0 T "z#v'G--c2 2 sE.. /64(66??3B%( &E!(T9:.H` M#<c))'2O&++  !115 '( MMOsB B"ceZdZUeed<deejejfde jfdZ deejejfde jfdZ y)_Runnerstreamrr7cyr9r:r;rs r<rz _Runner.runEs r?cyr9r:r|s r<runUntilFailurez_Runner.runUntilFailureHr>r?N) r@rArBrrXrrrrr0 IReporterrr~r:r?r<ryryBsc N foov/?/??@ VEUEU  &//6+;+;;<    r?ryceZdZUdZdZdZeeee e jge jfed<dZeeed<dZeed<ej&Zeed <d Ze ed <d Zeed <d Ze ed<d Ze ed<dZeed<d Ze ed<dZeeed<d Ze ed<e Ze jed<de jfdZe defdZ!e de fdZ"de#e$jJe$jLfde jfdZ' dde#e$jJe$jLfde de jfdZ(de#e$jJe$jLfde jfdZ)y) ra A specialised runner that the trial front end uses. @ivar reporterFactory: A callable to create a reporter to use. @ivar mode: Either C{None} for a normal test run, L{TrialRunner.DEBUG} for a run in the debugger, or L{TrialRunner.DRY_RUN} to collect and report the tests but not call any of them. @ivar logfile: The path to the file to write the test run log. @ivar stream: The file to report results to. @ivar profile: C{True} to run the tests with a profiler enabled. @ivar _tracebackFormat: A format name to use with L{Failure} for reporting failures. @ivar _realTimeErrors: C{True} if errors should be reported as they happen. C{False} if they should only be reported at the end of the test run in the summary. @ivar uncleanWarnings: C{True} to report dirty reactor errors as warnings, C{False} to report them as test-failing errors. @ivar workingDirectory: A path template to a directory which will be the process's working directory while the tests are running. @ivar _forceGarbageCollection: C{True} to perform a full garbage collection at least after each test. C{False} to let garbage collection run only when it normally would. @ivar debugger: In debug mode, an object to use to launch the debugger. @ivar _exitFirst: C{True} to stop after the first failed test. C{False} to run the whole suite. @ivar log: An object to give to the reporter to use as a log publisher. debugzdry-runreporterFactoryNmodeztest.logrjrzFprofiledefault_tracebackFormat_realTimeErrorsuncleanWarnings _trial_tempr__forceGarbageCollectiondebugger _exitFirst_logr7c|j|j|j|j|j}|j r t |}|jr t|}|Sr9) rrztbformatrterrorsrrr.rr-)r;reporters r< _makeResultzTrialRunner._makeResultsV'' KK tyy  ??#H-H   5h?Hr?c|jSr9)rrs r<rzTrialRunner.tbformats$$$r?c|jSr9)rrs r<rzTrialRunner.rterrorss###r?rctj|t}|jr!t j |j d}n |j }|||jS)zC Run the test or suite and return a result object. z profile.data)r'rr,rr(profiled_runWithoutDecorationr)r;rrs r<rzTrialRunner.runsQ  y1 <<-- : :NKC,,C45566r?rc@jt|g|jjk(rDt D]5}j |j |j|7nxjjk(rjJfd}nfd}tj5tj5|ddddddjS#1swY#xYw#1swY'xYw)zR Private helper that runs the given test but doesn't decorate it. NcPjjjSr9)rr=r)rr;rsr<rz3TrialRunner._runWithoutDecoration..sdmm33EIIvFr?c&jSr9r)rrsr<rz3TrialRunner._runWithoutDecoration..seii/r?)rr rDRY_RUNr*rrrDEBUGrrir_rwrjdone)r;rrsinglerrrs` @@r<rz!TrialRunner._runWithoutDecorations!!#D6#9: 99 $'. (  (!!&)' ( yyDJJ&}}000F/ 5 56 8N          s$DD&DD DDcd} |dz }|jjd|fz|dk(r|j|}n|j|}|jdk(r |S|j s |Sr)z8 Repeatedly run C{test} until it fails. rr/z Test Pass %d )rzwriterrtestsRun wasSuccessful)r;rcountrs r<r~zTrialRunner.runUntilFailures  QJE KK  .%9 :z$33D9!# '') r?rW)*r@rArBrrrrrrrZr$ LogPublisherr0rrXrrrjrcrmrzrrrrr_rrr3rrrpropertyrrrrrrrrr~r:r?r<rrNs&P EGvsD#2B2BCVEUEUUVVD(3-GSZZFFGT%c%!OT!!OT!)c)$)T)$(Hhy!(J D#   V--%#%%$$$$ 7foov/?/??@ 7VEUEU 7(-FOOV%5%556!%    >&//6+;+;;<   r?r)Ur__all__r;rQrrIrcrGr'rr9 contextlibrimportlib.machineryrtypingrrrrrrrzope.interfacerattrsrrrrr rr!twisted.pythonr"r#r$r%r& twisted.trialr(twisted.trial._asyncrunnerr)r*twisted.trial._synctestr+twisted.trial.itrialr,twisted.trial.reporterr-r.twisted.trial.unittestrrr0r1r3r r rr rkrurrrrr rrrrrXrrrr rrrrrirwryrr:r?r<rs  $ %0KKK&<<"CC(V0*O-t_  ""D.b   9( ).!!H   OO 9. .c.,DYtFOO'<= Y# # # L"*"JvBvBvBr A,SY7G-H&ci(89,  h  LLLr?