Ϫf UdZddlmZddlZddlZddlZddlZddlZddl m Z ddl m Z ddl mZmZmZmZmZmZddlmZddl mZdd lmZmZdd lmZdd lmZdd lmZdd l m!Z!m"Z"erddl#m$Z$ ddl%m&Z&eee(e(e fZ)de*d<ee)edfZ+ee+efZ,d8dZ-Gdde.Z/GddZ0ee!jbGddejdZ2ee!jbGddee!jbdZ3ee!jbGdde3Z4ee!jbGd d!e3Z5Gd"d#e3Z6ee!jbGd$d%e2Z7Gd&d'e7Z8Gd(d)e7Z9Gd*d+e7Z:Gd,d-e:Z;Gd.d/Z<Gd0d1Z=Gd2d3Z>ee!jbGd4d5Z?Gd6d7e7Z@y#e'$rdZ&YwxYw)9z3 Defines classes that handle the results of tests. ) annotationsN) OrderedDict) TracebackType) TYPE_CHECKINGListOptionalTupleTypeUnion) implementer) TypeAlias)logreflect)proxyForInterface)Failure)untilConcludes)itrialutil)Todo)TestProtocolClientr ExcInfo)NNNcddlm}||S)ad Return a L{Todo} object built from C{value}. This is a synonym for L{twisted.trial.unittest.makeTodo}, but imported locally to avoid circular imports. @param value: A string or a tuple of C{(errors, reason)}, where C{errors} is either a single exception class or an iterable of exception classes. @return: A L{Todo} object. r)makeTodo)twisted.trial.unittestr)valuers 8/usr/lib/python3/dist-packages/twisted/trial/reporter.py _makeTodor,s0 E?ceZdZdZy)BrokenTestCaseWarningzT Emitted as a warning when an exception occurs in one of setUp or tearDown. N__name__ __module__ __qualname____doc__rrr!r!=srr!c"eZdZdZdZdZdZy) SafeStreamz Wraps a stream object so that all C{write} calls are wrapped in L{untilConcludes}. c||_yN)original)selfr,s r__init__zSafeStream.__init__Is   rc.t|j|Sr+)getattrr,)r-names r __getattr__zSafeStream.__getattr__Lst}}d++rcHt|jjg|i|Sr+)rr,write)r-akws rr4zSafeStream.writeOs!dmm11r?)r- __class__s rr.zTestResult.__init__lsB  "#%   rc &dtj|j|jt |j t |j t |jt |jt |jfzS)Nz<<%s run=%d errors=%d failures=%d todos=%d dones=%d skips=%d>) rqualrCtestsRunlenerrorsfailuresr:r9r;r-s r__repr__zTestResult.__repr__vskM LL ( MM     %% &  O (( )Q   rc*tjSr+)timerJs r_getTimezTestResult._getTimesyy{rct|txrt|dk(}|rt|d|d|dSt|tr|St d|d)zX Convert a C{sys.exc_info()}-style tuple to a L{Failure}, if necessary. rrzCannot convert z to a Failure) isinstancetuplerGr TypeError)r-erroris_exc_info_tuples r _getFailurezTestResult._getFailures_'ue4HUq 58U1XuQx8 8 w 'L/% >??rcNt|||j|_y)zq This must be called before the given test is commenced. @type test: L{pyunit.TestCase} N)rA startTestrNr>r-testrCs rrYzTestResult.startTests $ MMOrct|||j#|j|jz |_yy)zp This must be called after the given test is completed. @type test: L{pyunit.TestCase} N)rAstopTestr>rNr?rZs rr]zTestResult.stopTests;     (!]]_t/@/@@DN )rc\|jj||j|fy)z Report a failed assertion for the given test. @type test: L{pyunit.TestCase} @type fail: L{Failure} or L{tuple} N)rIappendrW)r-r[fails r addFailurezTestResult.addFailures& dD$4$4T$:;|jj||fy)a5 Report that the given test was skipped. In Trial, tests can be 'skipped'. Tests are skipped mostly because there is some platform or configuration issue that prevents them from being run correctly. @type test: L{pyunit.TestCase} @type reason: L{str} N)r9r_)r-r[reasons raddSkipzTestResult.addSkips 4.)rcl|t|j}|jj||fy)a Report that the given test succeeded against expectations. In Trial, tests can be marked 'todo'. That is, they are expected to fail. When a test that is expected to fail instead succeeds, it should call this method to report the unexpected success. @type test: L{pyunit.TestCase} @type todo: L{unittest.Todo}, or L{None}, in which case a default todo message is provided. N)r _DEFAULT_TODOr;r_r-r[todos raddUnexpectedSuccesszTestResult.addUnexpectedSuccesss1 <T//0D   ''t 5rcn|t|j}|jj|||fy)ab Report that the given test failed, and was expected to do so. In Trial, tests can be marked 'todo'. That is, they are expected to fail. @type test: L{pyunit.TestCase} @type error: L{Failure} @type todo: L{unittest.Todo}, or L{None}, in which case a default todo message is provided. N)rrir:r_)r-r[rUrks raddExpectedFailurezTestResult.addExpectedFailures4 <T//0D $$dE4%89rc.|xjdz c_y)z_ Report that the given test succeeded. @type test: L{pyunit.TestCase} rN)r=r-r[s r addSuccesszTestResult.addSuccesss !rcnt|jt|jcxk(xrdk(ScS)a Report whether or not this test suite was successful or not. The behaviour of this method changed in L{pyunit} in Python 3.4 to fail if there are any errors, failures, or unexpected successes. Previous to 3.4, it was only if there were errors or failures. This method implements the old behaviour for backwards compatibility reasons, checking just for errors and failures. @rtype: L{bool} r)rGrIrHrJs r wasSuccessfulzTestResult.wasSuccessfuls,4==!S%5:::::rcy)z6 The test suite has finished running. Nr'rJs rdonezTestResult.doner)returnstrr+)r#r$r%r&ri__annotations__r.rKrNrWrYr]rardrgrlrnrqrsru __classcell__rCs@rr8r8Ssz ,M --@@;;N   @,A=< *6 :  ; rr8ceZdZdZy)TestResultDecoratorz Base class for TestResult decorators. @ivar _originalReporter: The wrapped instance of reporter. @type _originalReporter: A provider of L{itrial.IReporter} Nr"r'rrr}r}srr}_originalReporterceZdZdZdZy)UncleanWarningsReporterWrapperze A wrapper for a reporter that converts L{util.DirtyReactorAggregateError}s to warnings. ct|trC|jtjr$t j |jy|jj||y)z If the error is a L{util.DirtyReactorAggregateError}, instead of reporting it as a normal error, throw a warning. N) rRrcheckrDirtyReactorAggregateErrorwarningswarngetErrorMessager~rdrcs rrdz'UncleanWarningsReporterWrapper.addErrorsJ eW %%++d6U6U*V MM%//1 2  " " + +D% 8rN)r#r$r%r&rdr'rrrr s  9rrceZdZdZdZdZy) _ExitWrapperza A wrapper for a reporter that causes the reporter to stop after unsuccessful tests. cHd|_|jj|i|SNT) shouldStopr~rdr-argskwargss rrdz_ExitWrapper.addError#s'.t%%..???rcHd|_|jj|i|Sr)rr~rars rraz_ExitWrapper.addFailure's'0t%%00$A&AArN)r#r$r%r&rdrar'rrrrs @BrrcDeZdZdZdZdZd dZdZdZd dZ d Z d Z y) _AdaptedReporterz TestResult decorator that makes sure that addError only gets tests that have been adapted with a particular test adapter. c>tj||||_y)z Construct an L{_AdaptedReporter}. @param original: An {itrial.IReporter}. @param testAdapter: A callable that returns an L{itrial.ITestCase}. N)r}r. testAdapter)r-r,rs rr.z_AdaptedReporter.__init__2s $$T84&rc\|j|}|jj||Sz* See L{itrial.IReporter}. )rr~rdrcs rrdz_AdaptedReporter.addError<s-%%%..tU;;rNcZ|jj|j|||S)at See L{itrial.IReporter}. @type test: A L{pyunit.TestCase}. @type failure: A L{failure.Failure} or L{AssertionError} @type todo: A L{unittest.Todo} or None When C{todo} is L{None} a generic C{unittest.Todo} is built. L{pyunit.TestCase}'s C{run()} calls this with 3 positional arguments (without C{todo}). )r~rnr)r-r[failurerks rrnz#_AdaptedReporter.addExpectedFailureCs/%%88   T "GT  rc\|j|}|jj||Sr)rr~ra)r-r[rs rraz_AdaptedReporter.addFailureTs-%%%00w??rc\|j|}|jj||Sr)rr~rg)r-r[skips rrgz_AdaptedReporter.addSkip[s-%%%--dD99rc\|j|}|jj||S)a3 See L{itrial.IReporter}. @type test: A L{pyunit.TestCase}. @type todo: A L{unittest.Todo} or None When C{todo} is L{None} a generic C{unittest.Todo} is built. L{pyunit.TestCase}'s C{run()} calls this with 2 positional arguments (without C{todo}). )rr~rlrjs rrlz%_AdaptedReporter.addUnexpectedSuccessbs-%%%::4FFrcV|jj|j|Sr)r~rYrrps rrYz_AdaptedReporter.startTestqs&%%//0@0@0FGGrcV|jj|j|Sr)r~r]rrps rr]z_AdaptedReporter.stopTestws&%%..t/?/?/EFFrr+) r#r$r%r&r.rdrnrargrlrYr]r'rrrr,s3 '< "@: GH GrrceZdZdZdZdZejdddffd ZdZ fd Z fd Z fd Z d Z d Zdfd ZfdZdZdZdZdZdZdZdZdZdZdZxZS)Reportera A basic L{TestResult} with support for writing to a stream. @ivar _startTime: The time when the first test was started. It defaults to L{None}, which means that no test was actually launched. @type _startTime: C{float} or L{None} @ivar _warningCache: A C{set} of tuples of warning message (file, line, text, category) which have already been written to the output stream during the currently executing test. This is used to avoid writing duplicates of the same warning to the output stream. @type _warningCache: C{set} @ivar _publisher: The log publisher which will be observed for warning events. @type _publisher: L{twisted.python.log.LogPublisher} zO-------------------------------------------------------------------------------zO===============================================================================defaultFNct|t||_||_||_d|_t|_||_ ||j|jyyr+) rAr.r)_streamtbformatrealtime _startTimeset _warningCache _publisher addObserver_observeWarnings)r-streamrr publisherrCs rr.zReporter.__init__sc !&)      U$   ! !$"7"7 8 !rcd|vrv|d|d|djddt|df}||jvr:|jj||jj d|zyyy) a| Observe warning events and write them to C{self._stream}. This method is a log observer which will be registered with C{self._publisher.addObserver}. @param event: A C{dict} from the logging system. If it has a C{'warning'} key, a logged warning will be extracted from it and possibly written to C{self.stream}. warningfilenamelinenocategory.z%s:%s: %s: %s N)splitrxraddrr4)r-eventkeys rrzReporter._observeWarningss  j!hj!'',R0E)$% C $,,,""&&s+ ""#4s#:;- rct|||j|j|_t |_y)z Called when a test begins to run. Records the time when it was first called and resets the warning cache. @param test: L{ITestCase} N)rArYrrNrrrZs rrYzReporter.startTests3 $ ?? ""mmoDO Urct||||jr3|jdd}|j |j |yy)z Called when a test fails. If C{realtime} is set, then it prints the error to the stream. @param test: L{ITestCase} that failed. @param fail: L{failure.Failure} containing the error. rrN)rArarrI_write_formatFailureTraceback)r-r[r`rCs rrazReporter.addFailuresJ 4& ====$Q'D KK44T: ; rc|j|}t| |||jr3|jdd}|j |j |yy)z Called when a test raises an error. If C{realtime} is set, then it prints the error to the stream. @param test: L{ITestCase} that raised the error. @param error: L{failure.Failure} containing the error. rrN)rWrArdrrHrr)r-r[rUrCs rrdzReporter.addErrorsY  ' u% ==KKOA&E KK44U; < rct|}t|tsJ|r|jj||zn|jj|t |jj y)z Safely write to the reporter's stream. @param format: A format string to write. @param args: The arguments for the format string. N)rxrRrr4rflush)r-formatrss rrzReporter._writesZ K!S!!!  LL  q4x ( LL  q !t||))*rcL|j|g||jdy)z Safely write a line to the reporter's stream. Newline is appended to the format string. @param format: A format string to write. @param args: The arguments for the format string.  N)r)r-rrs r_writelnzReporter._writelns#  F"T" Drct||||||rU|j|}tj|dj ||}t j|tdyy)Nz3caught exception in {}, your TestCase is broken {}rQ) stacklevel) rA upDownErrorrrmsgrrrr!)r-methodrUr printStatustbStrrrCs rrzReporter.upDownErrorsb FE4= 007E GGENIPPC MM#4 C rct||tjdd|j |t y)Nz&REACTOR UNCLEAN! traceback(s) follow: r)rA cleanupErrorsrrrr!r-errsrCs rrzReporter.cleanupErrorss9 d# 9,,T2  "  rct|}t|dkr|S|dd}tjj tjj |ddd}|dd}tjj tjj |ddd}d}d}||f||ff} |D]s} tjj tjj | dd} | dk(sK| ddk(sT|j |j| u| |k(r|dd}n| |k(r|d d}n ||fd k(r|dd}|s|S|d } | djd rJtjj tjj | ddd k(r|dd }|S)a) Trim frames to remove internal paths. When a C{SynchronousTestCase} method fails synchronously, the stack looks like this: - [0]: C{SynchronousTestCase._run} - [1]: C{util.runWithWarningsSuppressed} - [2:-2]: code in the test method which failed - [-1]: C{_synctest.fail} When a C{TestCase} method fails synchronously, the stack looks like this: - [0]: C{defer.maybeDeferred} - [1]: C{utils.runWithWarningsSuppressed} - [2]: C{utils.runWithWarningsSuppressed} - [3:-2]: code in the test method which failed - [-1]: C{_synctest.fail} When a method fails inside a C{Deferred} (i.e., when the test method returns a C{Deferred}, and that C{Deferred}'s errback fires), the stack captured inside the resulting C{Failure} looks like this: - [0]: C{defer.Deferred._runCallbacks} - [1:-2]: code in the testmethod which failed - [-1]: C{_synctest.fail} As a result, we want to trim either [maybeDeferred, runWWS, runWWS] or [Deferred._runCallbacks] or [SynchronousTestCase._run, runWWS] from the front, and trim the [unittest.fail] from the end. There is also another case, when the test method is badly defined and contains extra arguments. If it doesn't recognize one of these cases, it just returns the original frames. @param frames: The C{list} of frames from the test failure. @return: The C{list} of frames to display. rQrr))_run _synctest)runWithWarningsSuppressedr)) maybeDeferreddefer)rutilscompatreraiseNrP) _runCallbacksrrr`r) listrGospathsplitextbasenamepopindex startswith) r-frames newFrames firstMethod firstFile secondMethod secondFilesyncCase asyncCase twoFramesframe frameFilelasts r _trimFrameszReporter._trimFramessPL v;? l1o GG$$RWW%5%5il1o%FGJ  |A WW%%bgg&6&6y|A&GHK QX !9- j/IJ  6E(()9)9%()CDQGIH$qY)> iooe45  6  !!" I ) #!!" I9 %)C C!!" I } G  v &  !1!1$q'!:;A>+M!#2Irct|tr|jdzS|j|j|jc|_}|j |j d}||_|S)NrT)detailelideFrameworkCode)rRrxrstriprr getTracebackr)r-r`rresults rrz Reporter._formatFailureTracebackesc dC ;;=4' '"..t{{;T[[ V""$--D"Q  rct}|D]2}|d}|dd}||}|j|gj|4t|j S)a  Group tests together based on their results. @param results: An iterable of tuples of two or more elements. The first element of each tuple is a test case. The remaining elements describe the outcome of that test case. @param formatter: A callable which turns a test case result into a string. The elements after the first of the tuples in C{results} will be passed as positional arguments to C{formatter}. @return: A C{list} of two-tuples. The first element of each tuple is a unique string describing one result from at least one of the test cases in C{results}. The second element is a list of the test cases which had that result. rrN)r setdefaultr_ritems)r-results formattergroupscontentcaseoutcomers r _groupResultszReporter._groupResultsmsf$ 4G1:DabkGW%C   c2 & - -d 3  4 FLLN##rc |j||D]y\}}|j|j|j||j||jd|D]!}|j|j #{y)a< Print a group of errors to the stream. @param flavor: A string indicating the kind of error (e.g. 'TODO'). @param errors: A list of errors, often L{failure.Failure}s, but sometimes 'todo' errors. @param formatter: A callable that knows how to format the errors. N)rr_doubleSeparatorrid)r-flavorrHrrfcasesrs r _printResultszReporter._printResultss{"// B )MFE MM$// 0 MM& ! KK  MM"  ) dggi( )  )rcXdj|j|j|S)NzReason: {!r} {})rrfr)r-rUrks r_printExpectedFailurezReporter._printExpectedFailures)!(( KK55e<  rcd|jd}|jr-|djdj|jz }|S)NzReason: rzExpected errors: {} , )rfrHrjoin)r-rkrets r_printUnexpectedSuccessz Reporter._printUnexpectedSuccesssCr* ;; *11$))DKK2HI IC rc|jd|jd|jd|jd|j|j|jd|j |j |jd|j|j |jd|j|jy) zM Print all of the non-success results to the stream in full. r [SKIPPED]c d|zS)N%s r')xs rz'Reporter._printErrors..s fqjr[TODO][FAIL][ERROR] [SUCCESS!?!]N) rrr9r:rrIrrHr;r rJs r _printErrorszReporter._printErrorss D ; 4HI 8T%:%:D>   ^t~~.?? @B )(s D! K rc@t|||jdyNr r>r8s rrgzVerboseTextReporter.addSkipBs  K rc@t|||jdyNrrAr8s rrnz&VerboseTextReporter.addExpectedFailureFs "D) Hrc@t|||jdyNrrDr8s rrlz(VerboseTextReporter.addUnexpectedSuccessJs $d+ N#rcFt|||jdy)Nr)rAr]rrZs rr]zVerboseTextReporter.stopTestNs  Dr) r#r$r%r&rYrqrdrargrnrlr]rzr{s@rrFrF(s5!!$rrFc"eZdZdZfdZxZS)TimingTextReporterze Prints out each test as it is running, followed by the time taken for each test to run. c`t|||jd|jzy)zm Mark the test as stopped, and write the time it took to run the test to the stream. z (%.03f secs) N)rAr]rr?)r-rrCs rr]zTimingTextReporter.stopTestYs(   $t~~56r)r#r$r%r&r]rzr{s@rrVrVSs 77rrVc deZdZdZedddddddd Zd Zeejfd Z d Z y)_AnsiColorizerz A colorizer is an object that loosely wraps around a stream, allowing callers to write text to the stream in a particular color. Colorizer classes must implement C{supported()} and C{write(text, color)}.  !"#$%)blackredgreenyellowbluemagentacyanwhitec||_yr+rr-rs rr.z_AnsiColorizer.__init__n  rc|jsy ddl} |jddkDS#|j$r'|j |jddkDcYSwxYw#t $rYywxYw#t $rYywxYw)z A class method that returns True if the current platform supports coloring terminal output using this method. Returns False otherwise. FrNcolorsrQ)isattycursestigetnumrU setupterm BaseException ImportError)clsrrqs r supportedz_AnsiColorizer.supportedqs }}   9!??84q88||9$$&!??84q889!    s8A5-3A# A&"A##A&& A21A25 BBcf|j|}|jjd|d|dy)z Write the given text to the stream in the given color. @param text: Text to be written to the stream. @param color: A string label for a color. e.g. 'red', 'white'. z;1mzN)_colorsrr4r-textcolors rr4z_AnsiColorizer.writes3 U# E%D69:rN) r#r$r%r&dictryr. classmethodr&r'rwr4r'rrrYrYbsJb2BSUG!jj, ;rrYcDeZdZdZdZeejfdZdZ y)_Win32Colorizer' See _AnsiColorizer docstring. c ddlm}m}m}m}m}m}||||f\}} } } ||_|||_|| z| z|| z| | z| | z|| z| z|| z| z| | z| z|| z| z| zd|_ y)Nr)FOREGROUND_BLUEFOREGROUND_GREENFOREGROUND_INTENSITYFOREGROUND_REDSTD_OUTPUT_HANDLE GetStdHandle)normalrcrdrfrergrhri) win32consolerrrrrrr screenBufferry) r-rrrrrrrrcrdrfbolds rr.z_Win32Colorizer.__init__s      " UD$  ():;EkD(:T\4KEkD(TzD(DL4'5[4'$.   rc ddl}|j|j}ddl} |j |j |jz|jzy#t$rYywxYw#|j$rYywxYw)NrFT) rrrru pywintypesSetConsoleTextAttributerrrrU)rvrrrrs rrwz_Win32Colorizer.supporteds  '44\5S5STL    0 0++//0../     s"A5A+ A('A(+A=<A=c|j|}|jj||jj ||jj|jdy)Nr)ryrrrr4rzs rr4z_Win32Colorizer.writesS U# 11%8 $ 11$,,x2HIrN r#r$r%r&r.r~r&r'rwr4r'rrrrs- :!jj(JrrcDeZdZdZdZeejfdZdZ y)_NullColorizerrc||_yr+rkrls rr.z_NullColorizer.__init__rmrcyrr')rvrs rrwz_NullColorizer.supportedsrc:|jj|yr+)rr4rzs rr4z_NullColorizer.writes $rNrr'rrrrs,!jj rrceZdZdZdZej dddfdZdZe dZ dZ d Z d Z d Zd Zd ZdZdZddZddZy)SubunitReporterz Reports test output via Subunit. @ivar _subunit: The subunit protocol client that we are wrapping. @ivar _successful: An internal variable, used to track whether we have received only successful results. @since: 10.0 NrFcTt tdt||_d|_y)aI Construct a L{SubunitReporter}. @param stream: A file-like object representing the stream to print output to. Defaults to stdout. @param tbformat: The format for tracebacks. Ignored, since subunit always uses Python's standard format. @param realtime: Whether or not to print exceptions in the middle of the test results. Ignored, since subunit always does this. @param publisher: The log publisher which will be preserved for reporting events. Ignored, as it's not relevant to subunit. NzSubunit not availableT)r Exception_subunit _successful)r-rrrrs rr.zSubunitReporter.__init__s*  %34 4*62 rcy)z Record that the entire test suite run is finished. We do nothing, since a summary clause is irrelevant to the subunit protocol. Nr'rJs rruzSubunitReporter.dones rc.|jjS)zK Whether or not the test runner should stop running tests. )rrrJs rrzSubunitReporter.shouldStops }}'''rc6|jjS)zH Signal that the test runner should stop running tests. )rstoprJs rrzSubunitReporter.stops}}!!##rc|jS)z Has the test run been successful so far? @return: C{True} if we have received no reports of errors or failures, C{False} otherwise. )rrJs rrszSubunitReporter.wasSuccessfulsrc8|jj|S)z2 Record that C{test} has started. )rrYrps rrYzSubunitReporter.startTest's}}&&t,,rc8|jj|S)z4 Record that C{test} has completed. )rr]rps rr]zSubunitReporter.stopTest-s}}%%d++rc8|jj|S)z5 Record that C{test} was successful. )rrqrps rrqzSubunitReporter.addSuccess3s}}''--rct|jdd}||j|y|jj||y)a Record that C{test} was skipped for C{reason}. Some versions of subunit don't have support for addSkip. In those cases, the skip is reported as a success. @param test: A unittest-compatible C{TestCase}. @param reason: The reason for it being skipped. The C{str()} of this object will be included in the subunit output stream. rgN)r0rrqrg)r-r[rfrgs rrgzSubunitReporter.addSkip9s;$--D9 ? OOD ! MM ! !$ /rcnd|_|jj|tj|S)z Record that C{test} failed with an unexpected error C{err}. Also marks the run as being unsuccessful, causing L{SubunitReporter.wasSuccessful} to return C{False}. F)rrrdrexcInfoOrFailureToExcInfor-r[errs rrdzSubunitReporter.addErrorJs.!}}%%dD,J,J3,OPPrcnd|_|jj|tj|S)z Record that C{test} failed an assertion with the error C{err}. Also marks the run as being unsuccessful, causing L{SubunitReporter.wasSuccessful} to return C{False}. F)rrrarrrs rrazSubunitReporter.addFailureTs.!}}''d.L.LS.QRRrctj|}t|jdd}||j |y|||y)z Record an expected failure from a test. Some versions of subunit do not implement this. For those versions, we record a success. rnN)rrr0rrq)r-r[rrkrns rrnz"SubunitReporter.addExpectedFailure^sD009$T]]4H$O  % OOD ! tW -rc&|j|y)z Record an unexpected success. Since subunit has no way of expressing this concept, we record a success on the subunit stream. N)rqrjs rrlz$SubunitReporter.addUnexpectedSuccessls rr+)r#r$r%r&rFr&r'r.rupropertyrrrsrYr]rqrgrdrarnrlr'rrrrso HZZ)et ( (( $  - , . 0"QS .rrceZdZdZdZdZdZdZdZdZ dZ dZ dZ e jffd Zd Zfd Zfd Zfd Zfd ZfdZfdZfdZdZdZfdZfdZfdZfdZdZxZS) TreeReporterz Print out the tests in the form a tree. Tests are indented according to which class and module they belong. Results are printed in ANSI color. rz Orcrfrdct||g|i|g|_ttt fD]"}|j |s|||_yyr+)rAr. _lastTestrrYrrw _colorizer)r-rrr colorizerrCs rr.zTreeReporter.__init__sT 1$1&1)>>J I""6*"+F"3 rcF|jjddS)z Return the name of the method which 'test' represents. This is what gets displayed in the leaves of the tree. e.g. getDescription(TestCase('test_foo')) ==> test_foo rr)rrrps rgetDescriptionzTreeReporter.getDescriptionswwys#B''rc\t|||jd|jyrJ)rArqendLineSUCCESSrZs rrqzTreeReporter.addSuccesss" 4  VT\\*rcVt|||jd|jyrL)rArdrERRORr8s rrdzTreeReporter.addErrors" $ Y +rcVt|||jd|jy)Nr)rArarFAILUREr8s rrazTreeReporter.addFailures" D! Xt||,rcVt|||jd|jyrO)rArgrSKIPr8s rrgzTreeReporter.addSkips!  [$)),rcVt|||jd|jyrQ)rArnrTODOr8s rrnzTreeReporter.addExpectedFailures" "D) Xtyy)rcVt|||jd|jyrS)rArlrTODONEr8s rrlz!TreeReporter.addUnexpectedSuccesss" $d+ ^T[[1rcT|r||z}||_t| |jyr+) currentLinerAr)r-rrrCs rrzTreeReporter._writes) d]F! t''(rc|jddd}t|dk(r|Sdj|dd|dfDcgc]}t|dkDs|}}|Scc}w)z Return a list of all non-leaf segments to display in the tree. Normally this is the module and class name. rNrr)rrGr )r-testIDsegmentssegs r_getPreludeSegmentsz TreeReporter._getPreludeSegmentsss <<$Sb) x=A OHHXcr]3Xb\B c#hQRlC   s AAc2|j|}d}|D]x}|t|jkr6||j|k7rG|j|j|z|dn#|j|j|z|d|dz }z||_y)z Write the name of the test to the stream, indenting it appropriately. If the test is the first test in a new 'branch' of the tree, also write all of the parents in that branch. rrrN)rrGrrindent)r-rr indentLevelrs r _testPreludezTreeReporter._testPreludes++F3  CS00$..55KK4;;#<"=cU" EF t{{[89#bAB 1 K  "rc|jjd|j|jd|jt||y)Nz cleanup errorsr)rr4rrrArrs rrzTreeReporter.cleanupErrorss; 2DJJ? Y + d#rc|jjd|z|j|r|jd|jt|||||y)Nz %sr)rr4rrrAr)r-rrUrrrCs rrzTreeReporter.upDownErrorsG fvotzz:  LLDJJ / FE4=rc|j|j|j|jt |j z|j |dt|!|y)zn Called when C{test} starts. Writes the tests name to the stream using a tree format. z ... N) rrrrrGrrrArYrZs rrYzTreeReporter.startTests\ $'')$ {{c$..12D4G4G4M O  $rcd|jt|jz t|z z}t|||j j ||t|dy)z Print 'message' in the given color. @param message: A string message, usually '[OK]' or something similar. @param color: A string color, 'red', 'green' and so forth. r,rN)columnsrGrrArrr4)r-messager|spacesrCs rrzTreeReporter.endLinesX s4+;+;'<    %rr)rrxrwz'Todo')Ar& __future__rrr&rMunittestpyunitr collectionsrtypesrtypingrrrr r r zope.interfacer r twisted.pythonrrtwisted.python.componentsrtwisted.python.failurertwisted.python.utilr twisted.trialrrrrsubunitrrurtrry XUnitFailure TrialFailurerWarningr!r) IReporterr8r}rrrrr)r2rFrVrYrrrrr'rrrs># #DD&'7*.&*4 . }LMMWe$4556 \7*+ "G = =  V  f ""f f R V  f&&(;< V  9%899$ V   B& B BOG*OGd V  ezeeP -h-D8>(((V 7, 7/;/;d;J;J|    V  QQQhR%8R%g"s1G,,G76G7