o
    Óó·iÿ}  ã                   @   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   údC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-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   Z
shouldStopÚ_streamZ	_tbformatZ	_rterrorsÚ
_publisher)r   ÚstreamÚtbformatZrterrorsZ	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   r0   >   ó   zCapturingReporter.startTestc                 C   r/   )z}
        Report the status of a single test method
        @param method: an object that is adaptable to ITestMethod
        ÚstopTestNr#   r1   r   r   r   r4   E   r3   zCapturingReporter.stopTestc                 C   r/   )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   ó   zCapturingReporter.cleanupErrorsc                 C   s   | j  d¡ d S )NÚ
addSuccessr#   ©r   Útestr   r   r   r7   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   r;   )zD
        Do nothing. These tests don't care about addError.
        Nr   ©r   r9   Úerrorr   r   r   ÚaddErrorZ   r=   zCapturingReporter.addErrorc                 C   r;   )zF
        Do nothing. These tests don't care about addFailure.
        Nr   )r   r9   r	   r   r   r   Ú
addFailure_   r=   zCapturingReporter.addFailurec                 C   r;   )zN
        Do nothing. These tests don't care about addExpectedFailure.
        Nr   )r   r9   r	   Útodor   r   r   ÚaddExpectedFailured   r=   z$CapturingReporter.addExpectedFailurec                 C   r;   )zP
        Do nothing. These tests don't care about addUnexpectedSuccess.
        Nr   )r   r9   rB   r   r   r   ÚaddUnexpectedSuccessi   r=   z&CapturingReporter.addUnexpectedSuccessc                 C   r;   )zC
        Do nothing. These tests don't care about addSkip.
        Nr   )r   r9   Úreasonr   r   r   ÚaddSkipn   r=   zCapturingReporter.addSkipc                 C   r;   )zI
        Do nothing. These tests don't care about wasSuccessful.
        Nr   r   r   r   r   ÚwasSuccessfuls   r=   zCapturingReporter.wasSuccessful)NNNNr   )r'   r(   r)   Ú__doc__r-   r.   r%   Ú	separatorÚtestsRunr   r0   r4   r5   r7   r<   r@   rA   rC   rD   rF   rG   r   r   r   r   r*   '   s&    


r*   c                   @   ó0   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   r;   )z=
        Empty test method, used by the other tests.
        Nr   r   r   r   r   Ú
test_empty~   r=   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)ÚlenrN   r   Úrunr9   ÚassertEqual)r   ZoriginalCountZnewCountr   r   r   Útest_addObservers†   s   z'TrialRunnerTestsMixin.test_addObserversc                 C   sT   t | jjƒ | jj¡}tdƒD ]}| j | j¡ | ¡  |  	| 
¡ ¡ | ¡  qdS )z=
        Test that a new file is opened on each run.
        é   N)r   r   ÚworkingDirectoryÚchildÚlogfileÚrangerP   r9   ZrestatÚ
