o
    ¯bàˆ  ã                   @   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   ó
   g | _ d S ©N)Ú_calls©Úself© r   ú@/usr/lib/python3/dist-packages/twisted/trial/test/test_runner.pyÚ__init__   ó   
zCapturingDebugger.__init__c                 O   s*   | j  d¡ |d |dd … i |¤Ž 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   Ú
shouldStopÚ_streamÚ	_tbformatÚ	_rterrorsÚ
_publisher)r   ÚstreamÚtbformatÚrterrorsÚ	publisherr   r   r   r   3   s   
zCapturingReporter.__init__c                 C   ó   | 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   r5   >   ó   zCapturingReporter.startTestc                 C   r4   )z}
        Report the status of a single test method
        @param method: an object that is adaptable to ITestMethod
        ÚstopTestNr#   r6   r   r   r   r9   E   r8   zCapturingReporter.stopTestc                 C   r4   )zƒcalled when the reactor has been left in a 'dirty' state
        @param errs: a list of L{twisted.python.failure.Failure}s
        ÚcleanupErrorNr#   )r   Úerrsr   r   r   ÚcleanupErrorsL   ó   zCapturingReporter.cleanupErrorsc                 C   s   | j  d¡ d S )NÚ
addSuccessr#   ©r   Útestr   r   r   r>   R   ó   zCapturingReporter.addSuccessc                 C   ó   dS )z@
        Do nothing. These tests don't care about done.
        Nr   r   r   r   r   ÚdoneU   ó    zCapturingReporter.donec                 C   rB   )zD
        Do nothing. These tests don't care about addError.
        Nr   ©r   r@   Úerrorr   r   r   ÚaddErrorZ   rD   zCapturingReporter.addErrorc                 C   rB   )zF
        Do nothing. These tests don't care about addFailure.
        Nr   )r   r@   r	   r   r   r   Ú
addFailure_   rD   zCapturingReporter.addFailurec                 C   rB   )zN
        Do nothing. These tests don't care about addExpectedFailure.
        Nr   )r   r@   r	   Útodor   r   r   ÚaddExpectedFailured   rD   z$CapturingReporter.addExpectedFailurec                 C   rB   )zP
        Do nothing. These tests don't care about addUnexpectedSuccess.
        Nr   )r   r@   rI   r   r   r   ÚaddUnexpectedSuccessi   rD   z&CapturingReporter.addUnexpectedSuccessc                 C   rB   )zC
        Do nothing. These tests don't care about addSkip.
        Nr   )r   r@   Úreasonr   r   r   ÚaddSkipn   rD   zCapturingReporter.addSkipc                 C   rB   )zI
        Do nothing. These tests don't care about wasSuccessful.
        Nr   r   r   r   r   ÚwasSuccessfuls   rD   zCapturingReporter.wasSuccessful)NNNNr   )r'   r(   r)   Ú__doc__r0   r1   r%   Ú	separatorÚtestsRunr   r5   r9   r<   r>   rC   rG   rH   rJ   rK   rM   rN   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d	„ Zd
d„ Zdd„ Z	dS )ÚTrialRunnerTestsMixinz9
    Mixin defining tests for L{runner.TrialRunner}.
    c                 C   s   | j  ¡  d S r   )r   Ú_tearDownLogFiler   r   r   r   ÚtearDown~   ó   zTrialRunnerTestsMixin.tearDownc                 C   rB   )z=
        Empty test method, used by the other tests.
        Nr   r   r   r   r   Ú
