o
    >h}                     @   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   ~/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/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   
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   )zcalled 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                   @   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   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)lenrW   r   runr@   assertEqual)r   originalCount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rangerY   r@   restat
assertTrueexistsremove)r   logPathir   r   r   test_logFileAlwaysActive   s   
z.TrialRunnerTestsMixin.test_logFileAlwaysActiveN)r'   r(   r)   rO   rT   rW   r]   ri   r   r   r   r   rS   y   s    
rS   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   rT   r   r0   r   TrialRunnerr*   rk   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   ro   rt   r   r   r   r   rk      s    rk   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   uncleanWarningsrT   rm   r   r   r   r   ro      s
   z1TrialRunnerWithUncleanWarningsReporterTests.setUpNr'   r(   r)   rO   ro   r   r   r   r   rv      s    rv   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 )Nrl   )r
   r   r0   r   rn   r*   DRY_RUNmakeTestFixturesr   r   r   r   ro      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   rY   	TestSuiterZ   r   rr   r   r   r   rT      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   rY   r@   rZ   r   rr   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   rY   r@   rZ   r
   r   r   r   r   test_testsNotRun   s   zDryRunMixin.test_testsNotRunN)	r'   r(   r)   rO   ro   r|   rT   r   r   r   r   r   r   rz      s    rz   c                   @   ru   )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                   @   ru   )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                   @   ru   )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                    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)descriptionlongOptshortOptklassc                    s,    | t  tj| g|R i | S r   )rZ   r   listoriginal)ifaceakwpluginsr   r   r   
getPlugins/  s    z%RunnerTests.setUp.<locals>.getPluginsr~   
   )r   Optionsconfigr   qualr*   splitjoinr   	_Reporterr   r   r   standardReport)r   partspackager   r   r   r   r   ro     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   >  rA   zRunnerTests.parseOptionsc                 C   s   t | j}t |_|S r   )r   _makeRunnerr   r   r0   )r   rr   r   r   	getRunnerA  s   zRunnerTests.getRunnerc                 C   s2   |  g  | jd }|  }| || j d S Nr   )r   r   r   rZ   rp   	__class__)r   rs   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   rp   rZ   r   r   r   r   rs   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   assertNotIsInstancerp   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   assertIsInstancerp   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   rZ   r_   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