assertTrueÚexistsÚremove)r   ZlogPathÚir   r   r   Útest_logFileAlwaysActive�   s   
úz.TrialRunnerTestsMixin.test_logFileAlwaysActiveN)r'   r(   r)   rH   rM   rN   rR   r\   r   r   r   r   rL   y   s    
rL   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©r-   rM   ©r   r-   r   ÚTrialRunnerr*   r^   r9   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)   rH   rb   rg   r   r   r   r   r^   Ÿ   s    r^   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©r-   ZuncleanWarningsrM   r`   r   r   r   r   rb   »   s
   ÿz1TrialRunnerWithUncleanWarningsReporterTests.setUpN©r'   r(   r)   rH   rb   r   r   r   r   ri   ³   s    ri   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 )Nr_   )r
   r   r-   r   ra   r*   ZDRY_RUNÚmakeTestFixturesr   r   r   r   rb   É   s   ÿzDryRunMixin.setUpc                 C   r;   )zh
        Set C{self.test} and C{self.suite}, where C{self.suite} is an empty
        TestSuite.
        Nr   r   r   r   r   rm   Ñ   r=   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   rP   Ú	TestSuiterQ   r   re   r   r   r   rM   ×   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.
        ©r0   r7   r4   N)r   rP   r9   rQ   r   re   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   rP   r9   rQ   r
   r   r   r   r   Útest_testsNotRunç   s   zDryRunMixin.test_testsNotRunN)	r'   r(   r)   rH   rb   rm   rM   rp   rq   r   r   r   r   rl   Ã   s    rl   c                   @   rh   )Ú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)   ru   r   r   r   r   Ú
PyunitCaseõ   ó    rx   ru   )r   ÚSynchronousTestCaser9   Úpyunitrn   Úsuite©r   rx   r   r   r   rm   ô   ó   
z'SynchronousDryRunTests.makeTestFixturesN©r'   r(   r)   rH   rm   r   r   r   r   rr   ï   ó    rr   c                   @   rh   )Ú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 )Nru   )r
   r$   ©r9   r   r   r   ru     r:   z7DryRunTests.makeTestFixtures.<locals>.MockTest.test_fooNrw   r   r   r   r   ÚMockTest  ó    r„   ru   )r   ÚTestCaser9   r   rn   r|   )r   r„   r   r   r   rm     s   
zDryRunTests.makeTestFixturesNr   r   r   r   r   r�   ý   r€   r�   c                   @   rh   )Ú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                   @   rs   )z6PyUnitDryRunTests.makeTestFixtures.<locals>.PyunitCasec                 S   rt   r   r   r   r   r   r   ru     rv   z?PyUnitDryRunTests.makeTestFixtures.<locals>.PyunitCase.test_fooNrw   r   r   r   r   rx     ry   rx   ru   )r{   r†   r9   rn   r|   r}   r   r   r   rm     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                    sz   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
 ˆ_d S )NÚ.éÿÿÿÿzTest Helper ReporterzUtility for unit testing.Ú	capturing)ÚdescriptionZlongOptZshortOptÚklassc                    s,   ˆ  | t¡ ˆ tˆj| g|¢R i |¤Žƒ S r   )rQ   r   ÚlistÚoriginal)ZifaceÚaÚkw©Zpluginsr   r   r   Ú
getPlugins/  s    z%RunnerTests.setUp.<locals>.getPluginsro   é
   )r   ÚOptionsÚconfigr   Zqualr*   ÚsplitÚjoinr   Z	_Reporterr   r“   r�   ÚstandardReport)r   ÚpartsÚpackager�   r“   r   r’   r   rb     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�   >  r:   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    rQ   rc   Ú	__class__)r   rf   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    rc   rQ   r¢   r–   ©r   r   rf   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assertNotIsInstancerc   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    ÚassertIsInstancerc   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    rQ   rT   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 }|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ÚpathÚ
addCleanuprP   )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®   –  r6   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   rz   rP   ÚerrorsÚfailuresÚfailrQ   rU   )r   ÚfirstRunnerrf   Ú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 }|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   Z_WorkingDirectoryBusyrP   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   rz   rP   r¼   r½   r¾   )r   ZinitialDirectoryr¿   rf   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Ú
loadByNamerP   rQ   r™   r   )r   Ú	my_runnerÚloaderr|   rf   r   r   r   Útest_runner_normalÌ  s   ûÿ	
zRunnerTests.test_runner_normalc                 C   s   t  ¡ }| dd¡}| |¡S )NrË   T)r   rÌ   rÍ   rP   )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Ñ   rQ   r™   r   )r   rÎ   rÓ   rf   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                    ó
   dˆ _ d S ©NT©Úruncall_called©Úpdbr|   rf   r   r   r   r!   ø  r    z=RunnerTests.test_runnerDebuggerDefaultsToPdb.<locals>.runcallr!   N)
r�   r   ÚtouchrØ   ÚpatchrÚ   ÚPdbrÑ   r    rX   )r   Z	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!     r    zGRunnerTests.test_runnerDebuggerWithExplicitlyPassedPdb.<locals>.runcallr!   N)r�   rØ   rÜ   rÚ   rÝ   rÑ   r    rX   )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Ñ   rQ   r™   r   rÓ   )r   rÎ   rf   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    rc   r©   r   Z_ExitWrapperr¤   r   r   r   Útest_exitfirst0  s   zRunnerTests.test_exitfirstN)r'   r(   r)   rb   rœ   r�   r    r£   r¥   r¨   rª   r¬   rÁ   rÉ   rÐ   rÑ   rÔ   rÞ   rà   r   Z	cdebuggerrá   râ   r   r   r   r   rˆ     s(    !9$rˆ   c                   @   rs   )Ú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ã   ;  ry   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$   rO   r¾   r   r   r   r   ru   I  s   ÿz$UntilFailureTests.FailAfter.test_foo)r'   r(   r)   rH   ræ   r   Ú__annotations__ru   r   r   r   r   Ú	FailAfterB  s   
 ré   c                 C   s4   g t j_t  d¡| _tƒ | _tjtj	| jd�| _d S )Nru   r_   )
rå   ré   ræ   r9   r   r-   r   ra   r   ÚReporterr   r   r   r   rb   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   ÚrunUntilFailurer9   rQ   rJ   ÚassertFalserG   Ú_getFailuresre   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.
        N)rO   r½   re   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$   ©r9   Z	interface©Z	decoratedr   r   Údecoratek  ó   z@UntilFailureTests.test_runUntilFailureDecorate.<locals>.decorateró   r"   N)	rÜ   r   r   rë   r9   rQ   rJ   rO   r   ©r   ró   rf   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                    rï   r   rð   rñ   rò   r   r   ró   }  rô   zGUntilFailureTests.test_runUntilFailureForceGCDecorate.<locals>.decorateró   Tr"   rS   N)rÜ   r   r   Z_forceGarbageCollectionrë   r9   rQ   rJ   rO   r   r   rõ   r   rò   r   Ú#test_runUntilFailureForceGCDecoratev  s   þz5UntilFailureTests.test_runUntilFailureForceGCDecorateN)r'   r(   r)   r{   r†   ré   rb   rî   rí   rö   r÷   r   r   r   r   rå   A  s    
rå   c                   @   r]   )Ú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 )NTrj   )rå   rb   r   ra   r   rê   r-   r   r   r   r   rb   “  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.
        N)rO   Z_originalReporterr½   re   r   r   r   rí   ™  ó   z%UncleanUntilFailureTests._getFailuresN)r'   r(   r)   rH   rb   rí   r   r   r   r   rø   �  s    rø   c                   @   rh   )Ú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	   ÚFailurere   r   r   r   rP   ¦  s
   ÿzBreakingSuite.runN)r'   r(   r)   rH   rP   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   )ZflushLoggedErrorsrû   r   r   r   r   rœ   µ  ó   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   ÚLoggedSuiterQ   Ú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ú   rP   rQ   rO   r¼   ÚidZNOT_IN_TESTrX   Úcheckrû   )r   rf   r|   r   r   r   Útest_capturesErrorÀ  s   
z$LoggedErrorsTests.test_capturesErrorN)r'   r(   r)   rH   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 ©NrŒ   )rŒ   r   Z
TestHolderÚholderr   r   r   r   rb   Í  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)rQ   r
  r  rŒ   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)rd   r
  r   rX   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  r
  rP   rX   rG   rQ   rJ   re   r   r   r   Útest_runsWithStandardResultå  ó   z+TestHolderTests.test_runsWithStandardResultN)r'   r(   r)   rb   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                   @   rK   )z$ErrorHolderTestsMixin.TestResultStubz)
        Stub for L{TestResult}.
        c                 C   r   r   )r¼   r   r   r   r   r     r    z-ErrorHolderTestsMixin.TestResultStub.__init__c                 C   rt   r   r   r8   r   r   r   r0     rv   z.ErrorHolderTestsMixin.TestResultStub.startTestc                 C   rt   r   r   r8   r   r   r   r4     rv   z-ErrorHolderTestsMixin.TestResultStub.stopTestc                 C   s   | j  ||f¡ d S r   )r¼   r$   r>   r   r   r   r@     s   z-ErrorHolderTestsMixin.TestResultStub.addErrorN)r'   r(   r)   rH   r   r0   r4   r@   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  r
  rP   rì   rG   rQ   rJ   re   r   r   r   r    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)	r
  rP   rf   rQ   r¼   r?   Ú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
  rf   rQ   r¼   r?   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)rQ   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
  r?   rQ   )r   Úexpectedr   r   r   Ú	test_repr2  s   ÿzErrorHolderTestsMixin.test_reprN)r'   r(   r)   rH   ÚZeroDivisionErrorÚexceptionForTestsr  r  r  r  r  r  r   r   r   r   r  ð  s    



r  c                   @   rh   )Ú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 r	  )rŒ   r  r  r	   rý   r?   r   ÚErrorHolderr
  r  rf   r   r   r   r   rb   D  s   ÿz$FailureHoldingErrorHolderTests.setUpNrk   r   r   r   r   r  >  ó    r  c                   @   rh   )Ú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 r	  )rŒ   r  r  ÚsysÚexc_infor	   rý   r?   r   r  r
  r  rf   )r   ZexceptionInfor   r   r   rb   U  s   þz$ExcInfoHoldingErrorHolderTests.setUpNrk   r   r   r   r   r!  O  r   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   rt   r   r   )r   Zblahr   r   r   ru   k  rv   z.MalformedMethodTests.ContainMalformed.test_fooc                   C   rt   r   r   r   r   r   r   Útest_barn  rv   z.MalformedMethodTests.ContainMalformed.test_barN)	r'   r(   r)   rH   ru   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}.
        r_   r"   N)r   r   ra   r   rê   r$  r'  rP   rQ   rJ   rì   rG   rO   r¼   )r   r2   r-   ZtrialRunnerr9   rf   r   r   r   Ú_tests  s   

zMalformedMethodTests._testc                 C   rÆ   )zE
        Test when the method has extra (useless) arguments.
        ru   N©r(  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.
        r%  Nr)  r   r   r   r   Ú
test_noArg…  rÇ   zMalformedMethodTests.test_noArgc                 C   rÆ   )z5
        Test a decorated method also fails.
        r&  Nr)  r   r   r   r   Útest_decorated‹  rÇ   z#MalformedMethodTests.test_decoratedN)r'   r(   r)   rH   r{   r†   r'  r(  r*  r+  r,  r   r   r   r   r$  a  s    r$  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   ru   ž  r   z?DestructiveTestSuiteTests.test_basic.<locals>.MockTest.test_fooNrw   r   r/  r   r   r„   �  r…   r„   ru   Tr   N)	r{   r†   r   r  r   ÚDestructiveTestSuiterQ   rP   r  ©r   r„   r9   rf   r|   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                    r.  )Nr"   rð   rƒ   r/  r   r   Ú	test_foo1±  r   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.  )NrS   rð   rƒ   r/  r   r   Ú	test_foo3·  r   zEDestructiveTestSuiteTests.test_shouldStop.<locals>.MockTest.test_foo3N)r'   r(   r)   r4  r6  r7  r   r/  r   r   r„   °  s    r„   r"   N)r   r†   r   r  r   rÌ   r1  ZsuiteFactoryZ	loadClassrQ   rP   r  )r   r„   rf   rÏ   r|   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                   @   rs   )z8DestructiveTestSuiteTests.test_cleanup.<locals>.MockTestc                 S   rt   r   r   rƒ   r   r   r   ru   Ë  rv   zADestructiveTestSuiteTests.test_cleanup.<locals>.MockTest.test_fooNrw   r   r   r   r   r„   Ê  ry   r„   ru   r"   r   N)	r{   r†   r   r  r   r1  rQ   r  rP   r2  r   r   r   Útest_cleanupÄ  s   
z&DestructiveTestSuiteTests.test_cleanupN)r'   r(   r)   rH   r3  r8  r9  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   rt   r   r   rž   r   r   r   ÚprintErrorsâ  rv   z/RunnerDeprecationTests.FakeReporter.printErrorsc                 G   rt   r   r   rž   r   r   r   ÚprintSummaryå  rv   z0RunnerDeprecationTests.FakeReporter.printSummaryc                 G   rt   r   r   rž   r   r   r   Úwriteè  rv   z)RunnerDeprecationTests.FakeReporter.writec                 G   rt   r   r   rž   r   r   r   Úwritelnë  rv   z+RunnerDeprecationTests.FakeReporter.writeln)r'   r(   r)   rH   r<   rI   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                   @   rh   )Ú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)rŽ   r   Z_qualNameWalkerrQ   )r   ZwalkerResultsr   r   r   Útest_walksDownPathô  s   
ýþz+QualifiedNameWalkerTests.test_walksDownPathN)r'   r(   r)   rH   rB  r   r   r   r   r@  ï  r€   r@  c                   @   rh   )Ú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  rù   z0TrialMainDoesNothingTests.test_importDoesNothingN)r'   r(   r)   rH   rE  r   r   r   r   rC    r   rC  )@r¯   rÚ   r"  r   r{   Ú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*   rL   rz   r^   ri   rl   rr   r�   r‡   rˆ   rã   rå   rø   rn   rú   rÿ   r  r  r  r!  r$  r-  r:  r@  rC  r   r   r   r   Ú<module>   s^   	Q&
ÿ,  $L$N1D