U
    ¹~Hjÿ}  ã                   @   s�  d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZmZmZ d d
lmZ d dlmZ d dlmZ d dlmZmZmZm Z  d dl!m"Z" d dl#m$Z$m%Z% G dd„ dƒZ&e
e$ƒG dd„ dƒƒZ'G dd„ dƒZ(G dd„ de(ej)ƒZ*G dd„ de(ej)ƒZ+G dd„ dƒZ,G dd„ de,ej)ƒZ-G dd„ de,ej)ƒZ.G d d!„ d!e,ej)ƒZ/G d"d#„ d#ej)ƒZ0G d$d%„ d%ej)ƒZ1G d&d'„ d'ej)ƒZ2G d(d)„ d)e2ƒZ3G d*d+„ d+ej4ƒZ5G d,d-„ d-ej)ƒZ6G d.d/„ d/ej)ƒZ7G d0d1„ d1ƒZ8G d2d3„ d3e8e7ƒZ9G d4d5„ d5e8e7ƒZ:G d6d7„ d7ej)ƒZ;G d8d9„ d9ej)ƒZ<G d:d;„ d;ej)ƒZ=G d<d=„ d=ej)ƒZ>G d>d?„ d?ej)ƒZ?dS )@é    N)ÚStringIO)ÚList)Úimplementer)ÚverifyObject)Úplugin)Údefer)Útwisted_trial)ÚfailureÚlogÚreflect)ÚFilePath©ÚnamedAny)Útrial)ÚreporterÚrunnerÚunittestÚutil)Ú _ForceGarbageCollectionDecorator)Ú	IReporterÚ	ITestCasec                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚCapturingDebuggerc                 C   s
   g | _ d S ©N)Ú_calls©Úself© r   úB/tmp/pip-unpacked-wheel-ewod1tgb/twisted/trial/test/test_runner.pyÚ__init__   s    zCapturingDebugger.__init__c                 O   s&   | j  d¡ |d |dd … |Ž d S )NÚruncallr   é   ©r   Úappend)r   ÚargsÚkwargsr   r   r   r   "   s    zCapturingDebugger.runcallN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r      s   r   c                   @   sŠ   e Zd ZdZdZdZdZdZdZddd„Z	dd„ Z
dd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zddd„Zddd„Zdd„ Zdd„ ZdS )ÚCapturingReporterzC
    Reporter that keeps a log of all actions performed on it.
    Nc                 C   s(   g | _ d| _|| _|| _|| _|| _dS )z.
        Create a capturing reporter.
        FN)r   Z
shouldStopÚ_streamZ	_tbformatZ	_rterrorsÚ
_publisher)r   ÚstreamÚtbformatZrterrorsZ	publisherr   r   r   r   3   s    zCapturingReporter.__init__c                 C   s   | j  d¡ dS )z‰
        Report the beginning of a run of a single test method
        @param method: an object that is adaptable to ITestMethod
        Ú	startTestNr!   ©r   Úmethodr   r   r   r-   >   s    zCapturingReporter.startTestc                 C   s   | j  d¡ dS )z}
        Report the status of a single test method
        @param method: an object that is adaptable to ITestMethod
        ÚstopTestNr!   r.   r   r   r   r0   E   s    zCapturingReporter.stopTestc                 C   s   | j  d¡ dS )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!   )r   Zerrsr   r   r   ÚcleanupErrorsL   s    zCapturingReporter.cleanupErrorsc                 C   s   | j  d¡ d S )NÚ
addSuccessr!   ©r   Útestr   r   r   r2   R   s    zCapturingReporter.addSuccessc                 C   s   dS )z@
        Do nothing. These tests don't care about done.
        Nr   r   r   r   r   ÚdoneU   s    zCapturingReporter.donec                 C   s   dS )zD
        Do nothing. These tests don't care about addError.
        Nr   ©r   r4   Úerrorr   r   r   ÚaddErrorZ   s    zCapturingReporter.addErrorc                 C   s   dS )zF
        Do nothing. These tests don't care about addFailure.
        Nr   )r   r4   r	   r   r   r   Ú
addFailure_   s    zCapturingReporter.addFailurec                 C   s   dS )zN
        Do nothing. These tests don't care about addExpectedFailure.
        Nr   )r   r4   r	   Útodor   r   r   ÚaddExpectedFailured   s    z$CapturingReporter.addExpectedFailurec                 C   s   dS )zP
        Do nothing. These tests don't care about addUnexpectedSuccess.
        Nr   )r   r4   r:   r   r   r   ÚaddUnexpectedSuccessi   s    z&CapturingReporter.addUnexpectedSuccessc                 C   s   dS )zC
        Do nothing. These tests don't care about addSkip.
        Nr   )r   r4   Úreasonr   r   r   ÚaddSkipn   s    zCapturingReporter.addSkipc                 C   s   dS )zI
        Do nothing. These tests don't care about wasSuccessful.
        Nr   r   r   r   r   ÚwasSuccessfuls   s    zCapturingReporter.wasSuccessful)NNNN)N)N)r%   r&   r'   Ú__doc__r+   r,   r#   Ú	separatorÚtestsRunr   r-   r0   r1   r2   r5   r8   r9   r;   r<   r>   r?   r   r   r   r   r(   '   s$   


r(   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚTrialRunnerTestsMixinz9
    Mixin defining tests for L{runner.TrialRunner}.
    c                 C   s   dS )z=
        Empty test method, used by the other tests.
        Nr   r   r   r   r   Ú