addCleanuprY   )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   rY   errorsfailuresfailrZ   r`   )r   firstRunnerrs   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   _WorkingDirectoryBusyrY   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   rY   r   r   r   )r   initialDirectoryr   rs   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
loadByNamerY   rZ   r   r   )r   	my_runnerloaderr   rs   r   r   r   test_runner_normal  s   	
zRunnerTests.test_runner_normalc                 C   s   t  }|dd}||S )Nr   T)r   r   r   rY   )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   rZ   r   r   )r   r   r   rs   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   rs   r   r   r   r!     r    z=RunnerTests.test_runnerDebuggerDefaultsToPdb.<locals>.runcallr!   N)
r   r   touchr   patchr   Pdbr   r   rd   )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!     r    zGRunnerTests.test_runnerDebuggerWithExplicitlyPassedPdb.<locals>.runcallr!   N)r   r   r   r   r   r   r   rd   )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   rZ   r   r   r   )r   r   rs   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   rp   r   r   _ExitWrapperr   r   r   r   test_exitfirst0  s   zRunnerTests.test_exitfirstN)r'   r(   r)   ro   r   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_imports<  s   zTrialSuiteTests.test_importsN)r'   r(   r)   r  r   r   r   r   r  ;  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$   rX   r   r   r   r   r   r   I  s   z$UntilFailureTests.FailAfter.test_foo)r'   r(   r)   rO   r  r   __annotations__r   r   r   r   r   	FailAfterB  s   
 r
  c                 C   s4   g t j_t d| _t | _tjtj	| jd| _d S )Nr   rl   )
r  r
  r  r@   r   r0   r   rn   r   Reporterr   r   r   r   ro   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   runUntilFailurer@   rZ   rQ   assertFalserN   _getFailuresrr   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.
        )rX   r   rr   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   decoratek     z@UntilFailureTests.test_runUntilFailureDecorate.<locals>.decorater  r"   N)	r   r   r   r  r@   rZ   rQ   rX   r   r   r  rs   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"   r^   N)r   r   r   _forceGarbageCollectionr  r@   rZ   rQ   rX   r   r   r  r   r  r   #test_runUntilFailureForceGCDecoratev  s   z5UntilFailureTests.test_runUntilFailureForceGCDecorateN)r'   r(   r)   r   r   r
  ro   r  r  r  r  r   r   r   r   r  A  s    
r  c                   @   rj   )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 )NTrw   )r  ro   r   rn   r   r  r0   r   r   r   r   ro     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.
        )rX   _originalReporterr   rr   r   r   r   r       z%UncleanUntilFailureTests._getFailuresN)r'   r(   r)   rO   ro   r  r   r   r   r   r    s    r  c                   @   ru   )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	   Failurerr   r   r   r   rY     s
   zBreakingSuite.runN)r'   r(   r)   rO   rY   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   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   LoggedSuiterZ   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  rY   rZ   rX   r   idNOT_IN_TESTrd   checkr   )r   rs   r   r   r   r   test_capturesError  s   
z$LoggedErrorsTests.test_capturesErrorN)r'   r(   r)   rO   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   
TestHolderholderr   r   r   r   ro     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)rZ   r2  r+  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)rq   r2  r   rd   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*  r2  rY   rd   rN   rZ   rQ   rr   r   r   r   test_runsWithStandardResult     z+TestHolderTests.test_runsWithStandardResultN)r'   r(   r)   ro   r4  r5  r7  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                   @   rR   )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     r   z.ErrorHolderTestsMixin.TestResultStub.startTestc                 C   r   r   r   r?   r   r   r   r9     r   z-ErrorHolderTestsMixin.TestResultStub.stopTestc                 C   s   | j ||f d S r   )r   r$   rE   r   r   r   rG     s   z-ErrorHolderTestsMixin.TestResultStub.addErrorN)r'   r(   r)   rO   r   r5   r9   rG   r   r   r   r   TestResultStub  s    r:  c                 C   r6  )zd
        A L{runner.ErrorHolder} can run against the standard Python
        C{TestResult}.
        r"   N)r   r*  r2  rY   r  rN   rZ   rQ   rr   r   r   r   r7    r8  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)	r2  rY   rs   rZ   r   rF   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)r2  rs   rZ   r   rF   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)rZ   r2  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reprr2  rF   rZ   )r   expectedr   r   r   	test_repr2  s   zErrorHolderTestsMixin.test_reprN)r'   r(   r)   rO   ZeroDivisionErrorexceptionForTestsr:  r7  r>  r?  r@  rD  r   r   r   r   r9    s    



r9  c                   @   ru   )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 r0  )r   rF  rE  r	   r"  rF   r   ErrorHolderr2  r:  rs   r   r   r   r   ro   D  s   z$FailureHoldingErrorHolderTests.setUpNry   r   r   r   r   rG  >      rG  c                   @   ru   )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 r0  )r   rF  rE  sysexc_infor	   r"  rF   r   rH  r2  r:  rs   )r   exceptionInfor   r   r   ro   U  s   z$ExcInfoHoldingErrorHolderTests.setUpNry   r   r   r   r   rJ  O  rI  rJ  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   k  r   z.MalformedMethodTests.ContainMalformed.test_fooc                   C   r   r   r   r   r   r   r   test_barn  r   z.MalformedMethodTests.ContainMalformed.test_barN)	r'   r(   r)   rO   r   rP  r   inlineCallbacks	test_spamr   r   r   r   ContainMalformedf  s
    rS  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}.
        rl   r"   N)r   r   rn   r   r  rN  rS  rY   rZ   rQ   r  rN   rX   r   )r   r7   r0   trialRunnerr@   rs   r   r   r   _tests  s   

zMalformedMethodTests._testc                 C   r   )zE
        Test when the method has extra (useless) arguments.
        r   NrU  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.
        rP  NrV  r   r   r   r   
test_noArg  r   zMalformedMethodTests.test_noArgc                 C   r   )z5
        Test a decorated method also fails.
        rR  NrV  r   r   r   r   test_decorated  r   z#MalformedMethodTests.test_decoratedN)r'   r(   r)   rO   r   r   rS  rU  rW  rX  rY  r   r   r   r   rN  a  s    rN  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     r&  z?DestructiveTestSuiteTests.test_basic.<locals>.MockTest.test_fooNr   r   r\  r   r   r     r   r   r   Tr   N)	r   r   r   r*  r   DestructiveTestSuiterZ   rY   r(  r   r   r@   rs   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[  )Nr^   r  r   r\  r   r   	test_foo3  r&  zEDestructiveTestSuiteTests.test_shouldStop.<locals>.MockTest.test_foo3N)r'   r(   r)   ra  rc  rd  r   r\  r   r   r     s    r   r"   N)r   r   r   r*  r   r   r^  suiteFactory	loadClassrZ   rY   r(  )r   r   rs   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                   @   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   r^  rZ   r(  rY   r_  r   r   r   test_cleanup  s   
z&DestructiveTestSuiteTests.test_cleanupN)r'   r(   r)   rO   r`  rg  rh  r   r   r   r   rZ    s
    rZ  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   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   rj  rk  rl  rm  r   r   r   r   FakeReporter  s    rn  N)r'   r(   r)   r   r  rn  r   r   r   r   ri    s    ri  c                   @   ru   )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   _qualNameWalkerrZ   )r   walkerResultsr   r   r   test_walksDownPath  s   
z+QualifiedNameWalkerTests.test_walksDownPathN)r'   r(   r)   rO   ru  r   r   r   r   ro    r   ro  c                   @   ru   )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)   rO   rx  r   r   r   r   rv    rI  rv  )@r   r   rK  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*   rS   r   rk   rv   rz   r   r   r   r   r  r  r  r}   r  r$  r/  r9  rG  rJ  rN  rZ  ri  ro  rv  r   r   r   r   <module>   s^   	Q&
,  $L$N1D