test_empty�   rD   z TrialRunnerTestsMixin.test_emptyc                 C   s   t jjS r   )r
   ÚtheLogPublisherÚ	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)ÚlenrY   r   Úrunr@   ÚassertEqual)r   ÚoriginalCountÚnewCountr   r   r   Útest_addObservers‰   s   z'TrialRunnerTestsMixin.test_addObserversc                    sl   ˆj j‰g ‰ ‡ ‡‡fdd„}|ˆj _ˆj  ˆj¡ ˆj  ˆj¡ ˆ tˆ ƒd¡ ˆ ˆ d ˆ d u d¡ dS )z=
        Test that a new file is opened on each run.
        c                      ó   ˆƒ  ˆ   ˆjj¡ d S r   )r$   r   Ú_logFileObserverr   ©ÚlÚoldSetUpLogFiler   r   r   ÚsetUpLogFileš   ó   zDTrialRunnerTestsMixin.test_logFileAlwaysActive.<locals>.setUpLogFileé   r   r"   z'Should have created a new file observerN)r   Ú_setUpLogFiler[   r@   r\   rZ   ÚassertFalse©r   re   r   rb   r   Útest_logFileAlwaysActive“   s   z.TrialRunnerTestsMixin.test_logFileAlwaysActivec                    sV   ˆj j‰g ‰ ‡ ‡‡fdd„}|ˆj _ˆj  ˆj¡ ˆ tˆ ƒd¡ ˆ ˆ d j¡ dS )zB
        Test that file created is closed during the run.
        c                      r`   r   )r$   r   Ú_logFileObjectr   rb   r   r   re   «   rf   zBTrialRunnerTestsMixin.test_logFileGetsClosed.<locals>.setUpLogFiler"   r   N)r   rh   r[   r@   r\   rZ   Ú
assertTrueÚclosedrj   r   rb   r   Útest_logFileGetsClosed¤   s   z,TrialRunnerTestsMixin.test_logFileGetsClosedN)
r'   r(   r)   rO   rT   rV   rY   r_   rk   ro   r   r   r   r   rR   y   s    
rR   c                   @   ó    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©r0   rV   ©r   r0   r   ÚTrialRunnerr*   rq   r@   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)   rO   ru   rz   r   r   r   r   rq   µ   s    rq   c                   @   ó   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©r0   ÚuncleanWarningsrV   rs   r   r   r   r   ru   Ñ   s
   ÿz1TrialRunnerWithUncleanWarningsReporterTests.setUpN©r'   r(   r)   rO   ru   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 )Nrr   )r
   r   r0   r   rt   r*   ÚDRY_RUNÚmakeTestFixturesr   r   r   r   ru   ß   s   ÿzDryRunMixin.setUpc                 C   rB   )zh
        Set C{self.test} and C{self.suite}, where C{self.suite} is an empty
        TestSuite.
        Nr   r   r   r   r   r‚   ç   rD   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   r[   Ú	TestSuiter\   r   rx   r   r   r   rV   í   s   zDryRunMixin.test_emptyc                 C   s$   | j  | j¡}|  |jg d¢¡ dS )z†
        If we are running a single test, check the reporter starts, passes and
        then stops the test during a dry run.
        )r5   r>   r9   N)r   r[   r@   r\   r   rx   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   r[   r@   r\   r
   r   r   r   r   Útest_testsNotRuný   s   zDryRunMixin.test_testsNotRunN)	r'   r(   r)   rO   ru   r‚   rV   r„   r…   r   r   r   r   r€   Ù   s    r€   c                   @   r{   )Ú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                   @   ó   e Zd Zdd„ ZdS )z;SynchronousDryRunTests.makeTestFixtures.<locals>.PyunitCasec                 S   ó   d S r   r   r   r   r   r   Útest_foo  ó   zDSynchronousDryRunTests.makeTestFixtures.<locals>.PyunitCase.test_fooN©r'   r(   r)   r‰   r   r   r   r   Ú
PyunitCase  ó    rŒ   r‰   )r   ÚSynchronousTestCaser@   Úpyunitrƒ   Úsuite©r   rŒ   r   r   r   r‚   
  ó   
z'SynchronousDryRunTests.makeTestFixturesN©r'   r(   r)   rO   r‚   r   r   r   r   r†     ó    r†   c                   @   r{   )Ú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                       ó   e Zd Z‡ fdd„ZdS )z.DryRunTests.makeTestFixtures.<locals>.MockTestc                    s   ˆ j  d¡ d S )Nr‰   )r
   r$   ©r@   r   r   r   r‰     rA   z7DryRunTests.makeTestFixtures.<locals>.MockTest.test_fooNr‹   r   r   r   r   ÚMockTest  ó    r˜   r‰   )r   ÚTestCaser@   r   rƒ   r�   )r   r˜   r   r   r   r‚     s   
zDryRunTests.makeTestFixturesNr“   r   r   r   r   r•     r”   r•   c                   @   r{   )Ú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                   @   r‡   )z6PyUnitDryRunTests.makeTestFixtures.<locals>.PyunitCasec                 S   rˆ   r   r   r   r   r   r   r‰   (  rŠ   z?PyUnitDryRunTests.makeTestFixtures.<locals>.PyunitCase.test_fooNr‹   r   r   r   r   rŒ   '  r�   rŒ   r‰   )r�   rš   r@   rƒ   r�   r‘   r   r   r   r‚   &  r’   z"PyUnitDryRunTests.makeTestFixturesNr“   r   r   r   r   r›   !  r”   r›   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                    sv   t  ¡ ˆ_t t¡ d¡}d |d d… ¡}|d }tj	d|ddd |d�g‰ ‡ ‡fdd„}t
jˆ_|t
_g d	¢ˆ_d S )
NÚ.éÿÿÿÿzTest Helper ReporterzUtility for unit testing.Ú	capturing)ÚdescriptionÚlongOptÚshortOptÚklassc                    s,   ˆ  | t¡ ˆ tˆj| g|¢R i |¤Žƒ S r   )r\   r   ÚlistÚoriginal)ÚifaceÚaÚkw©Úpluginsr   r   r   Ú
getPluginsE  s    z%RunnerTests.setUp.<locals>.getPlugins)r5   r>   r9   r5   r>   r9   r5   r>   r9   r5   r>   r9   r5   r>   r9   r5   r>   r9   r5   r>   r9   r5   r>   r9   r5   r>   r9   r5   r>   r9   )r   ÚOptionsÚconfigr   Úqualr*   ÚsplitÚjoinr   Ú	_Reporterr   r«   r¥   ÚstandardReport)r   ÚpartsÚpackager£   r«   r   r©   r   ru   0  s"   
úÿzRunnerTests.setUpc                 C   s   | j t_d S r   )r¥   r   r«   r   r   r   r   rT   m  s   zRunnerTests.tearDownc                 C   s   | j  |¡ d S r   )r­   ÚparseOptions©r   r%   r   r   r   rµ   p  rA   zRunnerTests.parseOptionsc                 C   s.   t  | j¡}tƒ |_|  |j¡ t ¡ |_	|S r   )
r   Ú_makeRunnerr­   r   r0   Ú
addCleanuprS   r
   ÚLogPublisherÚ_log)r   Úrr   r   r   Ú	getRunners  s
   
zRunnerTests.getRunnerc                 C   s2   |   g ¡ | jd }|  ¡ }|  || ¡ j¡ d S ©Nr   )rµ   r­   r¼   r\   rv   Ú	__class__)r   ry   r   r   r   r   Útest_runner_can_get_reporterƒ  s   

z(RunnerTests.test_runner_can_get_reporterc                 C   s2   |   g ¡ |  ¡ }| ¡ }|  |j| jd ¡ d S r½   )rµ   r¼   rv   r\   r¾   r­   ©r   r   ry   r   r   r   Útest_runner_get_result‰  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¼   ÚassertNotIsInstancerv   r   ÚUncleanWarningsReporterWrapper©r   r   r   r   r   Ú test_uncleanWarningsOffByDefault�  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¼   ÚassertIsInstancerv   r   rÃ   rÄ   r   r   r   Útest_getsUncleanWarnings›  s
   
ÿz$RunnerTests.test_getsUncleanWarningsc                 C   s(   |   ddg¡ |  ¡ }|  |jd¡ d S )Nú--temp-directoryÚ	some_path)rµ   r¼   r\   ÚworkingDirectoryrÄ   r   r   r   Útest_runner_working_directory§  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 }|rN|  |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Úpathr¸   r[   )r   ÚsubsequentDirectory©ÚConcurrentCaseÚ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Í   Ó  r=   zWRunnerTests.test_concurrentImplicitWorkingDirectory.<locals>.ConcurrentCase.test_secondN)r'   r(   r)   rØ   rÍ   r   rÓ   r   r   rÔ   Ä  s    rÔ   rØ   r   r"   Ú_trial_tempz_trial_temp-1)rÌ   rÙ   N)rµ   r¸   rÎ   rÐ   rÏ   r   ÚmktempÚmakedirsrÑ   r¼   r   rŽ   r[   ÚerrorsÚfailuresÚfailr\   Úchild)r   ÚfirstRunnerry   Úbadr   rÓ   r   Ú'test_concurrentImplicitWorkingDirectory¬  s&   


þþz3RunnerTests.test_concurrentImplicitWorkingDirectoryc                    s�   |   dtj |  ¡ ¡g¡ t ¡ }|  tj|¡ |  ¡ }|  ¡ ‰G ‡ ‡fdd„dt	j
ƒ‰ | ˆ dƒ¡}|j|j }|rF|  |d d ¡ dS 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   Ú_WorkingDirectoryBusyr[   r   ©rÔ   rÖ   r   r   Útest_concurrentó  s
   ýz[RunnerTests.test_concurrentExplicitWorkingDirectory.<locals>.ConcurrentCase.test_concurrentc                 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ä   þ  ó   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   rŽ   r[   rÝ   rÞ   rß   )r   ÚinitialDirectoryrá   ry   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È   ú
--reporterrŸ   útwisted.trial.test.sampleT)
rµ   rÛ   r¼   r   Ú
TestLoaderÚ
loadByNamer[   r\   r²   r   )r   Ú	my_runnerÚloaderr�   ry   r   r   r   Útest_runner_normal	  s   ûÿ	
zRunnerTests.test_runner_normalc                 C   s   t  ¡ }| dd¡}| |¡S )Nrï   T)r   rð   rñ   r[   )r   rò   ró   r�   r   r   r   ÚrunSampleSuite  s   
zRunnerTests.runSampleSuitec                 C   sP   |   g d¢¡ |  ¡ }tƒ  }|_|  |¡}|  | j|j¡ |  dg|j¡ dS )zL
        Trial uses its debugger if the `--debug` option is passed.
        )rî   rŸ   ú--debugrï   r!   N)rµ   r¼   r   Údebuggerrõ   r\   r²   r   )r   rò   r÷   ry   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ï   ÚpdbrcFc                    ó
   dˆ _ d S ©NT©Úruncall_called©Úpdbr�   ry   r   r   r   r!   5  r    z=RunnerTests.test_runnerDebuggerDefaultsToPdb.<locals>.runcallr!   N)
rµ   r   Útouchrý   Úpatchrÿ   ÚPdbrõ   r¼   rm   )r   Ú	pdbrcFiler!   r   r   r   Ú test_runnerDebuggerDefaultsToPdb+  s   z,RunnerTests.test_runnerDebuggerDefaultsToPdbc                    sN   ˆ   g d¢¡ dˆ _‡ fdd„}ˆ  tjd|¡ ˆ  ˆ  ¡ ¡ ˆ  ˆ j¡ dS )zU
        Trial uses pdb if pdb is passed explicitly to the `--debugger` arg.
        )rî   rŸ   ú
--debuggerrÿ   rö   rï   Fc                    rú   rû   rü   rþ   r   r   r   r!   O  r    zGRunnerTests.test_runnerDebuggerWithExplicitlyPassedPdb.<locals>.runcallr!   N)rµ   rý   r  rÿ   r  rõ   r¼   rm   )r   r!   r   r   r   Ú*test_runnerDebuggerWithExplicitlyPassedPdb>  s   ÿz6RunnerTests.test_runnerDebuggerWithExplicitlyPassedPdbc                 C   sF   |   g d¢¡ |  ¡ }|  |¡}|  | j|j¡ |  dg|jj¡ dS )zM
        Trial uses specified debugger if the debugger is available.
        )rî   rŸ   r  z4twisted.trial.test.test_runner.RunnerTests.cdebuggerrö   rï   r!   N)rµ   r¼   rõ   r\   r²   r   r÷   )r   rò   ry   r   r   r   Útest_runnerDebuggerZ  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¼   rv   rÆ   r   Ú_ExitWrapperrÀ   r   r   r   Útest_exitfirstm  s   zRunnerTests.test_exitfirstN)r'   r(   r)   ru   rT   rµ   r¼   r¿   rÁ   rÅ   rÇ   rË   rã   rí   rô   rõ   rø   r  r  r   Ú	cdebuggerr  r	  r   r   r   r   rœ   /  s(    =9$rœ   c                   @   r‡   )ÚTrialSuiteTestsc                 C   s   t dƒ d S )Nztwisted.trial.runner.TrialSuiter   r   r   r   r   Útest_importsy  s   zTrialSuiteTests.test_importsN)r'   r(   r)   r  r   r   r   r   r  x  r�   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 d S )Né   zCount reached 3)r  r$   rZ   rß   r   r   r   r   r‰   †  s   ÿz$UntilFailureTests.FailAfter.test_foo)r'   r(   r)   rO   r  r   Ú__annotations__r‰   r   r   r   r   Ú	FailAfter  s   
 r  c                 C   s4   g t j_t  d¡| _tƒ | _tjtj	| jd�| _d S )Nr‰   rr   )
r  r  r  r@   r   r0   r   rt   r   ÚReporterr   r   r   r   ru   ‹  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   ÚrunUntilFailurer@   r\   rQ   ri   rN   Ú_getFailuresrx   r   r   r   Útest_runUntilFailure‘  s   z&UntilFailureTests.test_runUntilFailurec                 C   s
   t |jƒS )zL
        Get the number of failures that were reported to a result.
        )rZ   rÞ   rx   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                    ó   ˆ   | |f¡ | S r   ©r$   ©r@   Ú	interface©Ú	decoratedr   r   Údecorate¨  ó   z@UntilFailureTests.test_runUntilFailureDecorate.<locals>.decorater  r"   N)	r  r   r   r  r@   r\   rQ   rZ   r   ©r   r  ry   r   r  r   Útest_runUntilFailureDecorate¡  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                    r  r   r  r  r  r   r   r  º  r  zGUntilFailureTests.test_runUntilFailureForceGCDecorate.<locals>.decorater  Tr"   rg   N)r  r   r   Ú_forceGarbageCollectionr  r@   r\   rQ   rZ   r   r   r  r   r  r   Ú#test_runUntilFailureForceGCDecorate³  s   þz5UntilFailureTests.test_runUntilFailureForceGCDecorateN)r'   r(   r)   r�   rš   r  ru   r  r  r  r!  r   r   r   r   r  ~  s    
r  c                   @   rp   )Ú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  ru   r   rt   r   r  r0   r   r   r   r   ru   Ð  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.
        )rZ   Ú_originalReporterrÞ   rx   r   r   r   r  Ö  ó   z%UncleanUntilFailureTests._getFailuresN)r'   r(   r)   rO   ru   r  r   r   r   r   r"  Ê  s    r"  c                   @   r{   )ÚBreakingSuitez;
    A L{TestSuite} that logs an error when it is run.
    c                 C   s,   zt dƒ‚ t y   t t ¡ ¡ Y d S w )Nz#error that occurs outside of a test)ÚRuntimeErrorr
   Úerrr	   ÚFailurerx   r   r   r   r[   ã  s
   ÿzBreakingSuite.runN)r'   r(   r)   rO   r[   r   r   r   r   r%  Þ  r”   r%  c                   @   ó(   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   )ÚflushLoggedErrorsr&  r   r   r   r   rT   ò  rU   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   ÚLoggedSuiter\   ÚcountTestCases)r   r�   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%  r[   r\   rZ   rÝ   ÚidÚNOT_IN_TESTrm   Úcheckr&  )r   ry   r�   r   r   r   Útest_capturesErrorý  s   
z$LoggedErrorsTests.test_capturesErrorN)r'   r(   r)   rO   rT   r.  r3  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 ©Nr    )r    r   Ú
TestHolderÚholderr   r   r   r   ru   
  rf   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)r\   r7  r0  r    Ú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)rw   r7  r   rm   r   r   r   r   r   Útest_holderImplementsITestCase  s   
ÿþz.TestHolderTests.test_holderImplementsITestCasec                 C   ó4   t  ¡ }| j |¡ |  | ¡ ¡ |  d|j¡ dS )zc
        A L{runner.TestHolder} can run against the standard Python
        C{TestResult}.
        r"   N)r�   r/  r7  r[   rm   rN   r\   rQ   rx   r   r   r   Útest_runsWithStandardResult"  ó   z+TestHolderTests.test_runsWithStandardResultN)r'   r(   r)   ru   r9  r:  r<  r   r   r   r   r4  	  s
    	r4  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   r   r   )rÝ   r   r   r   r   r   ?  r    z-ErrorHolderTestsMixin.TestResultStub.__init__c                 C   rˆ   r   r   r?   r   r   r   r5   B  rŠ   z.ErrorHolderTestsMixin.TestResultStub.startTestc                 C   rˆ   r   r   r?   r   r   r   r9   E  rŠ   z-ErrorHolderTestsMixin.TestResultStub.stopTestc                 C   s   | j  ||f¡ d S r   )rÝ   r$   rE   r   r   r   rG   H  s   z-ErrorHolderTestsMixin.TestResultStub.addErrorN)r'   r(   r)   rO   r   r5   r9   rG   r   r   r   r   ÚTestResultStub:  s    r?  c                 C   r;  )zd
        A L{runner.ErrorHolder} can run against the standard Python
        C{TestResult}.
        r"   N)r�   r/  r7  r[   ri   rN   r\   rQ   rx   r   r   r   r<  K  r=  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)	r7  r[   ry   r\   rÝ   rF   ÚtypeÚvalueÚtbr   r   r   r   Útest_runU  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)r7  ry   r\   rÝ   rF   r@  rA  rB  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)r\   r7  r-  r   r   r   r   Útest_countTestCasesi  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Úreprr7  rF   r\   )r   Úexpectedr   r   r   Ú	test_repro  s   ÿzErrorHolderTestsMixin.test_reprN)r'   r(   r)   rO   ÚZeroDivisionErrorÚexceptionForTestsr?  r<  rC  rD  rE  rI  r   r   r   r   r>  -  s    



r>  c                   @   r{   )ÚFailureHoldingErrorHolderTestsz“
    Tests for L{runner.ErrorHolder} behaving similarly to L{runner.TestHolder}
    when constructed with a L{Failure} representing its error.
    c                 C   sJ   d| _ z| j‚ ty   t ¡ | _Y nw t | j | j¡| _|  	¡ | _
d S r5  )r    rK  rJ  r	   r(  rF   r   ÚErrorHolderr7  r?  ry   r   r   r   r   ru   �  s   ÿz$FailureHoldingErrorHolderTests.setUpNr   r   r   r   r   rL  {  ó    rL  c                   @   r{   )Ú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   sP   d| _ z| j‚ ty   t ¡ }t ¡ | _Y nw t 	| j |¡| _
|  ¡ | _d S r5  )r    rK  rJ  ÚsysÚexc_infor	   r(  rF   r   rM  r7  r?  ry   )r   ÚexceptionInfor   r   r   ru   ’  s   þz$ExcInfoHoldingErrorHolderTests.setUpNr   r   r   r   r   rO  Œ  rN  rO  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   rˆ   r   r   )r   Úblahr   r   r   r‰   ¨  rŠ   z.MalformedMethodTests.ContainMalformed.test_fooc                   C   rˆ   r   r   r   r   r   r   Útest_bar«  rŠ   z.MalformedMethodTests.ContainMalformed.test_barN)	r'   r(   r)   rO   r‰   rU  r   ÚinlineCallbacksÚ	test_spamr   r   r   r   ÚContainMalformed£  s
    rX  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}.
        rr   r"   N)r   r   rt   r   r  rS  rX  r[   r\   rQ   ri   rN   rZ   rÝ   )r   r7   r0   ÚtrialRunnerr@   ry   r   r   r   Ú_test°  s   

zMalformedMethodTests._testc                 C   ré   )zE
        Test when the method has extra (useless) arguments.
        r‰   N©rZ  r   r   r   r   Útest_extraArg¼  rê   z"MalformedMethodTests.test_extraArgc                 C   ré   )zJ
        Test when the method doesn't have even self as argument.
        rU  Nr[  r   r   r   r   Ú
test_noArgÂ  rê   zMalformedMethodTests.test_noArgc                 C   ré   )z5
        Test a decorated method also fails.
        rW  Nr[  r   r   r   r   Útest_decoratedÈ  rê   z#MalformedMethodTests.test_decoratedN)r'   r(   r)   rO   r�   rš   rX  rZ  r\  r]  r^  r   r   r   r   rS  ž  s    rS  c                   @   r)  )	Ú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                       r–   )z6DestructiveTestSuiteTests.test_basic.<locals>.MockTestc                    ó   ˆ   d¡ d S rû   r  r—   ©Úcalledr   r   r‰   Û  rU   z?DestructiveTestSuiteTests.test_basic.<locals>.MockTest.test_fooNr‹   r   ra  r   r   r˜   Ú  r™   r˜   r‰   Tr   N)	r�   rš   r   r/  r   ÚDestructiveTestSuiter\   r[   r-  ©r   r˜   r@   ry   r�   r   ra  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                    r`  )Nr"   r  r—   ra  r   r   Ú	test_foo1î  rU   zEDestructiveTestSuiteTests.test_shouldStop.<locals>.MockTest.test_foo1c                 S   s   t ƒ ‚r   )ÚKeyboardInterruptr—   r   r   r   Ú	test_foo2ñ  s   zEDestructiveTestSuiteTests.test_shouldStop.<locals>.MockTest.test_foo2c                    r`  )Nrg   r  r—   ra  r   r   Ú	test_foo3ô  rU   zEDestructiveTestSuiteTests.test_shouldStop.<locals>.MockTest.test_foo3N)r'   r(   r)   rf  rh  ri  r   ra  r   r   r˜   í  s    r˜   r"   N)r   rš   r   r/  r   rð   rc  ÚsuiteFactoryÚ	loadClassr\   r[   r-  )r   r˜   ry   ró   r�   r   ra  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                   @   r‡   )z8DestructiveTestSuiteTests.test_cleanup.<locals>.MockTestc                 S   rˆ   r   r   r—   r   r   r   r‰     rŠ   zADestructiveTestSuiteTests.test_cleanup.<locals>.MockTest.test_fooNr‹   r   r   r   r   r˜     r�   r˜   r‰   r"   r   N)	r�   rš   r   r/  r   rc  r\   r-  r[   rd  r   r   r   Útest_cleanup  s   