test_empty~   s    z TrialRunnerTestsMixin.test_emptyc                 C   s   t jjS r   )r
   ZtheLogPublisherZ	observersr   r   r   r   Ú_getObserversƒ   s    z#TrialRunnerTestsMixin._getObserversc                 C   s6   t |  ¡ ƒ}| j | j¡ t |  ¡ ƒ}|  ||¡ dS )zn
        Any log system observers L{TrialRunner.run} adds are removed by the
        time it returns.
        N)ÚlenrE   r   Úrunr4   ÚassertEqual)r   ZoriginalCountZnewCountr   r   r   Útest_addObservers†   s    z'TrialRunnerTestsMixin.test_addObserversc                 C   sT   t | jjƒ | jj¡}tdƒD ]0}| j | j¡ | ¡  |  	| 
¡ ¡ | ¡  qdS )z=
        Test that a new file is opened on each run.
        é   N)r   r   ÚworkingDirectoryÚchildÚlogfileÚrangerG   r4   ZrestatÚ
assertTrueÚexistsÚremove)r   ZlogPathÚir   r   r   Útest_logFileAlwaysActive�   s    z.TrialRunnerTestsMixin.test_logFileAlwaysActiveN)r%   r&   r'   r@   rD   rE   rI   rS   r   r   r   r   rC   y   s
   
rC   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTrialRunnerTestszm
    Tests for L{runner.TrialRunner} with the feature to turn unclean errors
    into warnings disabled.
    c                 C   s(   t ƒ | _tjt| jd�| _tdƒ| _d S )N©r+   rD   ©r   r+   r   ÚTrialRunnerr(   rT   r4   r   r   r   r   ÚsetUp¥   s    zTrialRunnerTests.setUpc                 C   s   | j  ¡ }|  |jt¡ dS )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   Úresultr   r   r   Útest_publisherª   s    
zTrialRunnerTests.test_publisherN)r%   r&   r'   r@   rX   r]   r   r   r   r   rT   Ÿ   s   rT   c                   @   s   e Zd ZdZdd„ ZdS )Ú+TrialRunnerWithUncleanWarningsReporterTestsza
    Tests for the TrialRunner's interaction with an unclean-error suppressing
    reporter.
    c                 C   s*   t ƒ | _tjt| jdd�| _tdƒ| _d S )NT©r+   ZuncleanWarningsrD   rV   r   r   r   r   rX   »   s      ÿz1TrialRunnerWithUncleanWarningsReporterTests.setUpN©r%   r&   r'   r@   rX   r   r   r   r   r^   ³   s   r^   c                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚDryRunMixinze
    Mixin for testing that 'dry run' mode works with various
    L{pyunit.TestCase} subclasses.
    c                 C   s2   g | _ tƒ | _tjttjj| jd�| _|  ¡  d S )NrU   )r
   r   r+   r   rW   r(   ZDRY_RUNÚmakeTestFixturesr   r   r   r   rX   É   s      ÿzDryRunMixin.setUpc                 C   s   dS )zh
        Set C{self.test} and C{self.suite}, where C{self.suite} is an empty
        TestSuite.
        Nr   r   r   r   r   rb   Ñ   s    zDryRunMixin.makeTestFixturesc                 C   s"   | j  t  ¡ ¡}|  |jg ¡ dS )zf
        If there are no tests, the reporter should not receive any events to
        report.
        N)r   rG   Ú	TestSuiterH   r   r[   r   r   r   rD   ×   s    zDryRunMixin.test_emptyc                 C   s&   | j  | j¡}|  |jdddg¡ dS )z†
        If we are running a single test, check the reporter starts, passes and
        then stops the test during a dry run.
        r-   r2   r0   N)r   rG   r4   rH   r   r[   r   r   r   Útest_singleCaseReportingß   s    z$DryRunMixin.test_singleCaseReportingc                 C   s    | j  | j¡ |  | jg ¡ dS )zT
        When we are doing a dry run, the tests should not actually be run.
        N)r   rG   r4   rH   r
   r   r   r   r   Útest_testsNotRunç   s    zDryRunMixin.test_testsNotRunN)	r%   r&   r'   r@   rX   rb   rD   rd   re   r   r   r   r   ra   Ã   s   ra   c                   @   s   e Zd ZdZdd„ ZdS )ÚSynchronousDryRunTestszS
    Check that 'dry run' mode works well with trial's L{SynchronousTestCase}.
    c                 C   s*   G dd„ dt jƒ}|dƒ| _t ¡ | _d S )Nc                   @   s   e Zd Zdd„ ZdS )z;SynchronousDryRunTests.makeTestFixtures.<locals>.PyunitCasec                 S   s   d S r   r   r   r   r   r   Útest_fooö   s    zDSynchronousDryRunTests.makeTestFixtures.<locals>.PyunitCase.test_fooN©r%   r&   r'   rg   r   r   r   r   Ú
PyunitCaseõ   s   ri   rg   )r   ÚSynchronousTestCaser4   Úpyunitrc   Úsuite©r   ri   r   r   r   rb   ô   s    
z'SynchronousDryRunTests.makeTestFixturesN©r%   r&   r'   r@   rb   r   r   r   r   rf   ï   s   rf   c                   @   s   e Zd ZdZdd„ ZdS )ÚDryRunTestsz@
    Check that 'dry run' mode works well with Trial tests.
    c                    s.   G ‡ fdd„dt jƒ}|dƒˆ _t ¡ ˆ _d S )Nc                       s   e Zd Z‡ fdd„ZdS )z.DryRunTests.makeTestFixtures.<locals>.MockTestc                    s   ˆ j  d¡ d S )Nrg   )r
   r"   ©r4   r   r   r   rg     s    z7DryRunTests.makeTestFixtures.<locals>.MockTest.test_fooNrh   r   r   r   r   ÚMockTest  s   rq   rg   )r   ÚTestCaser4   r   rc   rl   )r   rq   r   r   r   rb     s    
