o b@sdZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z m Z ddlmZddlmZddlmZdd lmZmZzdd lmZWn eyWdZYnwd d ZGd ddeZGdddZe ejGdddejZe ejGdddeejdZ e ejGddde Z!e ejGddde Z"Gddde Z#e ejGdddeZ$Gddde$Z%Gd d!d!e$Z&Gd"d#d#e$Z'Gd$d%d%e'Z(Gd&d'd'Z)Gd(d)d)Z*Gd*d+d+Z+e ejGd,d-d-Z,Gd.d/d/e$Z-dS)0z3 Defines classes that handle the results of tests. N) OrderedDict) implementer)logreflect)proxyForInterface)Failure)untilConcludes)itrialutil)TestProtocolClientcCsddlm}||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 )valuer r8/usr/lib/python3/dist-packages/twisted/trial/reporter.py _makeTodo!s rc@eZdZdZdS)BrokenTestCaseWarningzT Emitted as a warning when an exception occurs in one of setUp or tearDown. N__name__ __module__ __qualname____doc__rrrrr2src@s(eZdZdZddZddZddZdS) SafeStreamz Wraps a stream object so that all C{write} calls are wrapped in L{untilConcludes}. cC ||_dSN)original)selfrrrr__init__> zSafeStream.__init__cCs t|j|Sr)getattrr)rnamerrr __getattr__As zSafeStream.__getattr__cOst|jjg|Ri|Sr)rrwrite)rakwrrrr#DszSafeStream.writeN)rrrrrr"r#rrrrr8s  rcseZdZdZdZfddZdefddZdd Zd d Z fd d Z fddZ ddZ ddZ ddZd!ddZd!ddZddZddZdd ZZS)" TestResultz Accumulates the results of several L{twisted.trial.unittest.TestCase}s. @ivar successes: count the number of successes achieved by the test run. @type successes: C{int} zTest expected to failcs,tg|_g|_g|_d|_g|_dS)Nr)superrskipsexpectedFailuresunexpectedSuccesses successes_timingsr __class__rrrTs  zTestResult.__init__returnc Cs>dt|j|jt|jt|jt|jt|jt|j fS)Nz<<%s run=%d errors=%d failures=%d todos=%d dones=%d skips=%d>) rqualr/testsRunlenerrorsfailuresr)r(r*r-rrr__repr__\s zTestResult.__repr__cCstSr)timer-rrr_getTimegszTestResult._getTimecCs&t|trt|d|d|dS|S)zX Convert a C{sys.exc_info()}-style tuple to a L{Failure}, if necessary. r) isinstancetupler)rerrorrrr _getFailurejs zTestResult._getFailurecst|||_dS)zq This must be called before the given test is commenced. @type test: L{pyunit.TestCase} N)r' startTestr8 _testStartedrtestr.rrr?rs zTestResult.startTestcs t|||j|_dS)zp This must be called after the given test is completed. @type test: L{pyunit.TestCase} N)r'stopTestr8r@ _lastTimerAr.rrrC{s zTestResult.stopTestcC|j|||fdS)z Report a failed assertion for the given test. @type test: L{pyunit.TestCase} @type fail: L{Failure} or L{tuple} N)r5appendr>rrBfailrrr addFailurezTestResult.addFailurecCrE)z Report an error that occurred while running the given test. @type test: L{pyunit.TestCase} @type error: L{Failure} or L{tuple} N)r4rFr>rrBr=rrraddErrorrJzTestResult.addErrorcCs|j||fdS)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)r(rF)rrBreasonrrraddSkips zTestResult.addSkipNcCs&|dur t|j}|j||fdS)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*rFrrBtodorrraddUnexpectedSuccesss zTestResult.addUnexpectedSuccesscCs(|dur t|j}|j|||fdS)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)rrOr)rF)rrBr=rQrrraddExpectedFailures zTestResult.addExpectedFailurecCs|jd7_dS)z_ Report that the given test succeeded. @type test: L{pyunit.TestCase} r9N)r+rArrr addSuccessszTestResult.addSuccesscCs$t|jt|jkodkSS)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)r3r5r4r-rrr wasSuccessfuls$ zTestResult.wasSuccessfulcCdS)z6 The test suite has finished running. Nrr-rrrdonezTestResult.doner)rrrrrOrstrr6r8r>r?rCrIrLrNrRrSrTrUrW __classcell__rrr.rr&Hs"       r&c@r)TestResultDecoratorz Base class for TestResult decorators. @ivar _originalReporter: The wrapped instance of reporter. @type _originalReporter: A provider of L{itrial.IReporter} Nrrrrrr[sr[_originalReporterc@seZdZdZddZdS)UncleanWarningsReporterWrapperze A wrapper for a reporter that converts L{util.DirtyReactorAggregateError}s to warnings. cCs:t|tr|tjrt|dS|j ||dS)z If the error is a L{util.DirtyReactorAggregateError}, instead of reporting it as a normal error, throw a warning. N) r;rcheckr DirtyReactorAggregateErrorwarningswarngetErrorMessager\rLrKrrrrLsz'UncleanWarningsReporterWrapper.addErrorN)rrrrrLrrrrr]s r]c@ eZdZdZddZddZdS) _ExitWrapperza A wrapper for a reporter that causes the reporter to stop after unsuccessful tests. cOd|_|jj|i|SNT) shouldStopr\rLrargskwargsrrrrLz_ExitWrapper.addErrorcOrerf)rgr\rIrhrrrrI rkz_ExitWrapper.addFailureN)rrrrrLrIrrrrrds rdc@sTeZdZdZddZddZdddZd d Zd d Zdd dZ ddZ ddZ dS)_AdaptedReporterz TestResult decorator that makes sure that addError only gets tests that have been adapted with a particular test adapter. cCst||||_dS)z Construct an L{_AdaptedReporter}. @param original: An {itrial.IReporter}. @param testAdapter: A callable that returns an L{itrial.ITestCase}. N)r[r testAdapter)rrrmrrrrs  z_AdaptedReporter.__init__cC||}|j||Sz* See L{itrial.IReporter}. )rmr\rLrKrrrrL z_AdaptedReporter.addErrorNcCs|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\rSrm)rrBfailurerQrrrrS%s z#_AdaptedReporter.addExpectedFailurecCrnro)rmr\rI)rrBrqrrrrI6rpz_AdaptedReporter.addFailurecCrnro)rmr\rN)rrBskiprrrrN=rpz_AdaptedReporter.addSkipcCrn)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}). )rmr\rRrPrrrrRDs z%_AdaptedReporter.addUnexpectedSuccesscC|j||Sro)r\r?rmrArrrr?Sz_AdaptedReporter.startTestcCrsro)r\rCrmrArrrrCYrtz_AdaptedReporter.stopTestr) rrrrrrLrSrIrNrRr?rCrrrrrls   rlcseZdZdZdZdZejdddffdd Zd d Z fd d Z fd dZ fddZ ddZ ddZd.fdd ZfddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-ZZS)/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===============================================================================defaultFNcsPtt||_||_||_d|_t|_||_ |dur&| |j dSdSr) r'rr_streamtbformatrealtime _startTimeset _warningCache _publisher addObserver_observeWarningsrstreamrxry publisherr.rrrws  zReporter.__init__cCsdd|vr.|d|d|dddt|df}||jvr0|j||jd|dSdSdS) 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)splitrYr|addrwr#)reventkeyrrrrs    zReporter._observeWarningscs,t||jdur||_t|_dS)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)r'r?rzr8r{r|rAr.rrr?s    zReporter.startTestcs:t|||jr|jdd}|||dSdS)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. rr9N)r'rIryr5_write_formatFailureTracebackrGr.rrrIs zReporter.addFailurecsD||}t|||jr |jdd}|||dSdS)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. rr9N)r>r'rLryr4rrrKr.rrrLs zReporter.addErrorcGsHt|}t|ts J|r|j||n|j|t|jjdS)z Safely write to the reporter's stream. @param format: A format string to write. @param args: The arguments for the format string. N)rYr;rwr#rflush)rformatrisrrrrs  zReporter._writecGs |j|g|R|ddS)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)rrrrirrr_writelnszReporter._writelnTcsNt|||||r%||}t|d||}tj|tdddSdS)Nz3caught exception in {}, your TestCase is broken {}r:) stacklevel) r' upDownErrorrrmsgrr`rar)rmethodr=ra printStatustbStrrr.rrrs  zReporter.upDownErrorcs*t|tdd||ftdS)Nz%s %sz&REACTOR UNCLEAN! traceback(s) follow: )r' cleanupErrorsr`rarrrerrsr.rrrs zReporter.cleanupErrorsc Csdt|}t|dkr |S|dd}tjtj|ddd}|dd}tjtj|ddd}d}d}||f||ff} |D]"} tjtj| dd} | dkrh| ddkrh||| qF| |krt|dd}n| |kr|d d}n ||fd kr|dd}|s|S|d } | dd rtjtj| ddd kr|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. r:rr9))_run _synctest)runWithWarningsSuppressedr )) maybeDeferreddefer)rutilscompatreraiseN) _runCallbacksrrrHr) listr3ospathsplitextbasenamepopindex startswith) rframes newFrames firstMethod firstFile secondMethod secondFilesyncCase asyncCase twoFramesframe frameFilelastrrr _trimFramess:(          zReporter._trimFramescCsFt|tr |dS||j|j|_}|j|jdd}||_|S)NrT)detailelideFrameworkCode)r;rYrstriprr getTracebackrx)rrHrresultrrrrGs  z Reporter._formatFailureTracebackcCsJt}|D]}|d}|dd}||}||g|qt|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. rr9N)r setdefaultrFritems)rresults formattergroupscontentcaseoutcomerrrr _groupResultsOs  zReporter._groupResultscCs\|||D]%\}}||j|||||d|D] }||q!qdS)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)rflavorr4rrMcasesrrrr _printResultsis    zReporter._printResultscCsd|j||S)NzReason: {!r} {})rrMr)rr=rQrrr_printExpectedFailurezs zReporter._printExpectedFailurecCs.d|jd}|jr|dd|j7}|S)NzReason: rzExpected errors: {} , )rMr4rjoin)rrQretrrr_printUnexpectedSuccesssz Reporter._printUnexpectedSuccesscCsj|d|d|jdd|d|j|j|d|j|j|d|j|j|d|j|j d S) zM Print all of the non-success results to the stream in full. r [SKIPPED]cSsd|S)N%s r)xrrrsz'Reporter._printErrors..[TODO][FAIL][ERROR] [SUCCESS!?!]N) rrr(r)rr5rr4r*rr-rrr _printErrorss  zReporter._printErrorscCshg}dD]}tt||}|r|d||fq|jr%|d|jf|r0dd|dp1d}|S)zC Return a formatted count of tests status results. )r(r)r5r4r*z%s=%dz successes=%dz (r)r)r3r rFr+r)r summariesstatnumsummaryrrr _getSummaryszReporter._getSummarycCs,|}|r d}nd}|d||dS)zJ Print a line summarising the test results to the stream. PASSEDFAILEDz%s%s N)rrUr)rrstatusrrr _printSummarys zReporter._printSummarycCsf|jdur |j|j|||j|jdur(|d|jt|j| d| dS)a Summarize the result of the test run. The summary includes a report of all of the errors, todos, skips and so forth that occurred during the run. It also includes the number of tests that were run and how long it took to run them (not including load time). Expects that C{_printErrors}, C{_writeln}, C{_write}, C{_printSummary} and C{_separator} are all implemented. NzRan %d tests in %.3fsr) r}removeObserverrrr _separatorrzr2r7rrr-rrrrWs     z Reporter.done)TT)rrrrrrsysstdoutrrr?rIrLrrrrrrrrrrrrrrWrZrrr.rru`s0     T  ruc@rc)MinimalReporterz A minimalist reporter that prints only a summary of the test result, in the form of (timeTaken, #tests, #tests, #errors, #failures, #skips). cCrV)zb Don't print a detailed summary of errors. We only care about the counts. Nrr-rrrrrXzMinimalReporter._printErrorscCs`|j}|jdur||j}nd}|||t|jt|jt|jf}|dt t |dS)z Print out a one-line summary of the form: '%(runtime) %(number_of_tests) %(number_of_tests) %(num_errors) %(num_failures) %(num_skips)' Nr ) r2rzr8r3r4r5r(rrmaprY)rnumTeststimingtrrrrs zMinimalReporter._printSummaryN)rrrrrrrrrrrs rcs\eZdZdZfddZfddZfddZfdd Zfd d Zfd d Z Z S) TextReporterz Simple reporter that prints a single character for each test as it runs, along with the standard Trial summary text. ct||ddS)Nrr'rTrrAr.rrrT zTextReporter.addSuccessctj||ddS)NEr'rLrrrir.rrrLrzTextReporter.addErrorcr)NFr'rIrrr.rrrIrzTextReporter.addFailurecr)NSr'rNrrr.rrrNrzTextReporter.addSkipcr)NTr'rSrrr.rrrSrzTextReporter.addExpectedFailurecr)N!r'rRrrr.rrrRrz!TextReporter.addUnexpectedSuccess) rrrrrTrLrIrNrSrRrZrrr.rrs     rcsteZdZdZfddZfddZfddZfdd Zfd d Zfd d Z fddZ fddZ Z S)VerboseTextReporterz A verbose reporter that prints the name of each test as it is running. Each line is printed with the name of the test, followed by the result of that test. cs |d|t|dS)Nz%s ... )rrr'r?)rtmr.rrr?szVerboseTextReporter.startTestcrNz[OK]rrAr.rrrTrzVerboseTextReporter.addSuccesscrNrrrr.rrrLrzVerboseTextReporter.addErrorcr)Nz [FAILURE]rrr.rrrI rzVerboseTextReporter.addFailurecrNrrrr.rrrN$rzVerboseTextReporter.addSkipcrNrrrr.rrrS(rz&VerboseTextReporter.addExpectedFailurecrNrrrr.rrrR,rz(VerboseTextReporter.addUnexpectedSuccesscr)Nr)r'rCrrAr.rrrC0rzVerboseTextReporter.stopTest) rrrrr?rTrLrIrNrSrRrCrZrrr.rr s      rcs eZdZdZfddZZS)TimingTextReporterze Prints out each test as it is running, followed by the time taken for each test to run. cs t||d|jdS)zm Mark the test as stopped, and write the time it took to run the test to the stream. z (%.03f secs) N)r'rCrrD)rrr.rrrC;s zTimingTextReporter.stopTest)rrrrrCrZrrr.rr 5sr c @sJeZdZdZedddddddd d Zd d Zeej fd dZ ddZ dS)_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)}.  !"#$%)blackredgreenyellowbluemagentacyanwhitecCrrrrrrrrrPrz_AnsiColorizer.__init__cCs|sdSzddl}Wn tyYdSwz z |ddkWWS|jy7||ddkYWSwtyAYdSw)z A class method that returns True if the current platform supports coloring terminal output using this method. Returns False otherwise. FrNcolorsr:)isattycurses ImportErrortigetnumr= setupterm BaseException)clsrr rrr supportedSs"   z_AnsiColorizer.supportedcCs(|j|}|jd|d|ddS)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)_colorsrr#rtextcolorrrrr#js z_AnsiColorizer.writeN) rrrrdictr'r classmethodrrr&r#rrrrr Ds r c@2eZdZdZddZeejfddZddZ dS) _Win32Colorizer' See _AnsiColorizer docstring. c Csddlm}m}m}m}m}m}||||f\}} } } ||_|||_|| B| B|| B| | B| | B|| B| B|| B| B| | B| B|| B| B| Bd|_ dS)Nr)FOREGROUND_BLUEFOREGROUND_GREENFOREGROUND_INTENSITYFOREGROUND_REDSTD_OUTPUT_HANDLE GetStdHandle)normalrrrrrrr) win32consoler0r1r2r3r4r5r screenBufferr') rrr0r1r2r3r4r5rrrboldrrrr{s"         z_Win32Colorizer.__init__cCslz ddl}||j}Wn tyYdSwddl}z||j|jB|jBWdS|j y5YdSw)NrFT) r7r5r4r! pywintypesSetConsoleTextAttributer3r1r0r=)r%rr7r8r:rrrr&s& z_Win32Colorizer.supportedcCs8|j|}|j||j||j|jddS)Nr6)r'r8r;rr#r(rrrr#s   z_Win32Colorizer.writeN rrrrrr,rrr&r#rrrrr.vs  r.c@r-) _NullColorizerr/cCrrrrrrrrrz_NullColorizer.__init__cCrVrfr)r%rrrrr&sz_NullColorizer.supportedcCs|j|dSr)rr#r(rrrr#sz_NullColorizer.writeNr<rrrrr=s  r=c@seZdZdZdZejdddfddZddZe d d Z d d Z d dZ ddZ ddZddZddZddZddZdddZdddZdS) 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 NrvFcCs$tdurtdt||_d|_dS)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 _successfulrrrrrs  zSubunitReporter.__init__cCrV)z Record that the entire test suite run is finished. We do nothing, since a summary clause is irrelevant to the subunit protocol. Nrr-rrrrWszSubunitReporter.donecCs|jjS)zK Whether or not the test runner should stop running tests. )r@rgr-rrrrgszSubunitReporter.shouldStopcCs |jS)zH Signal that the test runner should stop running tests. )r@stopr-rrrrBs zSubunitReporter.stopcCs|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. )rAr-rrrrUs zSubunitReporter.wasSuccessfulcC |j|S)z2 Record that C{test} has started. )r@r?rArrrr?  zSubunitReporter.startTestcCrC)z4 Record that C{test} has completed. )r@rCrArrrrCrDzSubunitReporter.stopTestcCrC)z5 Record that C{test} was successful. )r@rTrArrrrTrDzSubunitReporter.addSuccesscCs6t|jdd}|dur||dS|j||dS)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. rNN)r r@rTrN)rrBrMrNrrrrNs zSubunitReporter.addSkipcCd|_|j|t|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)rAr@rLr excInfoOrFailureToExcInforrBerrrrrrL,zSubunitReporter.addErrorcCrE)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)rAr@rIr rFrGrrrrI6rIzSubunitReporter.addFailurecCs<t|}t|jdd}|dur||dS|||dS)z Record an expected failure from a test. Some versions of subunit do not implement this. For those versions, we record a success. rSN)r rFr r@rT)rrBrqrQrSrrrrS@s z"SubunitReporter.addExpectedFailurecCs||dS)z Record an unexpected success. Since subunit has no way of expressing this concept, we record a success on the subunit stream. N)rTrPrrrrRNsz$SubunitReporter.addUnexpectedSuccessr)rrrrr2rrrrWpropertyrgrBrUr?rCrTrNrLrIrSrRrrrrr>s$     r>cseZdZdZdZdZdZdZdZdZ dZ dZ dZ e jffdd Zd d Zfd d ZfddZfddZfddZfddZfddZfddZddZddZfddZfd d!Zfd"d#Zfd$d%Zd&d'ZZS)( 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 OrrrcsNtj|g|Ri|g|_tttfD]}||r$|||_dSqdSr)r'r _lastTestr.r r=r& _colorizer)rrrirj colorizerr.rrrls  zTreeReporter.__init__cCs|ddS)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)rrrArrrgetDescriptiontszTreeReporter.getDescriptioncst||d|jdSr)r'rTendLineSUCCESSrAr.rrrT} zTreeReporter.addSuccessctj||d|jdSr)r'rLrQERRORrr.rrrLrSzTreeReporter.addErrorcrT)Nr)r'rIrQFAILURErr.rrrIrSzTreeReporter.addFailurecrTr)r'rNrQSKIPrr.rrrNrSzTreeReporter.addSkipcrTr)r'rSrQTODOrr.rrrSrSzTreeReporter.addExpectedFailurecrTr )r'rRrQTODONErr.rrrRrSz!TreeReporter.addUnexpectedSuccesscs$|r||}||_t|jdSr) currentLiner'rrr.rrrszTreeReporter._writecCsJ|ddd}t|dkr|Sddd|dd|dfD}|S)z Return a list of all non-leaf segments to display in the tree. Normally this is the module and class name. rNrrcSsg|] }t|dkr|qS)r)r3).0segrrr sz4TreeReporter._getPreludeSegments..)rr3r)rtestIDsegmentsrrr_getPreludeSegmentss z TreeReporter._getPreludeSegmentscCs|||}d}|D]/}|t|jkr'||j|kr&||j||dn ||j||d|d7}q ||_dS)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. rrr9N)r`r3rMrindent)rr^r_ indentLevelr\rrr _testPreludes   zTreeReporter._testPreludecs.|jd|j|d|jt|dS)Nz cleanup errorsr)rNr#rUrQr'rrr.rrrszTreeReporter.cleanupErrorscs<|jd||j|r|d|jt||||dS)Nz %sr)rNr#rUrQr'r)rrr=rarr.rrrszTreeReporter.upDownErrorcsB|||d|jt|j||ft|dS)zn Called when C{test} starts. Writes the tests name to the stream using a tree format. z %s%s ... N) rcrrrar3rMrPr'r?rAr.rrr?szTreeReporter.startTestcsFd|jt|jt|}t||j||tddS)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. rrN)columnsr3rZr'rrNr#)rmessager*spacesr.rrrQs zTreeReporter.endLinecCsD|}|rd}|j}nd}|j}|j|||d|dS)zo Print a line summarising the test results to the stream, and color the status result. rrrN)rrUrRrVrNr#r)rrrr*rrrrszTreeReporter._printSummary) rrrrrZrardrVrUrXrWrYrRrrrrPrTrLrIrNrSrRrr`rcrrr?rQrrZrrr.rrKYs6           rK).rrrr7unittestpyunitr` collectionsrzope.interfacertwisted.pythonrrtwisted.python.componentsrtwisted.python.failurertwisted.python.utilr twisted.trialr r subunitr r!rWarningrr IReporterr&r[r]rdrlrurrrr r r.r=r>rKrrrrs`         Rj"+2>