z&DestructiveTestSuiteTests.test_cleanupN)r'   r(   r)   rO   re  rl  rm  r   r   r   r   r_  Ï  s
    r_  c                   @   s&   e Zd ZG dd„ dejƒZdd„ 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   rˆ   r   r   r¶   r   r   r   ÚprintErrors  rŠ   z/RunnerDeprecationTests.FakeReporter.printErrorsc                 G   rˆ   r   r   r¶   r   r   r   ÚprintSummary"  rŠ   z0RunnerDeprecationTests.FakeReporter.printSummaryc                 G   rˆ   r   r   r¶   r   r   r   Úwrite%  rŠ   z)RunnerDeprecationTests.FakeReporter.writec                 G   rˆ   r   r   r¶   r   r   r   Úwriteln(  rŠ   z+RunnerDeprecationTests.FakeReporter.writeln)r'   r(   r)   rO   rC   rP   r0   ro  rp  rq  rr  r   r   r   r   ÚFakeReporter  s    rs  c                    s    t  d¡‰|  ¡ ‰ ‡ fdd„ˆ_‡fdd„}|ƒ  |  | jg¡}|  |d d t¡ |  |d d d	t 	ˆ j
¡ ¡ |  t |d d
 ¡¡ |  t|ƒd¡ dS )zk
        The runner emits a warning if it is using a result that doesn't
        implement 'done'.
        Nc                      s   ˆ S r   r   r   )ry   r   r   Ú<lambda>2  rD   zBRunnerDeprecationTests.test_reporterDeprecations.<locals>.<lambda>c                      s   ˆ   t d¡¡ d S )Nr0  )r[   r�   rš   r   )rY  r   r   Úf4  s   z;RunnerDeprecationTests.test_reporterDeprecations.<locals>.fr   ÚcategoryÚmessagezR%s should implement done() but doesn't. Falling back to printErrors() and friends.Úfilenamer"   )r   rt   rs  rv   ÚflushWarningsÚtest_reporterDeprecationsr\   ÚDeprecationWarningr   r®   r¾   rm   Ú__file__Ú