zDryRunTests.makeTestFixturesNrn   r   r   r   r   ro   ý   s   ro   c                   @   s   e Zd ZdZdd„ ZdS )ÚPyUnitDryRunTestszJ
    Check that 'dry run' mode works well with stdlib unittest tests.
    c                 C   s*   G dd„ dt jƒ}|dƒ| _t  ¡ | _d S )Nc                   @   s   e Zd Zdd„ ZdS )z6PyUnitDryRunTests.makeTestFixtures.<locals>.PyunitCasec                 S   s   d S r   r   r   r   r   r   rg     s    z?PyUnitDryRunTests.makeTestFixtures.<locals>.PyunitCase.test_fooNrh   r   r   r   r   ri     s   ri   rg   )rk   rr   r4   rc   rl   rm   r   r   r   rb     s    
z"PyUnitDryRunTests.makeTestFixturesNrn   r   r   r   r   rs     s   rs   c                   @   s¢   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zeƒ Zd!d"„ Zd#d$„ Zd%S )&ÚRunnerTestsc                    s|   t  ¡ ˆ_t t¡ d¡}d |d d… ¡}|d }tj	d|ddd |d�g‰ ‡ ‡fdd„}t
jˆ_|t
_d	d
dgd ˆ_d S )NÚ.éÿÿÿÿzTest Helper ReporterzUtility for unit testing.Ú	capturing)ÚdescriptionZlongOptZshortOptÚklassc                    s&   ˆ  | t¡ ˆ tˆj| f|ž|Žƒ S r   )rH   r   ÚlistÚoriginal)ZifaceÚaÚkw©Zpluginsr   r   r   Ú
getPlugins/  s    z%RunnerTests.setUp.<locals>.getPluginsr-   r2   r0   é
   )r   ÚOptionsÚconfigr   Zqualr(   ÚsplitÚjoinr   Z	_Reporterr   r   r{   ÚstandardReport)r   ÚpartsÚpackagery   r   r   r~   r   rX     s"    
úÿzRunnerTests.setUpc                 C   s   | j t_d S r   )r{   r   r   r   r   r   r   ÚtearDown;  s    zRunnerTests.tearDownc                 C   s   | j  |¡ d S r   )r‚   ÚparseOptions©r   r#   r   r   r   r‰   >  s    zRunnerTests.parseOptionsc                 C   s   t  | j¡}tƒ |_|S r   )r   Z_makeRunnerr‚   r   r+   )r   Úrr   r   r   Ú	getRunnerA  s    zRunnerTests.getRunnerc                 C   s2   |   g ¡ | jd }|  ¡ }|  || ¡ j¡ d S ©Nr   )r‰   r‚   rŒ   rH   rY   Ú	__class__)r   r\   r   r   r   r   Útest_runner_can_get_reporterF  s    

z(RunnerTests.test_runner_can_get_reporterc                 C   s2   |   g ¡ |  ¡ }| ¡ }|  |j| jd ¡ d S r�   )r‰   rŒ   rY   rH   rŽ   r‚   ©r   r   r\   r   r   r   Útest_runner_get_resultL  s    
z"RunnerTests.test_runner_get_resultc                 C   s(   |   g ¡ |  ¡ }|  | ¡ tj¡ dS )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Œ   ZassertNotIsInstancerY   r   ÚUncleanWarningsReporterWrapper©r   r   r   r   r   Ú test_uncleanWarningsOffByDefaultR  s    
 ÿz,RunnerTests.test_uncleanWarningsOffByDefaultc                 C   s*   |   dg¡ |  ¡ }|  | ¡ tj¡ dS )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Œ   ÚassertIsInstancerY   r   r’   r“   r   r   r   Útest_getsUncleanWarnings^  s     ÿz$RunnerTests.test_getsUncleanWarningsc                 C   s(   |   ddg¡ |  ¡ }|  |jd¡ d S )Nú--temp-directoryZ	some_path)r‰   rŒ   rH   rK   r“   r   r   r   Útest_runner_working_directoryj  s    z)RunnerTests.test_runner_working_directoryc                    sÂ   |   g ¡ |  tjt ¡ ¡ t|  ¡ ƒ‰ˆ ¡  t ˆj¡ |  	¡ }|  	¡ ‰i ‰G ‡ ‡‡‡fdd„dt
jƒ‰ | ˆ dƒ¡}|j|j }|rœ|  |d d ¡ |  ˆˆ d¡jˆ d¡jdœ¡ 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.
        c                       s*   e Zd Z‡ ‡‡‡fdd„Z‡fdd„ZdS )zKRunnerTests.test_concurrentImplicitWorkingDirectory.<locals>.ConcurrentCasec                    s<   t  ¡  ˆd< }t  ˆj¡ |  t j|¡ ˆ ˆ dƒ¡ dS )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ÚpathÚ
