HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/trial/test/__pycache__/test_runner.cpython-38.pyc
U

�`�[��@s�ddlmZmZddlZddlZddlZddlmZddlm	Z	ddl
mZmZddl
mZmZmZmZddlmZddlmZmZmZdd	lmZdd
lmZddlmZddlmZdd
l m!Z!ddl"m#Z#ddl$m%Z%e&d�Z'Gdd�de(�Z)ee�Gdd�de(��Z*Gdd�de(�Z+Gdd�de+ej,�Z-Gdd�de+ej,�Z.Gdd�de(�Z/Gdd�de/ej,�Z0Gdd �d e/ej,�Z1Gd!d"�d"e/ej,�Z2Gd#d$�d$ej,�Z3Gd%d&�d&ej,�Z4Gd'd(�d(ej,�Z5Gd)d*�d*e5�Z6Gd+d,�d,ej7�Z8Gd-d.�d.ej,�Z9Gd/d0�d0ej,�Z:Gd1d2�d2e(�Z;Gd3d4�d4e;e:�Z<Gd5d6�d6e;e:�Z=Gd7d8�d8ej,�Z>Gd9d:�d:ej,�Z?Gd;d<�d<ej,�Z@Gd=d>�d>ej,�ZAGd?d@�d@ej,�ZBdS)A�)�absolute_import�divisionN)�implementer)�verifyObject)�	IReporter�	ITestCase)�unittest�runner�reporter�util)� _ForceGarbageCollectionDecorator)�failure�log�reflect)�FilePath��namedAny)�NativeStringIO)�trial)�
twisted_trial)�plugin)�deferrc@seZdZdd�Zdd�ZdS)�CapturingDebuggercCs
g|_dS�N)�_calls��self�r�@/usr/lib/python3/dist-packages/twisted/trial/test/test_runner.py�__init__"szCapturingDebugger.__init__cOs&|j�d�|d|dd�|�dS)N�runcallr��r�append)r�args�kwargsrrrr %szCapturingDebugger.runcallN)�__name__�
__module__�__qualname__rr rrrrr src@sVeZdZdZdZdZdZdZdZddd�Z	dd�Z
dd�Zd	d
�Zdd�Z
d
d�ZdS)�CapturingReporterzC
    Reporter that keeps a log of all actions performed on it.
    NcCs(g|_d|_||_||_||_||_dS)z.
        Create a capturing reporter.
        FN)rZ
shouldStop�_streamZ	_tbformatZ	_rterrors�
_publisher)r�stream�tbformatZrterrorsZ	publisherrrrr7szCapturingReporter.__init__cCs|j�d�dS)z�
        Report the beginning of a run of a single test method
        @param method: an object that is adaptable to ITestMethod
        �	startTestNr"�r�methodrrrr.DszCapturingReporter.startTestcCs|j�d�dS)z}
        Report the status of a single test method
        @param method: an object that is adaptable to ITestMethod
        �stopTestNr"r/rrrr1LszCapturingReporter.stopTestcCs|j�d�dS)z�called when the reactor has been left in a 'dirty' state
        @param errs: a list of L{twisted.python.failure.Failure}s
        ZcleanupErrorNr")rZerrsrrr�
cleanupErrorsTszCapturingReporter.cleanupErrorscCs|j�d�dS)N�
addSuccessr"�r�testrrrr3[szCapturingReporter.addSuccesscCsdS)z@
        Do nothing. These tests don't care about done.
        Nrrrrr�done_szCapturingReporter.done)NNNN)r&r'r(�__doc__r,r-r$�	separator�testsRunrr.r1r2r3r6rrrrr)+s�

r)c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�TrialRunnerTestsMixinz9
    Mixin defining tests for L{runner.TrialRunner}.
    cCs|j��dSr)r	�_tearDownLogFilerrrr�tearDownjszTrialRunnerTestsMixin.tearDowncCsdS)z=
        Empty test method, used by the other tests.
        Nrrrrr�
test_emptynsz TrialRunnerTestsMixin.test_emptycCstjjSr)rZtheLogPublisherZ	observersrrrr�
_getObserverstsz#TrialRunnerTestsMixin._getObserverscCs6t|���}|j�|j�t|���}|�||�dS)zn
        Any log system observers L{TrialRunner.run} adds are removed by the
        time it returns.
        N)�lenr>r	�runr5�assertEqual)rZ
originalCountZnewCountrrr�test_addObserversxsz'TrialRunnerTestsMixin.test_addObserverscsl�jj�g����fdd�}|�j_�j��j��j��j���t��d����d�dkd�dS)z=
        Test that a new file is opened on each run.
        cs�����jj�dSr)r#r	Z_logFileObserverr��lZoldSetUpLogFilerrr�setUpLogFile�szDTrialRunnerTestsMixin.test_logFileAlwaysActive.<locals>.setUpLogFile�rr!z'Should have created a new file observerN)r	�
_setUpLogFiler@r5rAr?�assertFalse�rrErrCr�test_logFileAlwaysActive�sz.TrialRunnerTestsMixin.test_logFileAlwaysActivecsV�jj�g����fdd�}|�j_�j��j���t��d����dj�dS)zB
        Test that file created is closed during the run.
        cs�����jj�dSr)r#r	Z_logFileObjectrrCrrrE�szBTrialRunnerTestsMixin.test_logFileGetsClosed.<locals>.setUpLogFiler!rN)r	rGr@r5rAr?�
assertTrue�closedrIrrCr�test_logFileGetsClosed�sz,TrialRunnerTestsMixin.test_logFileGetsClosedN)
r&r'r(r7r<r=r>rBrJrMrrrrr:fsr:c@s eZdZdZdd�Zdd�ZdS)�TrialRunnerTestszm
    Tests for L{runner.TrialRunner} with the feature to turn unclean errors
    into warnings disabled.
    cCs(t�|_tjt|jd�|_td�|_dS)N�r,r=�rr,r	�TrialRunnerr)rNr5rrrr�setUp�szTrialRunnerTests.setUpcCs|j��}|�|jt�dS)z�
        The reporter constructed by L{runner.TrialRunner} is passed
        L{twisted.python.log} as the value for the C{publisher} parameter.
        N)r	�_makeResult�assertIdenticalr+r�r�resultrrr�test_publisher�s
zTrialRunnerTests.test_publisherN)r&r'r(r7rRrWrrrrrN�srNc@seZdZdZdd�ZdS)�+TrialRunnerWithUncleanWarningsReporterTestsza
    Tests for the TrialRunner's interaction with an unclean-error suppressing
    reporter.
    cCs*t�|_tjt|jdd�|_td�|_dS)NT�r,ZuncleanWarningsr=rPrrrrrR�s

�z1TrialRunnerWithUncleanWarningsReporterTests.setUpN�r&r'r(r7rRrrrrrX�srXc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�DryRunMixinze
    Mixin for testing that 'dry run' mode works with various
    L{pyunit.TestCase} subclasses.
    cCs2g|_t�|_tjttjj|jd�|_|��dS)NrO)rrr,r	rQr)ZDRY_RUN�makeTestFixturesrrrrrR�s�zDryRunMixin.setUpcCsdS)zh
        Set C{self.test} and C{self.suite}, where C{self.suite} is an empty
        TestSuite.
        Nrrrrrr\�szDryRunMixin.makeTestFixturescCs"|j�t���}|�|jg�dS)zf
        If there are no tests, the reporter should not receive any events to
        report.
        N)r	r@�	TestSuiterArrUrrrr=�szDryRunMixin.test_emptycCs&|j�|j�}|�|jdddg�dS)z�
        If we are running a single test, check the reporter starts, passes and
        then stops the test during a dry run.
        r.r3r1N)r	r@r5rArrUrrr�test_singleCaseReporting�sz$DryRunMixin.test_singleCaseReportingcCs |j�|j�|�|jg�dS)zT
        When we are doing a dry run, the tests should not actually be run.
        N)r	r@r5rArrrrr�test_testsNotRun�szDryRunMixin.test_testsNotRunN)	r&r'r(r7rRr\r=r^r_rrrrr[�s			r[c@seZdZdZdd�ZdS)�SynchronousDryRunTestszS
    Check that 'dry run' mode works well with trial's L{SynchronousTestCase}.
    cCs*Gdd�dtj�}|d�|_t��|_dS)Nc@seZdZdd�ZdS)z;SynchronousDryRunTests.makeTestFixtures.<locals>.PyunitCasecSsdSrrrrrr�test_foo�szDSynchronousDryRunTests.makeTestFixtures.<locals>.PyunitCase.test_fooN�r&r'r(rarrrr�
PyunitCase�srcra)r�SynchronousTestCaser5�pyunitr]�suite�rrcrrrr\�s
z'SynchronousDryRunTests.makeTestFixturesN�r&r'r(r7r\rrrrr`�sr`c@seZdZdZdd�ZdS)�DryRunTestsz@
    Check that 'dry run' mode works well with Trial tests.
    cs.G�fdd�dtj�}|d��_t���_dS)NcseZdZ�fdd�ZdS)z.DryRunTests.makeTestFixtures.<locals>.MockTestcs�j�d�dS)Nra)rr#�r5rrrrasz7DryRunTests.makeTestFixtures.<locals>.MockTest.test_fooNrbrrrr�MockTest
srkra)r�TestCaser5r	r]rf)rrkrrrr\	s
zDryRunTests.makeTestFixturesNrhrrrrrisric@seZdZdZdd�ZdS)�PyUnitDryRunTestszJ
    Check that 'dry run' mode works well with stdlib unittest tests.
    cCs*Gdd�dtj�}|d�|_t��|_dS)Nc@seZdZdd�ZdS)z6PyUnitDryRunTests.makeTestFixtures.<locals>.PyunitCasecSsdSrrrrrrrasz?PyUnitDryRunTests.makeTestFixtures.<locals>.PyunitCase.test_fooNrbrrrrrcsrcra)rerlr5r]rfrgrrrr\s
z"PyUnitDryRunTests.makeTestFixturesNrhrrrrrmsrmc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Ze�Zd!d"�Zd#d$�Zd%S)&�RunnerTestscs�t���_t�t��d�}d�|dd��}|d}tj	d|ddd|d�g���fdd�}t
j�_|t
_d	d
dd	d
dd	d
dd	d
dd	d
dd	d
dd	d
dd	d
dd	d
dd	d
dg�_
dS)N�.���zTest Helper ReporterzUtility for unit testing.�	capturing)�descriptionZlongOptZshortOpt�klasscs&��|t��t�j|f|�|��Sr)rAr�list�original)Ziface�a�kw�Zpluginsrrr�
getPlugins3sz%RunnerTests.setUp.<locals>.getPluginsr.r3r1)rZOptions�configr�qualr)�split�joinrZ	_Reporterrryru�standardReport)r�parts�packagersryrrxrrR sX
��zRunnerTests.setUpcCs|jt_dSr)rurryrrrrr<FszRunnerTests.tearDowncCs|j�|�dSr)rz�parseOptions�rr$rrrr�JszRunnerTests.parseOptionscCs.t�|j�}t�|_|�|j�t��|_	|Sr)
rZ_makeRunnerrzrr,�
addCleanupr;rZLogPublisherZ_log)r�rrrr�	getRunnerNs

zRunnerTests.getRunnercCs2|�g�|jd}|��}|�||��j�dS�Nr
)r�rzr�rArS�	__class__)rrVr	rrr�test_runner_can_get_reporter_s

z(RunnerTests.test_runner_can_get_reportercCs2|�g�|��}|��}|�|j|jd�dSr�)r�r�rSrAr�rz�rr	rVrrr�test_runner_get_resultfs
z"RunnerTests.test_runner_get_resultcCs(|�g�|��}|�|��tj�dS)z�
        By default Trial sets the 'uncleanWarnings' option on the runner to
        False. This means that dirty reactor errors will be reported as
        errors. See L{test_reporter.DirtyReactorTests}.
        N)r�r�ZassertNotIsInstancerSr
�UncleanWarningsReporterWrapper�rr	rrr� test_uncleanWarningsOffByDefaultms


�z,RunnerTests.test_uncleanWarningsOffByDefaultcCs*|�dg�|��}|�|��tj�dS)z�
        Specifying '--unclean-warnings' on the trial command line will cause
        reporters to be wrapped in a device which converts unclean errors to
        warnings.  See L{test_reporter.DirtyReactorTests} for implications.
        z--unclean-warningsN)r�r��assertIsInstancerSr
r�r�rrr�test_getsUncleanWarningsys

�z$RunnerTests.test_getsUncleanWarningscCs(|�ddg�|��}|�|jd�dS)N�--temp-directoryZ	some_path)r�r�rAZworkingDirectoryr�rrr�test_runner_working_directory�sz)RunnerTests.test_runner_working_directorycs�|�g�|�tjt���t|�������t��j�|�	�}|�	��i�G����fdd�dt
j��|��d��}|j
|j}|r�|�|dd�|����d�j��d�jd��d	S)
z�
        If no working directory is explicitly specified and the default
        working directory is in use by another runner, L{TrialRunner.run}
        selects a different default working directory to use.
        cs*eZdZ����fdd�Z�fdd�ZdS)zKRunnerTests.test_concurrentImplicitWorkingDirectory.<locals>.ConcurrentCasecs<t���d<}t��j�|�tj|����d��dS)z�
                Start a second test run which will have a default working
                directory which is the same as the working directory of the
                test run already in progress.
                �
concurrent�test_secondN)�os�getcwd�chdir�pathr�r@)rZsubsequentDirectory��ConcurrentCaseZrunDirectory�secondRunner�whererr�
test_first�szVRunnerTests.test_concurrentImplicitWorkingDirectory.<locals>.ConcurrentCase.test_firstcst���d<dS)zR
                Record the working directory for later analysis.
                �recordN)r�r�r)r�rrr��szWRunnerTests.test_concurrentImplicitWorkingDirectory.<locals>.ConcurrentCase.test_secondN)r&r'r(r�r�rr�rrr��sr�r�rr!Z_trial_tempz
_trial_temp-1)r�r�N)r�r�r�r�r�r�mktemp�makedirsr�r�rrdr@�errors�failures�failrAZchild)r�firstRunnerrV�badrr�r�'test_concurrentImplicitWorkingDirectory�s&


��z3RunnerTests.test_concurrentImplicitWorkingDirectorycs�|�dtj�|���g�t��}|�tj|�|��}|���G��fdd�dt	j
��|��d��}|j|j
}|r�|�|dd�dS)z�
        If a working directory which is already in use is explicitly specified,
        L{TrialRunner.run} raises L{_WorkingDirectoryBusy}.
        r�cs"eZdZ��fdd�Zdd�ZdS)zKRunnerTests.test_concurrentExplicitWorkingDirectory.<locals>.ConcurrentCasecs|�tj�j�d��dS)z�
                Try to start another runner in the same working directory and
                assert that it raises L{_WorkingDirectoryBusy}.
                �test_failureN)ZassertRaisesrZ_WorkingDirectoryBusyr@r�r�r�rr�test_concurrent�s
�z[RunnerTests.test_concurrentExplicitWorkingDirectory.<locals>.ConcurrentCase.test_concurrentcSs|�d�dS)zE
                Should not be called, always fails.
                z$test_failure should never be called.N)r�rrrrr��szXRunnerTests.test_concurrentExplicitWorkingDirectory.<locals>.ConcurrentCase.test_failureN)r&r'r(r�r�rr�rrr��s	r�r�rr!N)r�r�r��abspathr�r�r�r�r�rrdr@r�r�r�)rZinitialDirectoryr�rVr�rr�r�'test_concurrentExplicitWorkingDirectory�sz3RunnerTests.test_concurrentExplicitWorkingDirectorycCsR|�d|��dddg�|��}t��}|�dd�}|�|�}|�|j|j	�dS)Nr��
--reporterrq�twisted.trial.test.sampleT)
r�r�r�r	�
TestLoader�
loadByNamer@rAr~r)r�	my_runner�loaderrfrVrrr�test_runner_normal�s�
zRunnerTests.test_runner_normalcCst��}|�dd�}|�|�S)Nr�T)r	r�r�r@)rr�r�rfrrr�runSampleSuite�szRunnerTests.runSampleSuitecCsT|�ddddg�|��}t�}|_|�|�}|�|j|j�|�dg|j�dS)zL
        Trial uses its debugger if the `--debug` option is passed.
        r�rq�--debugr�r N)r�r�r�debuggerr�rAr~r)rr�r�rVrrr�test_runnerDebug�s�
zRunnerTests.test_runnerDebugcs^��ddg�td�}|��d�_�fdd�}��tjd|���������	�j�dS)	zL
        Trial uses pdb if no debugger is specified by `--debugger`
        r�r�ZpdbrcFcs
d�_dS�NT��runcall_called��pdbrfrVrrrr sz=RunnerTests.test_runnerDebuggerDefaultsToPdb.<locals>.runcallr N)
r�rZtouchr��patchr��Pdbr�r�rK)rZ	pdbrcFiler rrr� test_runnerDebuggerDefaultsToPdbsz,RunnerTests.test_runnerDebuggerDefaultsToPdbcsV��ddddddg�d�_�fdd	�}��tjd
|����������j�dS)zU
        Trial uses pdb if pdb is passed explicitly to the `--debugger` arg.
        r�rq�
--debuggerr�r�r�Fcs
d�_dSr�r�r�rrrr  szGRunnerTests.test_runnerDebuggerWithExplicitlyPassedPdb.<locals>.runcallr N)r�r�r�r�r�r�r�rK)rr rrr�*test_runnerDebuggerWithExplicitlyPassedPdbs�z6RunnerTests.test_runnerDebuggerWithExplicitlyPassedPdbcCsN|�ddddddg�|��}|�|�}|�|j|j�|�dg|jj�dS)	zM
        Trial uses specified debugger if the debugger is available.
        r�rqr�z4twisted.trial.test.test_runner.RunnerTests.cdebuggerr�r�r N)r�r�r�rAr~rr�)rr�rVrrr�test_runnerDebugger,s�
zRunnerTests.test_runnerDebuggercCs.|�dg�|��}|��}|�|tj�dS)z�
        If trial was passed the C{--exitfirst} option, the constructed test
        result object is wrapped with L{reporter._ExitWrapper}.
        z--exitfirstN)r�r�rSr�r
Z_ExitWrapperr�rrr�test_exitfirst=szRunnerTests.test_exitfirstN)r&r'r(rRr<r�r�r�r�r�r�r�r�r�r�r�r�r�r�rZ	cdebuggerr�r�rrrrrns&&7#
rnc@seZdZdd�ZdS)�TrialSuiteTestscCstd�dS)Nztwisted.trial.runner.TrialSuiterrrrr�test_importsKszTrialSuiteTests.test_importsN)r&r'r(r�rrrrr�Isr�c@sFeZdZGdd�dej�Zdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
S)�UntilFailureTestsc@seZdZdZgZdd�ZdS)zUntilFailureTests.FailAfterzC
        A test case that fails when run 3 times in a row.
        cCs(|j�d�t|j�dkr$|�d�dS)N�zCount reached 3)�countr#r?r�rrrrraWsz$UntilFailureTests.FailAfter.test_fooN)r&r'r(r7r�rarrrr�	FailAfterRsr�cCs4gtj_t�d�|_t�|_tjtj	|jd�|_dS)NrarO)
r�r�r�r5rr,r	rQr
�ReporterrrrrrR]szUntilFailureTests.setUpcCs@|j�|j�}|�|jd�|�|���|�|�|�d�dS)zl
        Test that the runUntilFailure method of the runner actually fail after
        a few runs.
        r!N)r	�runUntilFailurer5rAr9rH�
wasSuccessful�_getFailuresrUrrr�test_runUntilFailuredsz&UntilFailureTests.test_runUntilFailurecCs
t|j�S)zL
        Get the number of failures that were reported to a result.
        )r?r�rUrrrr�oszUntilFailureTests._getFailurescsbg��fdd�}|�td|�|j�|j�}|�|jd�|�t��d�|��|jtfg�dS)z�
        C{runUntilFailure} doesn't decorate the tests uselessly: it does it one
        time when run starts, but not at each turn.
        cs��||f�|Sr�r#�r5Z	interface�Z	decoratedrr�decorate|sz@UntilFailureTests.test_runUntilFailureDecorate.<locals>.decorater�r!N)	r�rr	r�r5rAr9r?r�rr�rVrr�r�test_runUntilFailureDecoratevsz.UntilFailureTests.test_runUntilFailureDecoratecsrg��fdd�}|�td|�d|j_|j�|j�}|�|jd�|�t��d�|��|jt	f|jt
fg�dS)z�
        C{runUntilFailure} applies the force-gc decoration after the standard
        L{ITestCase} decoration, but only one time.
        cs��||f�|Srr�r�r�rrr��szGUntilFailureTests.test_runUntilFailureForceGCDecorate.<locals>.decorater�Tr!rFN)r�rr	Z_forceGarbageCollectionr�r5rAr9r?rrr�rr�r�#test_runUntilFailureForceGCDecorate�s��z5UntilFailureTests.test_runUntilFailureForceGCDecorateN)r&r'r(rerlr�rRr�r�r�r�rrrrr�Qsr�c@s eZdZdZdd�Zdd�ZdS)�UncleanUntilFailureTestszh
    Test that the run-until-failure feature works correctly with the unclean
    error suppressor.
    cCs$t�|�tjtj|jdd�|_dS)NTrY)r�rRr	rQr
r�r,rrrrrR�s
�zUncleanUntilFailureTests.setUpcCst|jj�S)z�
        Get the number of failures that were reported to a result that
        is wrapped in an UncleanFailureWrapper.
        )r?Z_originalReporterr�rUrrrr��sz%UncleanUntilFailureTests._getFailuresN)r&r'r(r7rRr�rrrrr��sr�c@seZdZdZdd�ZdS)�
BreakingSuitez;
    A L{TestSuite} that logs an error when it is run.
    cCs4ztd��Wn"tk
r.t�t���YnXdS)Nz#error that occurs outside of a test)�RuntimeErrorr�errr
�FailurerUrrrr@�szBreakingSuite.runN)r&r'r(r7r@rrrrr��sr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�LoggedErrorsTestsa

    It is possible for an error generated by a test to be logged I{outside} of
    any test. The log observers constructed by L{TestCase} won't catch these
    errors. Here we try to generate such errors and ensure they are reported to
    a L{TestResult} object.
    cCs|�t�dSr)ZflushLoggedErrorsr�rrrrr<�szLoggedErrorsTests.tearDowncCst��}|�|��d�dS)zg
        Check that we can construct a L{runner.LoggedSuite} and that it
        starts empty.
        rN)r	�LoggedSuiterA�countTestCases)rrfrrr�test_construct�sz LoggedErrorsTests.test_constructcCslt��}t�t�g�}|�|�|�t|j�d�|�|jdd�	�tj
�|�|jdd�t
��dS)zU
        Chek that a L{LoggedSuite} reports any logged errors to its result.
        r!rN)r
�
TestResultr	r�r�r@rAr?r��idZNOT_IN_TESTrKZcheckr�)rrVrfrrr�test_capturesError�s
z$LoggedErrorsTests.test_capturesErrorN)r&r'r(r7r<r�r�rrrrr��s	r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestHolderTestscCsd|_t�|j�|_dS�Nrr)rrr	Z
TestHolder�holderrrrrrR�szTestHolderTests.setUpcCs,|�|j��|j�|�|j��|j�dS)z�
        Check that L{runner.TestHolder} takes a description as a parameter
        and that this description is returned by the C{id} and
        C{shortDescription} methods.
        N)rAr�r�rrZshortDescriptionrrrr�test_holder�szTestHolderTests.test_holdercCs6|�|jt|j��|�tt|j�d|jtf�dS)z?
        L{runner.TestHolder} implements L{ITestCase}.
        z5%r claims to provide %r but does not do so correctly.N)rTr�rrKrrrrr�test_holderImplementsITestCase�s
��z.TestHolderTests.test_holderImplementsITestCasecCs4t��}|j�|�|�|���|�d|j�dS)zc
        A L{runner.TestHolder} can run against the standard Python
        C{TestResult}.
        r!N)rer�r�r@rKr�rAr9rUrrr�test_runsWithStandardResult�sz+TestHolderTests.test_runsWithStandardResultN)r&r'r(rRr�r�r�rrrrr��s
r�c@sPeZdZdZed�ZGdd�de�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�ZdS)�ErrorHolderTestsMixinaa
    This mixin defines test methods which can be applied to a
    L{runner.ErrorHolder} constructed with either a L{Failure} or a
    C{exc_info}-style tuple.

    Subclass this and implement C{setUp} to create C{self.holder} referring to a
    L{runner.ErrorHolder} instance and C{self.error} referring to a L{Failure}
    which the holder holds.
    z"integer division or modulo by zeroc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)z$ErrorHolderTestsMixin.TestResultStubz)
        Stub for L{TestResult}.
        cCs
g|_dSr)r�rrrrrsz-ErrorHolderTestsMixin.TestResultStub.__init__cCsdSrrr4rrrr.sz.ErrorHolderTestsMixin.TestResultStub.startTestcCsdSrrr4rrrr1sz-ErrorHolderTestsMixin.TestResultStub.stopTestcCs|j�||f�dSr)r�r#)rr5�errorrrr�addError sz-ErrorHolderTestsMixin.TestResultStub.addErrorN)r&r'r(r7rr.r1r�rrrr�TestResultStubs
r�cCs4t��}|j�|�|�|���|�d|j�dS)zd
        A L{runner.ErrorHolder} can run against the standard Python
        C{TestResult}.
        r!N)rer�r�r@rHr�rAr9rUrrrr�$sz1ErrorHolderTestsMixin.test_runsWithStandardResultcCs<|j�|j�|�|jj|j|jj|jj|jjffg�dS)zM
        L{runner.ErrorHolder} adds an error to the result when run.
        N)	r�r@rVrAr�r��type�value�tbrrrr�test_run/s
�zErrorHolderTestsMixin.test_runcCs:|�|j�|�|jj|j|jj|jj|jjffg�dS)zP
        L{runner.ErrorHolder} adds an error to the result when called.
        N)r�rVrAr�r�r�r�r�rrrr�	test_call9s
�zErrorHolderTestsMixin.test_callcCs|�|j��d�dS)zH
        L{runner.ErrorHolder.countTestCases} always returns 0.
        rN)rAr�r�rrrr�test_countTestCasesCsz)ErrorHolderTestsMixin.test_countTestCasescCs,d�t|jjd��}|�t|j�|�dS)zh
        L{runner.ErrorHolder.__repr__} returns a string describing the error it
        holds.
        z0<ErrorHolder description='description' error={}>r!N)�format�reprr�r�rA)rZexpectedrrr�	test_reprJs
��zErrorHolderTestsMixin.test_reprN)
r&r'r(r7�ZeroDivisionError�exceptionForTests�objectr�r�r�r�r�r�rrrrr�s	

r�c@seZdZdZdd�ZdS)�FailureHoldingErrorHolderTestsz�
    Tests for L{runner.ErrorHolder} behaving similarly to L{runner.TestHolder}
    when constructed with a L{Failure} representing its error.
    cCsPd|_z
|j�Wntk
r.t��|_YnXt�|j|j�|_|�	�|_
dSr�)rrr�r�r
r�r�r	�ErrorHolderr�r�rVrrrrrR]s
z$FailureHoldingErrorHolderTests.setUpNrZrrrrr�Xsr�c@seZdZdZdd�ZdS)�ExcInfoHoldingErrorHolderTestsz�
    Tests for L{runner.ErrorHolder} behaving similarly to L{runner.TestHolder}
    when constructed with a C{exc_info}-style tuple representing its error.
    cCsVd|_z
|j�Wn&tk
r6t��}t��|_YnXt�	|j|�|_
|��|_dSr�)
rrr�r��sys�exc_infor
r�r�r	r�r�r�rV)rZ
exceptionInforrrrRns
z$ExcInfoHoldingErrorHolderTests.setUpNrZrrrrr�isr�c@sBeZdZdZGdd�dej�Zdd�Zdd�Zdd	�Z	d
d�Z
dS)
�MalformedMethodTestszR
    Test that trial manages when test methods don't have correct signatures.
    c@s*eZdZdZdd�Zdd�Ze�e�ZdS)z%MalformedMethodTests.ContainMalformedzV
        This TestCase holds malformed test methods that trial should handle.
        cCsdSrr)rZblahrrrra�sz.MalformedMethodTests.ContainMalformed.test_foocCsdSrrrrrr�test_bar�sz.MalformedMethodTests.ContainMalformed.test_barN)	r&r'r(r7rar�rZinlineCallbacks�	test_spamrrrr�ContainMalformedsr�cCs\t�}tjtj|d�}t�|�}|�|�}|�|j	d�|�
|���|�t|j
�d�dS)zL
        Wrapper for one of the test method of L{ContainMalformed}.
        rOr!N)rr	rQr
r�r�r�r@rAr9rHr�r?r�)rr0r,�trialRunnerr5rVrrr�_test�s

zMalformedMethodTests._testcCs|�d�dS)zE
        Test when the method has extra (useless) arguments.
        raN�rrrrr�
test_extraArg�sz"MalformedMethodTests.test_extraArgcCs|�d�dS)zJ
        Test when the method doesn't have even self as argument.
        r�Nrrrrr�
test_noArg�szMalformedMethodTests.test_noArgcCs|�d�dS)z5
        Test a decorated method also fails.
        r�Nrrrrr�test_decorated�sz#MalformedMethodTests.test_decoratedN)r&r'r(r7rerlr�rrrrrrrrr�{s
r�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�DestructiveTestSuiteTestsz2
    Test for L{runner.DestructiveTestSuite}.
    csng�G�fdd�dtj�}|d�}t��}t�|g�}|��g�|�|�|��dg�|�|��d�dS)zL
        Thes destructive test suite should run the tests normally.
        cseZdZ�fdd�ZdS)z6DestructiveTestSuiteTests.test_basic.<locals>.MockTestcs��d�dSr�r�rj�Zcalledrrra�sz?DestructiveTestSuiteTests.test_basic.<locals>.MockTest.test_fooNrbrrrrrk�srkraTrN)	rerlr
r�r	�DestructiveTestSuiterAr@r��rrkr5rVrfrrr�
test_basic�s
z$DestructiveTestSuiteTests.test_basiccstg�G�fdd�dtj�}t��}t��}tj|_|�|�}|�	�g�|�
|�|�	�dg�|�	|��d�dS)zu
        Test the C{shouldStop} management: raising a C{KeyboardInterrupt} must
        interrupt the suite.
        cs,eZdZ�fdd�Zdd�Z�fdd�ZdS)z;DestructiveTestSuiteTests.test_shouldStop.<locals>.MockTestcs��d�dS)Nr!r�rjrrr�	test_foo1�szEDestructiveTestSuiteTests.test_shouldStop.<locals>.MockTest.test_foo1cSs
t��dSr)�KeyboardInterruptrjrrr�	test_foo2�szEDestructiveTestSuiteTests.test_shouldStop.<locals>.MockTest.test_foo2cs��d�dS)NrFr�rjrrr�	test_foo3�szEDestructiveTestSuiteTests.test_shouldStop.<locals>.MockTest.test_foo3N)r&r'r(r
rr
rrrrrk�srkr!N)rrlr
r�r	r�rZsuiteFactoryZ	loadClassrAr@r�)rrkrVr�rfrrr�test_shouldStop�s

z)DestructiveTestSuiteTests.test_shouldStopcCs\Gdd�dtj�}|d�}t��}t�|g�}|�|��d�|�|�|�|��d�dS)zn
        Checks that the test suite cleanups its tests during the run, so that
        it ends empty.
        c@seZdZdd�ZdS)z8DestructiveTestSuiteTests.test_cleanup.<locals>.MockTestcSsdSrrrjrrrra�szADestructiveTestSuiteTests.test_cleanup.<locals>.MockTest.test_fooNrbrrrrrk�srkrar!rN)	rerlr
r�r	rrAr�r@rrrr�test_cleanup�s
z&DestructiveTestSuiteTests.test_cleanupN)r&r'r(r7r	rrrrrrr�src@s&eZdZGdd�dej�Zdd�ZdS)�RunnerDeprecationTestsc@s<eZdZdZdZdZdZdd�Zdd�Zdd�Z	d	d
�Z
dS)z#RunnerDeprecationTests.FakeReporterz�
        Fake reporter that does *not* implement done() but *does* implement
        printErrors, separator, printSummary, stream, write and writeln
        without deprecations.
        NcGsdSrrr�rrr�printErrors�sz/RunnerDeprecationTests.FakeReporter.printErrorscGsdSrrr�rrr�printSummary�sz0RunnerDeprecationTests.FakeReporter.printSummarycGsdSrrr�rrr�write�sz)RunnerDeprecationTests.FakeReporter.writecGsdSrrr�rrr�writeln�sz+RunnerDeprecationTests.FakeReporter.writeln)r&r'r(r7r6r8r,rrrrrrrr�FakeReporter�srcs�t�d��|����fdd��_�fdd�}|�|�|jg�}|�|ddt�|�|ddd	t�	�j
��|�t�
|dd
��|�t|�d�dS)zk
        The runner emits a warning if it is using a result that doesn't
        implement 'done'.
        Ncs�Srrr)rVrr�<lambda>	�zBRunnerDeprecationTests.test_reporterDeprecations.<locals>.<lambda>cs��t�d��dS)Nr�)r@rerlr)r�rr�f
sz;RunnerDeprecationTests.test_reporterDeprecations.<locals>.fr�category�messagezR%s should implement done() but doesn't. Falling back to printErrors() and friends.�filenamer!)r	rQrrSZ
flushWarnings�test_reporterDeprecationsrA�DeprecationWarningrr{r�rK�__file__�
startswithr?)rr�warningsr)rVr�rrs

��z0RunnerDeprecationTests.test_reporterDeprecationsN)r&r'r(r
r�rrrrrrr�src@seZdZdZdd�ZdS)�QualifiedNameWalkerTestsz<
    Tests for L{twisted.trial.runner._qualNameWalker}.
    cCs6tt�d��}|�|dgfddgfdddgfg�dS)z�
        C{_qualNameWalker} is a generator that, when given a Python qualified
        name, yields that name, and then the parent of that name, and so forth,
        along with a list of the tried components, in a 2-tuple.
        zwalker.texas.rangerzwalker.texasZrangerZwalkerZtexasN)rtr	Z_qualNameWalkerrA)rZ
walkerResultsrrr�test_walksDownPath s
��z+QualifiedNameWalkerTests.test_walksDownPathN)r&r'r(r7r"rrrrr!sr!c@seZdZdZdd�ZdS)�TrialMainDoesNothingTestszl
    Importing L{twisted.trial.__main__} will not run the script
    unless it is actually C{__main__}.
    cCstd�dS)zO
        If we import L{twisted.trial.__main__}, it should do nothing.
        ztwisted.trial.__main__N)�
__import__rrrr�test_importDoesNothing4sz0TrialMainDoesNothingTests.test_importDoesNothingN)r&r'r(r7r%rrrrr#/sr#)CZ
__future__rrr�r�r�Zzope.interfacerZzope.interface.verifyrZtwisted.trial.itrialrrZ
twisted.trialrr	r
rZtwisted.trial._asyncrunnerrZtwisted.pythonr
rrZtwisted.python.filepathrZtwisted.python.reflectrZtwisted.python.compatrZtwisted.scriptsrZtwisted.pluginsrZtwistedrZtwisted.internetrr$rer�rr)r:rdrNrXr[r`rirmrnr�r�r�r]r�r�r�r�r�r�r�rrr!r#rrrr�<module>s\:=�1


,K
"(Q.?3