startswithrZ   )r   ru  Úwarningsr   )ry   rY  r   rz  +  s   


ÿþz0RunnerDeprecationTests.test_reporterDeprecationsN)r'   r(   r)   r   r  rs  rz  r   r   r   r   rn    s    rn  c                   @   r{   )Ú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.texasÚrangerÚwalkerÚtexasN)r¤   r   Ú_qualNameWalkerr\   )r   ÚwalkerResultsr   r   r   Útest_walksDownPathK  s   
ýþz+QualifiedNameWalkerTests.test_walksDownPathN)r'   r(   r)   rO   r…  r   r   r   r   r  F  r”   r  c                   @   r{   )Ú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_importDoesNothingc  r$  z0TrialMainDoesNothingTests.test_importDoesNothingN)r'   r(   r)   rO   rˆ  r   r   r   r   r†  ]  rN  r†  )@rÎ   rÿ   rP  r   r�   Úior   Útypingr   Úzope.interfacer   Úzope.interface.verifyr   Útwistedr   Útwisted.internetr   Útwisted.pluginsr   Útwisted.pythonr	   r
   r   Útwisted.python.filepathr   Útwisted.python.reflectr   Útwisted.scriptsr   Útwisted.trialr   r   r   Útwisted.trial._asyncrunnerr   Útwisted.trial.itrialr   r   r   r*   rR   rŽ   rq   r|   r€   r†   r•   r›   rœ   r  r  r"  rƒ   r%  r*  r4  r>  rL  rO  rS  r_  rn  r  r†  r   r   r   r   Ú<module>   s^   	Q<
ÿ,  KL$N1D3