addCleanuprG   )r   ZsubsequentDirectory©ÚConcurrentCaseZrunDirectoryÚsecondRunnerÚwherer   r   Ú
test_firstˆ  s    zVRunnerTests.test_concurrentImplicitWorkingDirectory.<locals>.ConcurrentCase.test_firstc                    s   t  ¡ ˆ d< dS )zR
                Record the working directory for later analysis.
                ÚrecordN)r›   rœ   r   )r£   r   r   rš   –  s    zWRunnerTests.test_concurrentImplicitWorkingDirectory.<locals>.ConcurrentCase.test_secondN)r%   r&   r'   r¤   rš   r   r    r   r   r¡   ‡  s   r¡   r¤   r   r    Z_trial_tempz_trial_temp-1)r™   r¥   N)r‰   rŸ   r›   r�   rœ   r   ÚmktempÚmakedirsrž   rŒ   r   rj   rG   ÚerrorsÚfailuresÚfailrH   rL   )r   ÚfirstRunnerr\   Úbadr   r    r   Ú'test_concurrentImplicitWorkingDirectoryo  s&    


þþz3RunnerTests.test_concurrentImplicitWorkingDirectoryc                    sŒ   |   dtj |  ¡ ¡g¡ t ¡ }|  tj|¡ |  ¡ }|  ¡ ‰G ‡ ‡fdd„dt	j
ƒ‰ | ˆ dƒ¡}|j|j }|rˆ|  |d d ¡ dS )z•
        If a working directory which is already in use is explicitly specified,
        L{TrialRunner.run} raises L{_WorkingDirectoryBusy}.
        r—   c                       s"   e Zd Z‡ ‡fdd„Zdd„ ZdS )zKRunnerTests.test_concurrentExplicitWorkingDirectory.<locals>.ConcurrentCasec                    s   |   tjˆjˆ dƒ¡ dS )zŸ
                Try to start another runner in the same working directory and
                assert that it raises L{_WorkingDirectoryBusy}.
                Útest_failureN)ÚassertRaisesr   Z_WorkingDirectoryBusyrG   r   ©r¡   r¢   r   r   Útest_concurrent¶  s
    ýz[RunnerTests.test_concurrentExplicitWorkingDirectory.<locals>.ConcurrentCase.test_concurrentc                 S   s   |   d¡ dS )zE
                Should not be called, always fails.
                z$test_failure should never be called.N)rª   r   r   r   r   r®   Á  s    zXRunnerTests.test_concurrentExplicitWorkingDirectory.<locals>.ConcurrentCase.test_failureN)r%   r&   r'   r±   r®   r   r°   r   r   r¡   µ  s   r¡   r±   r   r    N)r‰   r›   rž   Úabspathr¦   rœ   rŸ   r�   rŒ   r   rj   rG   r¨   r©   rª   )r   ZinitialDirectoryr«   r\   r¬   r   r°   r   Ú'test_concurrentExplicitWorkingDirectory¨  s    z3RunnerTests.test_concurrentExplicitWorkingDirectoryc                 C   sR   |   d|  ¡ dddg¡ |  ¡ }t ¡ }| dd¡}| |¡}|  | j|j	¡ d S )Nr—   ú
--reporterrw   útwisted.trial.test.sampleT)
r‰   r¦   rŒ   r   Ú
TestLoaderÚ
loadByNamerG   rH   r…   r   )r   Ú	my_runnerÚloaderrl   r\   r   r   r   Útest_runner_normalÌ  s    ûÿ	
zRunnerTests.test_runner_normalc                 C   s   t  ¡ }| dd¡}| |¡S )Nrµ   T)r   r¶   r·   rG   )r   r¸   r¹   rl   r   r   r   ÚrunSampleSuiteÜ  s    zRunnerTests.runSampleSuitec                 C   sT   |   ddddg¡ |  ¡ }tƒ  }|_|  |¡}|  | j|j¡ |  dg|j¡ dS )zL
        Trial uses its debugger if the `--debug` option is passed.
        r´   rw   ú--debugrµ   r   N)r‰   rŒ   r   Údebuggerr»   rH   r…   r   )r   r¸   r½   r\   r   r   r   Útest_runnerDebugá  s    
ÿ
zRunnerTests.test_runnerDebugc                    s^   ˆ   ddg¡ tdƒ}| ¡  dˆ _‡ fdd„}ˆ  tjd|¡ ˆ  ˆ  ¡ ¡ ˆ  	ˆ j¡ dS )	zL
        Trial uses pdb if no debugger is specified by `--debugger`
        r¼   rµ   ZpdbrcFc                    s
   dˆ _ d S ©NT©Úruncall_called©Úpdbrl   r\   r   r   r   r   ø  s    z=RunnerTests.test_runnerDebuggerDefaultsToPdb.<locals>.runcallr   N)
r‰   r   ÚtouchrÁ   ÚpatchrÃ   ÚPdbr»   rŒ   rO   )r   Z	pdbrcFiler   r   r   r   Ú test_runnerDebuggerDefaultsToPdbî  s    z,RunnerTests.test_runnerDebuggerDefaultsToPdbc                    sV   ˆ   ddddddg¡ dˆ _‡ fdd	„}ˆ  tjd
|¡ ˆ  ˆ  ¡ ¡ ˆ  ˆ j¡ dS )zU
        Trial uses pdb if pdb is passed explicitly to the `--debugger` arg.
        r´   rw   ú
--debuggerrÃ   r¼   rµ   Fc                    s
   dˆ _ d S r¿   rÀ   rÂ   r   r   r   r     s    zGRunnerTests.test_runnerDebuggerWithExplicitlyPassedPdb.<locals>.runcallr   N)r‰   rÁ   rÅ   rÃ   rÆ   r»   rŒ   rO   )r   r   r   r   r   Ú*test_runnerDebuggerWithExplicitlyPassedPdb  s    úÿz6RunnerTests.test_runnerDebuggerWithExplicitlyPassedPdbc                 C   sN   |   ddddddg¡ |  ¡ }|  |¡}|  | j|j¡ |  dg|jj¡ dS )	zM
        Trial uses specified debugger if the debugger is available.
        r´   rw   rÈ   z4twisted.trial.test.test_runner.RunnerTests.cdebuggerr¼   rµ   r   N)r‰   rŒ   r»   rH   r…   r   r½   )r   r¸   r\   r   r   r   Útest_runnerDebugger  s    úÿ

zRunnerTests.test_runnerDebuggerc                 C   s.   |   dg¡ |  ¡ }| ¡ }|  |tj¡ dS )z•
        If trial was passed the C{--exitfirst} option, the constructed test
        result object is wrapped with L{reporter._ExitWrapper}.
        z--exitfirstN)r‰   rŒ   rY   r•   r   Z_ExitWrapperr�   r   r   r   Útest_exitfirst0  s    zRunnerTests.test_exitfirstN)r%   r&   r'   rX   rˆ   r‰   rŒ   r�   r‘   r”   r–   r˜   r­   r³   rº   r»   r¾   rÇ   rÉ   r   Z	cdebuggerrÊ   rË   r   r   r   r   rt     s&   !9$rt   c                   @   s   e Zd Zdd„ ZdS )ÚTrialSuiteTestsc                 C   s   t dƒ d S )Nztwisted.trial.runner.TrialSuiter   r   r   r   r   Útest_imports<  s    zTrialSuiteTests.test_importsN)r%   r&   r'   rÍ   r   r   r   r   rÌ   ;  s   rÌ   c                   @   sF   e Zd ZG dd„ dejƒZdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dS )ÚUntilFailureTestsc                   @   s*   e Zd ZU dZg Zed ed< dd„ ZdS )zUntilFailureTests.FailAfterzC
        A test case that fails when run 3 times in a row.
        NÚcountc                 C   s(   | j  d ¡ t| j ƒdkr$|  d¡ d S )Né   zCount reached 3)rÏ   r"   rF   rª   r   r   r   r   rg   I  s    z$UntilFailureTests.FailAfter.test_foo)r%   r&   r'   r@   rÏ   r   Ú__annotations__rg   r   r   r   r   Ú	FailAfterB  s   
rÒ   c                 C   s4   g t j_t  d¡| _tƒ | _tjtj	| jd�| _d S )Nrg   rU   )
rÎ   rÒ   rÏ   r4   r   r+   r   rW   r   ÚReporterr   r   r   r   rX   N  s    zUntilFailureTests.setUpc                 C   s@   | j  | j¡}|  |jd¡ |  | ¡ ¡ |  |  |¡d¡ dS )zl
        Test that the runUntilFailure method of the runner actually fail after
        a few runs.
        r    N)r   ÚrunUntilFailurer4   rH   rB   ÚassertFalser?   Ú_getFailuresr[   r   r   r   Útest_runUntilFailureT  s    z&UntilFailureTests.test_runUntilFailurec                 C   s
   t |jƒS )zL
        Get the number of failures that were reported to a result.
        )rF   r©   r[   r   r   r   rÖ   ^  s    zUntilFailureTests._getFailuresc                    sb   g ‰ ‡ fdd„}|   td|¡ | j | j¡}|  |jd¡ |  tˆ ƒd¡ |  ˆ | jtfg¡ dS )z�
        C{runUntilFailure} doesn't decorate the tests uselessly: it does it one
        time when run starts, but not at each turn.
        c                    s   ˆ   | |f¡ | S r   ©r"   ©r4   Z	interface©Z	decoratedr   r   Údecoratek  s    z@UntilFailureTests.test_runUntilFailureDecorate.<locals>.decoraterÛ   r    N)	rÅ   r   r   rÔ   r4   rH   rB   rF   r   ©r   rÛ   r\   r   rÚ   r   Útest_runUntilFailureDecorated  s    z.UntilFailureTests.test_runUntilFailureDecoratec                    sr   g ‰ ‡ fdd„}|   td|¡ d| j_| j | j¡}|  |jd¡ |  tˆ ƒd¡ |  ˆ | jt	f| jt
fg¡ dS )z‹
        C{runUntilFailure} applies the force-gc decoration after the standard
        L{ITestCase} decoration, but only one time.
        c                    s   ˆ   | |f¡ | S r   rØ   rÙ   rÚ   r   r   rÛ   }  s    zGUntilFailureTests.test_runUntilFailureForceGCDecorate.<locals>.decoraterÛ   Tr    rJ   N)rÅ   r   r   Z_forceGarbageCollectionrÔ   r4   rH   rB   rF   r   r   rÜ   r   rÚ   r   Ú#test_runUntilFailureForceGCDecoratev  s    þz5UntilFailureTests.test_runUntilFailureForceGCDecorateN)r%   r&   r'   rk   rr   rÒ   rX   r×   rÖ   rÝ   rÞ   r   r   r   r   rÎ   A  s   
rÎ   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚUncleanUntilFailureTestszh
    Test that the run-until-failure feature works correctly with the unclean
    error suppressor.
    c                 C   s$   t  | ¡ tjtj| jdd�| _d S )NTr_   )rÎ   rX   r   rW   r   rÓ   r+   r   r   r   r   rX   “  s    
  ÿzUncleanUntilFailureTests.setUpc                 C   s   t |jjƒS )z€
        Get the number of failures that were reported to a result that
        is wrapped in an UncleanFailureWrapper.
        )rF   Z_originalReporterr©   r[   r   r   r   rÖ   ™  s    z%UncleanUntilFailureTests._getFailuresN)r%   r&   r'   r@   rX   rÖ   r   r   r   r   rß   �  s   rß   c                   @   s   e Zd ZdZdd„ ZdS )ÚBreakingSuitez;
    A L{TestSuite} that logs an error when it is run.
    c                 C   s4   zt dƒ‚W n" t k
r.   t t ¡ ¡ Y nX d S )Nz#error that occurs outside of a test)ÚRuntimeErrorr
   Úerrr	   ÚFailurer[   r   r   r   rG   ¦  s    zBreakingSuite.runN)r%   r&   r'   r@   rG   r   r   r   r   rà   ¡  s   rà   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú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.
    c                 C   s   |   t¡ d S r   )ZflushLoggedErrorsrá   r   r   r   r   rˆ   µ  s    zLoggedErrorsTests.tearDownc                 C   s   t  ¡ }|  | ¡ d¡ dS )zg
        Check that we can construct a L{runner.LoggedSuite} and that it
        starts empty.
        r   N)r   ÚLoggedSuiterH   ÚcountTestCases)r   rl   r   r   r   Útest_construct¸  s    z LoggedErrorsTests.test_constructc                 C   sl   t  ¡ }t tƒ g¡}| |¡ |  t|jƒd¡ |  |jd d  	¡ tj
¡ |  |jd d  t¡¡ dS )zU
        Chek that a L{LoggedSuite} reports any logged errors to its result.
        r    r   N)r   Ú
TestResultr   rå   rà   rG   rH   rF   r¨   ÚidZNOT_IN_TESTrO   Úcheckrá   )r   r\   rl   r   r   r   Útest_capturesErrorÀ  s    
z$LoggedErrorsTests.test_capturesErrorN)r%   r&   r'   r@   rˆ   rç   rë   r   r   r   r   rä   ­  s   rä   c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚTestHolderTestsc                 C   s   d| _ t | j ¡| _d S ©Nrx   )rx   r   Z
TestHolderÚholderr   r   r   r   rX   Í  s    zTestHolderTests.setUpc                 C   s,   |   | j ¡ | j¡ |   | j ¡ | j¡ dS )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)rH   rî   ré   rx   ZshortDescriptionr   r   r   r   Útest_holderÑ  s    zTestHolderTests.test_holderc                 C   s6   |   | jt| jƒ¡ |  tt| jƒd| jtf ¡ dS )z?
        L{runner.TestHolder} implements L{ITestCase}.
        z5%r claims to provide %r but does not do so correctly.N)rZ   rî   r   rO   r   r   r   r   r   Útest_holderImplementsITestCaseÚ  s    
ÿþz.TestHolderTests.test_holderImplementsITestCasec                 C   s4   t  ¡ }| j |¡ |  | ¡ ¡ |  d|j¡ dS )zc
        A L{runner.TestHolder} can run against the standard Python
        C{TestResult}.
        r    N)rk   rè   rî   rG   rO   r?   rH   rB   r[   r   r   r   Útest_runsWithStandardResultå  s    z+TestHolderTests.test_runsWithStandardResultN)r%   r&   r'   rX   rï   rð   rñ   r   r   r   r   rì   Ì  s   	rì   c                   @   sN   e Zd ZdZedƒZG dd„ dƒZdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ ZdS )Ú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                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )z$ErrorHolderTestsMixin.TestResultStubz)
        Stub for L{TestResult}.
        c                 C   s
   g | _ d S r   )r¨   r   r   r   r   r     s    z-ErrorHolderTestsMixin.TestResultStub.__init__c                 C   s   d S r   r   r3   r   r   r   r-     s    z.ErrorHolderTestsMixin.TestResultStub.startTestc                 C   s   d S r   r   r3   r   r   r   r0     s    z-ErrorHolderTestsMixin.TestResultStub.stopTestc                 C   s   | j  ||f¡ d S r   )r¨   r"   r6   r   r   r   r8     s    z-ErrorHolderTestsMixin.TestResultStub.addErrorN)r%   r&   r'   r@   r   r-   r0   r8   r   r   r   r   ÚTestResultStubý  s
   ró   c                 C   s4   t  ¡ }| j |¡ |  | ¡ ¡ |  d|j¡ dS )zd
        A L{runner.ErrorHolder} can run against the standard Python
        C{TestResult}.
        r    N)rk   rè   rî   rG   rÕ   r?   rH   rB   r[   r   r   r   rñ     s    z1ErrorHolderTestsMixin.test_runsWithStandardResultc                 C   s<   | j  | j¡ |  | jj| j | jj| jj| jjffg¡ dS )zM
        L{runner.ErrorHolder} adds an error to the result when run.
        N)	rî   rG   r\   rH   r¨   r7   ÚtypeÚvalueÚtbr   r   r   r   Útest_run  s
    þzErrorHolderTestsMixin.test_runc                 C   s:   |   | j¡ |  | jj| j | jj| jj| jjffg¡ dS )zP
        L{runner.ErrorHolder} adds an error to the result when called.
        N)rî   r\   rH   r¨   r7   rô   rõ   rö   r   r   r   r   Ú	test_call"  s
    þzErrorHolderTestsMixin.test_callc                 C   s   |   | j ¡ d¡ dS )zH
        L{runner.ErrorHolder.countTestCases} always returns 0.
        r   N)rH   rî   ræ   r   r   r   r   Útest_countTestCases,  s    z)ErrorHolderTestsMixin.test_countTestCasesc                 C   s,   d  t| jjd ƒ¡}|  t| jƒ|¡ dS )zh
        L{runner.ErrorHolder.__repr__} returns a string describing the error it
        holds.
        z0<ErrorHolder description='description' error={}>r    N)ÚformatÚreprrî   r7   rH   )r   Úexpectedr   r   r   Ú	test_repr2  s    ÿzErrorHolderTestsMixin.test_reprN)r%   r&   r'   r@   ÚZeroDivisionErrorÚexceptionForTestsró   rñ   r÷   rø   rù   rý   r   r   r   r   rò   ð  s   



rò   c                   @   s   e Zd ZdZdd„ ZdS )ÚFailureHoldingErrorHolderTestsz“
    Tests for L{runner.ErrorHolder} behaving similarly to L{runner.TestHolder}
    when constructed with a L{Failure} representing its error.
    c                 C   sP   d| _ z
| j‚W n tk
r.   t ¡ | _Y nX t | j | j¡| _|  	¡ | _
d S rí   )rx   rÿ   rþ   r	   rã   r7   r   ÚErrorHolderrî   ró   r\   r   r   r   r   rX   D  s    
z$FailureHoldingErrorHolderTests.setUpNr`   r   r   r   r   r   >  s   r   c                   @   s   e Zd ZdZdd„ ZdS )ÚExcInfoHoldingErrorHolderTestsz 
    Tests for L{runner.ErrorHolder} behaving similarly to L{runner.TestHolder}
    when constructed with a C{exc_info}-style tuple representing its error.
    c                 C   sV   d| _ z
| j‚W n& tk
r6   t ¡ }t ¡ | _Y nX t 	| j |¡| _
|  ¡ | _d S rí   )rx   rÿ   rþ   ÚsysÚexc_infor	   rã   r7   r   r  rî   ró   r\   )r   ZexceptionInfor   r   r   rX   U  s    
z$ExcInfoHoldingErrorHolderTests.setUpNr`   r   r   r   r   r  O  s   r  c                   @   sB   e Zd ZdZG dd„ dejƒZdd„ Zdd„ Zdd	„ Z	d
d„ Z
dS )ÚMalformedMethodTestszR
    Test that trial manages when test methods don't have correct signatures.
    c                   @   s*   e Zd ZdZdd„ Zdd„ Ze e¡ZdS )z%MalformedMethodTests.ContainMalformedzV
        This TestCase holds malformed test methods that trial should handle.
        c                 C   s   d S r   r   )r   Zblahr   r   r   rg   k  s    z.MalformedMethodTests.ContainMalformed.test_fooc                   C   s   d S r   r   r   r   r   r   Útest_barn  s    z.MalformedMethodTests.ContainMalformed.test_barN)	r%   r&   r'   r@   rg   r  r   ZinlineCallbacksÚ	test_spamr   r   r   r   ÚContainMalformedf  s   r  c                 C   s\   t ƒ }tjtj|d�}t |¡}| |¡}|  |j	d¡ |  
| ¡ ¡ |  t|jƒd¡ dS )zL
        Wrapper for one of the test method of L{ContainMalformed}.
        rU   r    N)r   r   rW   r   rÓ   r  r  rG   rH   rB   rÕ   r?   rF   r¨   )r   r/   r+   ZtrialRunnerr4   r\   r   r   r   Ú_tests  s    

zMalformedMethodTests._testc                 C   s   |   d¡ dS )zE
        Test when the method has extra (useless) arguments.
        rg   N©r	  r   r   r   r   Útest_extraArg  s    z"MalformedMethodTests.test_extraArgc                 C   s   |   d¡ dS )zJ
        Test when the method doesn't have even self as argument.
        r  Nr
  r   r   r   r   Ú
test_noArg…  s    zMalformedMethodTests.test_noArgc                 C   s   |   d¡ dS )z5
        Test a decorated method also fails.
        r  Nr
  r   r   r   r   Útest_decorated‹  s    z#MalformedMethodTests.test_decoratedN)r%   r&   r'   r@   rk   rr   r  r	  r  r  r  r   r   r   r   r  a  s   r  c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚDestructiveTestSuiteTestsz2
    Test for L{runner.DestructiveTestSuite}.
    c                    sn   g ‰ G ‡ fdd„dt jƒ}|dƒ}t ¡ }t |g¡}|  ˆ g ¡ | |¡ |  ˆ dg¡ |  | ¡ d¡ dS )zL
        Thes destructive test suite should run the tests normally.
        c                       s   e Zd Z‡ fdd„ZdS )z6DestructiveTestSuiteTests.test_basic.<locals>.MockTestc                    s   ˆ   d¡ d S r¿   rØ   rp   ©Úcalledr   r   rg   ž  s    z?DestructiveTestSuiteTests.test_basic.<locals>.MockTest.test_fooNrh   r   r  r   r   rq   �  s   rq   rg   Tr   N)	rk   rr   r   rè   r   ÚDestructiveTestSuiterH   rG   ræ   ©r   rq   r4   r\   rl   r   r  r   Ú
test_basic—  s    
z$DestructiveTestSuiteTests.test_basicc                    st   g ‰ G ‡ fdd„dt jƒ}t ¡ }t ¡ }tj|_| |¡}|  	ˆ g ¡ | 
|¡ |  	ˆ dg¡ |  	| ¡ d¡ dS )zu
        Test the C{shouldStop} management: raising a C{KeyboardInterrupt} must
        interrupt the suite.
        c                       s,   e Zd Z‡ fdd„Zdd„ Z‡ fdd„ZdS )z;DestructiveTestSuiteTests.test_shouldStop.<locals>.MockTestc                    s   ˆ   d¡ d S )Nr    rØ   rp   r  r   r   Ú	test_foo1±  s    zEDestructiveTestSuiteTests.test_shouldStop.<locals>.MockTest.test_foo1c                 S   s
   t ƒ ‚d S r   )ÚKeyboardInterruptrp   r   r   r   Ú	test_foo2´  s    zEDestructiveTestSuiteTests.test_shouldStop.<locals>.MockTest.test_foo2c                    s   ˆ   d¡ d S )NrJ   rØ   rp   r  r   r   Ú	test_foo3·  s    zEDestructiveTestSuiteTests.test_shouldStop.<locals>.MockTest.test_foo3N)r%   r&   r'   r  r  r  r   r  r   r   rq   °  s   rq   r    N)r   rr   r   rè   r   r¶   r  ZsuiteFactoryZ	loadClassrH   rG   ræ   )r   rq   r\   r¹   rl   r   r  r   Útest_shouldStop©  s    


z)DestructiveTestSuiteTests.test_shouldStopc                 C   s\   G dd„ dt jƒ}|dƒ}t ¡ }t |g¡}|  | ¡ d¡ | |¡ |  | ¡ d¡ dS )zn
        Checks that the test suite cleanups its tests during the run, so that
        it ends empty.
        c                   @   s   e Zd Zdd„ ZdS )z8DestructiveTestSuiteTests.test_cleanup.<locals>.MockTestc                 S   s   d S r   r   rp   r   r   r   rg   Ë  s    zADestructiveTestSuiteTests.test_cleanup.<locals>.MockTest.test_fooNrh   r   r   r   r   rq   Ê  s   rq   rg   r    r   N)	rk   rr   r   rè   r   r  rH   ræ   rG   r  r   r   r   Útest_cleanupÄ  s    
z&DestructiveTestSuiteTests.test_cleanupN)r%   r&   r'   r@   r  r  r  r   r   r   r   r  ’  s   r  c                   @   s   e Zd ZG dd„ dejƒZdS )ÚRunnerDeprecationTestsc                   @   s<   e Zd ZdZdZdZdZdd„ Zdd„ Zdd„ Z	d	d
„ Z
dS )z#RunnerDeprecationTests.FakeReporterz»
        Fake reporter that does *not* implement done() but *does* implement
        printErrors, separator, printSummary, stream, write and writeln
        without deprecations.
        Nc                 G   s   d S r   r   rŠ   r   r   r   ÚprintErrorsâ  s    z/RunnerDeprecationTests.FakeReporter.printErrorsc                 G   s   d S r   r   rŠ   r   r   r   ÚprintSummaryå  s    z0RunnerDeprecationTests.FakeReporter.printSummaryc                 G   s   d S r   r   rŠ   r   r   r   Úwriteè  s    z)RunnerDeprecationTests.FakeReporter.writec                 G   s   d S r   r   rŠ   r   r   r   Úwritelnë  s    z+RunnerDeprecationTests.FakeReporter.writeln)r%   r&   r'   r@   r5   rA   r+   r  r  r  r  r   r   r   r   ÚFakeReporter×  s   r  N)r%   r&   r'   r   rÓ   r  r   r   r   r   r  Ö  s   r  c                   @   s   e Zd ZdZdd„ ZdS )ÚQualifiedNameWalkerTestsz<
    Tests for L{twisted.trial.runner._qualNameWalker}.
    c                 C   s6   t t d¡ƒ}|  |dg fddgfdddgfg¡ dS )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.
        zwalker.texas.rangerzwalker.texasZrangerÚwalkerZtexasN)rz   r   Z_qualNameWalkerrH   )r   ZwalkerResultsr   r   r   Útest_walksDownPathô  s    
ýþz+QualifiedNameWalkerTests.test_walksDownPathN)r%   r&   r'   r@   r"  r   r   r   r   r   ï  s   r   c                   @   s   e Zd ZdZdd„ ZdS )ÚTrialMainDoesNothingTestszl
    Importing L{twisted.trial.__main__} will not run the script
    unless it is actually C{__main__}.
    c                 C   s   t dƒ dS )zO
        If we import L{twisted.trial.__main__}, it should do nothing.
        ztwisted.trial.__main__N)Ú
__import__r   r   r   r   Útest_importDoesNothing  s    z0TrialMainDoesNothingTests.test_importDoesNothingN)r%   r&   r'   r@   r%  r   r   r   r   r#    s   r#  )@r›   rÃ   r  r   rk   Úior   Útypingr   Zzope.interfacer   Zzope.interface.verifyr   Ztwistedr   Ztwisted.internetr   Ztwisted.pluginsr   Ztwisted.pythonr	   r
   r   Ztwisted.python.filepathr   Ztwisted.python.reflectr   Ztwisted.scriptsr   Ztwisted.trialr   r   r   Ztwisted.trial._asyncrunnerr   Ztwisted.trial.itrialr   r   r   r(   rC   rj   rT   r^   ra   rf   ro   rs   rt   rÌ   rÎ   rß   rc   rà   rä   rì   rò   r   r  r  r  r  r   r#  r   r   r   r   Ú<module>   s^   	Q&
 ÿ,  $L$N1D