
    Yf}                     L   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          Z& e
e$           G d d                      Z' G d d          Z( G d de(ej)                  Z* G d de(ej)                  Z+ G d d          Z, G d de,ej)                  Z- G d de,ej)                  Z. G d  d!e,ej)                  Z/ G d" d#ej)                  Z0 G d$ d%ej)                  Z1 G d& d'ej)                  Z2 G d( d)e2          Z3 G d* d+ej4                  Z5 G d, d-ej)                  Z6 G d. d/ej)                  Z7 G d0 d1          Z8 G d2 d3e8e7          Z9 G d4 d5e8e7          Z: G d6 d7ej)                  Z; G d8 d9ej)                  Z< G d: d;ej)                  Z= G d< d=ej)                  Z> G 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                       e Zd Zd Zd ZdS )CapturingDebuggerc                     g | _         d S N)_callsselfs    P/var/www/html/env/lib/python3.11/site-packages/twisted/trial/test/test_runner.py__init__zCapturingDebugger.__init__   s        c                 f    | j                             d            |d         |dd          i | d S )Nruncallr      r   append)r   argskwargss      r   r#   zCapturingDebugger.runcall"   s?    9%%%Qabb$V$$$$$r!   N)__name__
__module____qualname__r    r#    r!   r   r   r      s2          % % % % %r!   r   c                   t    e Zd ZdZdZdZdZdZdZddZ	d Z
d Zd Zd Zd Zd	 Zd
 ZddZddZd Zd ZdS )CapturingReporterzC
    Reporter that keeps a log of all actions performed on it.
    Nc                 Z    g | _         d| _        || _        || _        || _        || _        dS )z.
        Create a capturing reporter.
        FN)r   
shouldStop_stream	_tbformat	_rterrors
_publisher)r   streamtbformatrterrors	publishers        r   r    zCapturingReporter.__init__3   s2     !!#r!   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   methods     r   r:   zCapturingReporter.startTest>   s     
 	;'''''r!   c                 :    | j                             d           dS )z}
        Report the status of a single test method
        @param method: an object that is adaptable to ITestMethod
        stopTestNr%   r;   s     r   r>   zCapturingReporter.stopTestE   s     
 	:&&&&&r!   c                 :    | j                             d           dS )zcalled when the reactor has been left in a 'dirty' state
        @param errs: a list of L{twisted.python.failure.Failure}s
        cleanupErrorNr%   )r   errss     r   cleanupErrorszCapturingReporter.cleanupErrorsL   s      	>*****r!   c                 :    | j                             d           d S )N
addSuccessr%   r   tests     r   rD   zCapturingReporter.addSuccessR   s    <(((((r!   c                     dS )z@
        Do nothing. These tests don't care about done.
        Nr,   r   s    r   donezCapturingReporter.doneU         r!   c                     dS )zD
        Do nothing. These tests don't care about addError.
        Nr,   r   rF   errors      r   addErrorzCapturingReporter.addErrorZ   rI   r!   c                     dS )zF
        Do nothing. These tests don't care about addFailure.
        Nr,   )r   rF   r
   s      r   
addFailurezCapturingReporter.addFailure_   rI   r!   c                     dS )zN
        Do nothing. These tests don't care about addExpectedFailure.
        Nr,   )r   rF   r
   todos       r   addExpectedFailurez$CapturingReporter.addExpectedFailured   rI   r!   c                     dS )zP
        Do nothing. These tests don't care about addUnexpectedSuccess.
        Nr,   )r   rF   rQ   s      r   addUnexpectedSuccessz&CapturingReporter.addUnexpectedSuccessi   rI   r!   c                     dS )zC
        Do nothing. These tests don't care about addSkip.
        Nr,   )r   rF   reasons      r   addSkipzCapturingReporter.addSkipn   rI   r!   c                     dS )zI
        Do nothing. These tests don't care about wasSuccessful.
        Nr,   r   s    r   wasSuccessfulzCapturingReporter.wasSuccessfuls   rI   r!   )NNNNr   )r)   r*   r+   __doc__r5   r6   r'   	separatortestsRunr    r:   r>   rB   rD   rH   rM   rO   rR   rT   rW   rY   r,   r!   r   r.   r.   '   s          FHDIH	$ 	$ 	$ 	$( ( (' ' '+ + +) ) )  
  
  
   
   
  
    r!   r.   c                   *    e Zd ZdZd Zd Zd Zd ZdS )TrialRunnerTestsMixinz9
    Mixin defining tests for L{runner.TrialRunner}.
    c                     dS )z=
        Empty test method, used by the other tests.
        Nr,   r   s    r   
test_emptyz TrialRunnerTestsMixin.test_empty~   rI   r!   c                 $    t           j        j        S r   )r   theLogPublisher	observersr   s    r   _getObserversz#TrialRunnerTestsMixin._getObservers   s    ",,r!   c                     t          |                                           }| j                            | j                   t          |                                           }|                     ||           dS )zn
        Any log system observers L{TrialRunner.run} adds are removed by the
        time it returns.
        N)lenrd   r   runrF   assertEqual)r   originalCountnewCounts      r   test_addObserversz'TrialRunnerTestsMixin.test_addObservers   sh    
 D..0011	"""t))++,,=11111r!   c                 r   t          | j        j                                      | j        j                  }t          d          D ]p}| j                            | j                   |                                 | 	                    |
                                           |                                 qdS )z=
        Test that a new file is opened on each run.
           N)r   r   workingDirectorychildlogfilerangerg   rF   restat
assertTrueexistsremove)r   logPathis      r   test_logFileAlwaysActivez.TrialRunnerTestsMixin.test_logFileAlwaysActive   s     4;788>>t{?RSSq 	 	AKOODI&&&NNOOGNN,,--- NN	 	r!   N)r)   r*   r+   rZ   r`   rd   rk   rx   r,   r!   r   r^   r^   y   sZ           
- - -2 2 2    r!   r^   c                       e Zd ZdZd Zd ZdS )TrialRunnerTestszm
    Tests for L{runner.TrialRunner} with the feature to turn unclean errors
    into warnings disabled.
    c                     t                      | _        t          j        t          | j                  | _        t          d          | _        d S )Nr5   r`   r   r5   r   TrialRunnerr.   rz   rF   r   s    r   setUpzTrialRunnerTests.setUp   s:    jj():4;OOO$\22			r!   c                 x    | 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assertIdenticalr4   r   r   results     r   test_publisherzTrialRunnerTests.test_publisher   s6    
 ((**V.44444r!   N)r)   r*   r+   rZ   r   r   r,   r!   r   rz   rz      s<         
3 3 3
5 5 5 5 5r!   rz   c                       e Zd ZdZd ZdS )+TrialRunnerWithUncleanWarningsReporterTestsza
    Tests for the TrialRunner's interaction with an unclean-error suppressing
    reporter.
    c                     t                      | _        t          j        t          | j        d          | _        t          d          | _        d S )NTr5   uncleanWarningsr`   r}   r   s    r   r   z1TrialRunnerWithUncleanWarningsReporterTests.setUp   sD    jj(dk4
 
 
 %\22			r!   Nr)   r*   r+   rZ   r   r,   r!   r   r   r      s-         
3 3 3 3 3r!   r   c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )DryRunMixinze
    Mixin for testing that 'dry run' mode works with various
    L{pyunit.TestCase} subclasses.
    c                     g | _         t                      | _        t          j        t
          t          j        j        | j                  | _        |                                  d S )Nr|   )r   r   r5   r   r~   r.   DRY_RUNmakeTestFixturesr   s    r   r   zDryRunMixin.setUp   sV    jj(v19$+
 
 
 	r!   c                     dS )zh
        Set C{self.test} and C{self.suite}, where C{self.suite} is an empty
        TestSuite.
        Nr,   r   s    r   r   zDryRunMixin.makeTestFixtures   rI   r!   c                     | j                             t          j                              }|                     |j        g            dS )zf
        If there are no tests, the reporter should not receive any events to
        report.
        N)r   rg   	TestSuiterh   r   r   s     r   r`   zDryRunMixin.test_empty   s>    
 !1!3!344+++++r!   c                 ~    | 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.
        r:   rD   r>   N)r   rg   rF   rh   r   r   s     r   test_singleCaseReportingz$DryRunMixin.test_singleCaseReporting   s>    
 ++(O(O(OPPPPPr!   c                 z    | j                             | j                   |                     | j        g            dS )zT
        When we are doing a dry run, the tests should not actually be run.
        N)r   rg   rF   rh   r   r   s    r   test_testsNotRunzDryRunMixin.test_testsNotRun   s8     		"""2&&&&&r!   N)	r)   r*   r+   rZ   r   r   r`   r   r   r,   r!   r   r   r      sl         
       , , ,Q Q Q' ' ' ' 'r!   r   c                       e Zd ZdZd ZdS )SynchronousDryRunTestszS
    Check that 'dry run' mode works well with trial's L{SynchronousTestCase}.
    c                      G d dt           j                  } |d          | _        t          j                    | _        d S )Nc                       e Zd Zd ZdS );SynchronousDryRunTests.makeTestFixtures.<locals>.PyunitCasec                     d S r   r,   r   s    r   test_foozDSynchronousDryRunTests.makeTestFixtures.<locals>.PyunitCase.test_foo       r!   Nr)   r*   r+   r   r,   r!   r   
PyunitCaser      #            r!   r   r   )r   SynchronousTestCaserF   pyunitr   suiter   r   s     r   r   z'SynchronousDryRunTests.makeTestFixtures   sV    	 	 	 	 	5 	 	 	 Jz**	%''


r!   Nr)   r*   r+   rZ   r   r,   r!   r   r   r      -         ( ( ( ( (r!   r   c                       e Zd ZdZd ZdS )DryRunTestsz@
    Check that 'dry run' mode works well with Trial tests.
    c                       G  fddt           j                  } |d           _        t          j                     _        d S )Nc                       e Zd Z fdZdS ).DryRunTests.makeTestFixtures.<locals>.MockTestc                 <    j                             d           d S )Nr   )r   r&   )rF   r   s    r   r   z7DryRunTests.makeTestFixtures.<locals>.MockTest.test_foo  s    
+++++r!   Nr   r   s   r   MockTestr     s.        , , , , , , ,r!   r   r   )r   TestCaserF   r   r   r   )r   r   s   ` r   r   zDryRunTests.makeTestFixtures  sa    	, 	, 	, 	, 	, 	, 	,x( 	, 	, 	, HZ((	%''


r!   Nr   r,   r!   r   r   r      r   r!   r   c                       e Zd ZdZd ZdS )PyUnitDryRunTestszJ
    Check that 'dry run' mode works well with stdlib unittest tests.
    c                      G d dt           j                  } |d          | _        t          j                    | _        d S )Nc                       e Zd Zd ZdS )6PyUnitDryRunTests.makeTestFixtures.<locals>.PyunitCasec                     d S r   r,   r   s    r   r   z?PyUnitDryRunTests.makeTestFixtures.<locals>.PyunitCase.test_foo  r   r!   Nr   r,   r!   r   r   r     r   r!   r   r   )r   r   rF   r   r   r   s     r   r   z"PyUnitDryRunTests.makeTestFixtures  sU    	 	 	 	 	 	 	 	 Jz**	%''


r!   Nr   r,   r!   r   r   r     r   r!   r   c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Z e            Zd Zd ZdS )RunnerTestsc                 p    t          j                     _        t          j        t
                                        d          }d                    |d d                   }|d         }t          j	        d|ddd |          g fd}t          j         _        |t          _        g dd	z   _        d S )
N.zTest Helper ReporterzUtility for unit testing.	capturing)descriptionlongOptshortOptklassc                 |                         | t                     t           j        | g|R i |          z   S r   )rh   r   listoriginal)ifaceakwpluginsr   s      r   
getPluginsz%RunnerTests.setUp.<locals>.getPlugins/  sH    UI...T-$-"@"@"@"@R"@"@AAAAr!   r   
   )r   Optionsconfigr   qualr.   splitjoinr	   	_Reporterr   r   r   standardReport)r   partspackager   r   r   s   `    @r   r   zRunnerTests.setUp  s    moo .//55c::((5":&&b	#&7#  	
	B 	B 	B 	B 	B 	B )&
 FEEJr!   c                 (    | j         t          _        d S r   )r   r   r   r   s    r   tearDownzRunnerTests.tearDown;  s     Mr!   c                 :    | j                             |           d S r   )r   parseOptionsr   r'   s     r   r   zRunnerTests.parseOptions>  s      &&&&&r!   c                 ^    t          j        | j                  }t                      |_        |S r   )r   _makeRunnerr   r   r5   )r   rs     r   	getRunnerzRunnerTests.getRunnerA  s$    dk**::r!   c                     |                      g            | j        d         }|                                 }|                     | |j                    j                   d S Nr   )r   r   r   rh   r   	__class__)r   r   r   s      r   test_runner_can_get_reporterz(RunnerTests.test_runner_can_get_reporterF  s\    "Z(!!!3!3!5!5!?@@@@@r!   c                     |                      g            |                                 } |j                    }|                     |j        | j        d                    d S r   )r   r   r   rh   r   r   r   r   r   s      r   test_runner_get_resultz"RunnerTests.test_runner_get_resultL  s[    "!!##%%)4;z+BCCCCCr!   c                     |                      g            |                                 }|                      |j                    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   assertNotIsInstancer   r   UncleanWarningsReporterWrapperr   r   s     r    test_uncleanWarningsOffByDefaultz,RunnerTests.test_uncleanWarningsOffByDefaultR  s\     	"!!  F  ("I	
 	
 	
 	
 	
r!   c                     |                      dg           |                                 }|                      |j                    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   assertIsInstancer   r   r   r   s     r   test_getsUncleanWarningsz$RunnerTests.test_getsUncleanWarnings^  s`     	/0111!!F  ("I	
 	
 	
 	
 	
r!   c                     |                      ddg           |                                 }|                     |j        d           d S )N--temp-directory	some_path)r   r   rh   rn   r   s     r   test_runner_working_directoryz)RunnerTests.test_runner_working_directoryj  sJ    -{;<<<!!0+>>>>>r!   c                    |                      g            |                     t          j        t          j                               t          |                                                                            t          j        j                   | 	                                }| 	                                i  G fddt          j                  |                     d                    }|j        |j        z   }|r!|                     |d         d                    |                                         d          j                            d          j        d           d	S )
z
        If no working directory is explicitly specified and the default
        working directory is in use by another runner, L{TrialRunner.run}
        selects a different default working directory to use.
        c                   *    e Zd Z fdZfdZdS )KRunnerTests.test_concurrentImplicitWorkingDirectory.<locals>.ConcurrentCasec                     t          j                    xd<   }t          j        j                   |                     t           j        |                                d                     dS )z
                Start a second test run which will have a default working
                directory which is the same as the working directory of the
                test run already in progress.
                
concurrenttest_secondN)osgetcwdchdirpath
addCleanuprg   )r   subsequentDirectoryConcurrentCaserunDirectorysecondRunnerwheres     r   
test_firstzVRunnerTests.test_concurrentImplicitWorkingDirectory.<locals>.ConcurrentCase.test_first  si     =?IKKGl#&9*+++*=>>>  !>!>?????r!   c                 4    t          j                    d<   dS )zR
                Record the working directory for later analysis.
                recordN)r   r   )r   r   s    r   r   zWRunnerTests.test_concurrentImplicitWorkingDirectory.<locals>.ConcurrentCase.test_second  s     #%)++hr!   N)r)   r*   r+   r   r   )r   r   r   r   s   r   r   r     s^        @ @ @ @ @ @ @ @. . . . . . .r!   r   r   r   r$   _trial_tempz_trial_temp-1)r   r  N)r   r   r   r   r   r   mktempmakedirsr   r   r   r   rg   errorsfailuresfailrh   ro   )r   firstRunnerr   badr   r   r   r   s       @@@@r   'test_concurrentImplicitWorkingDirectoryz3RunnerTests.test_concurrentImplicitWorkingDirectoryo  s    	" 	")++...
  ..
"###nn&&~~''	. 	. 	. 	. 	. 	. 	. 	. 	. 	.X9 	. 	. 	.* !=!=>>mfo- 	!IIc!fQi   *00??D&,,_==B 	
 	
 	
 	
 	
r!   c                 &   |                      dt          j                            |                                           g           t          j                    }|                     t          j        |           |                                 }|                                  G fddt          j
                  |                     d                    }|j        |j        z   }|r#|                     |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                   "    e Zd Z fdZd ZdS )KRunnerTests.test_concurrentExplicitWorkingDirectory.<locals>.ConcurrentCasec                 f    |                      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   _WorkingDirectoryBusyrg   )r   r   r   s    r   test_concurrentz[RunnerTests.test_concurrentExplicitWorkingDirectory.<locals>.ConcurrentCase.test_concurrent  s@    
 !!. $"N>22    r!   c                 0    |                      d           dS )zE
                Should not be called, always fails.
                z$test_failure should never be called.N)r  r   s    r   r  zXRunnerTests.test_concurrentExplicitWorkingDirectory.<locals>.ConcurrentCase.test_failure  s     		@AAAAAr!   N)r)   r*   r+   r  r  )r   r   s   r   r   r    sG        	 	 	 	 	 	B B B B Br!   r   r  r   r$   N)r   r   r   abspathr  r   r   r   r   r   r   rg   r  r  r  )r   initialDirectoryr	  r   r
  r   r   s        @@r   'test_concurrentExplicitWorkingDirectoryz3RunnerTests.test_concurrentExplicitWorkingDirectory  s   
 	-rwt{{}}/M/MNOOO9;;"2333nn&&~~''	B 	B 	B 	B 	B 	B 	B 	BX9 	B 	B 	B$ 0A!B!BCCmfo- 	!IIc!fQi     	! 	!r!   c                 B   |                      d|                                 dddg           |                                 }t          j                    }|                    dd          }|                    |          }|                     | j        |j	                   d S )Nr   
--reporterr   twisted.trial.test.sampleT)
r   r  r   r   
TestLoader
loadByNamerg   rh   r   r   )r   	my_runnerloaderr   r   s        r   test_runner_normalzRunnerTests.test_runner_normal  s    "+	
 	
 	
 NN$$	"$$!!"=tDDu%%,fm<<<<<r!   c                 ~    t          j                    }|                    dd          }|                    |          S )Nr  T)r   r  r  rg   )r   r  r  r   s       r   runSampleSuitezRunnerTests.runSampleSuite  s8    "$$!!"=tDD}}U###r!   c                 (   |                      g d           |                                 }t                      x}|_        |                     |          }|                     | 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!  rh   r   r   )r   r  r$  r   s       r   test_runnerDebugzRunnerTests.test_runnerDebug  s     	OOO	
 	
 	
 NN$$	(9(;(;;9%$$Y//,fm<<<)ho66666r!   c                 X                          ddg           t          d          }|                                 d _         f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   r   r   s      r   r#   z=RunnerTests.test_runnerDebuggerDefaultsToPdb.<locals>.runcall      "&Dr!   r#   N)
r   r   touchr+  patchr-  Pdbr!  r   rs   )r   	pdbrcFiler#   s   `  r    test_runnerDebuggerDefaultsToPdbz,RunnerTests.test_runnerDebuggerDefaultsToPdb  s     	9&ABCCCW%%	#	' 	' 	' 	' 	' 	

37Iw///DNN,,---+,,,,,r!   c                                           g d           d _         f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                     d_         d S r)  r*  r,  s      r   r#   zGRunnerTests.test_runnerDebuggerWithExplicitlyPassedPdb.<locals>.runcall  r.  r!   r#   N)r   r+  r0  r-  r1  r!  r   rs   )r   r#   s   ` r   *test_runnerDebuggerWithExplicitlyPassedPdbz6RunnerTests.test_runnerDebuggerWithExplicitlyPassedPdb  s     	  		
 		
 		
 $	' 	' 	' 	' 	' 	

37Iw///DNN,,---+,,,,,r!   c                    |                      g d           |                                 }|                     |          }|                     | j        |j                   |                     dg|j        j                   dS )zM
        Trial uses specified debugger if the debugger is available.
        )r  r   r5  z4twisted.trial.test.test_runner.RunnerTests.cdebuggerr#  r  r#   N)r   r   r!  rh   r   r   r$  )r   r  r   s      r   test_runnerDebuggerzRunnerTests.test_runnerDebugger  s     	  		
 		
 		
 NN$$	$$Y//,fm<<<)i&8&?@@@@@r!   c                     |                      dg           |                                 } |j                    }|                     |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   r   r   r   _ExitWrapperr   s      r   test_exitfirstzRunnerTests.test_exitfirst0  sX    
 	=/***!!##%%fh&;<<<<<r!   N)r)   r*   r+   r   r   r   r   r   r   r   r   r   r  r  r  r!  r%  r3  r7  r   	cdebuggerr9  r<  r,   r!   r   r   r     sA       K K KB* * *' ' '  
A A AD D D

 

 



 

 

? ? ?
7
 7
 7
r"! "! "!H= = = $ $ $
7 7 7- - -&- - -4 "!##IA A A&= = = = =r!   r   c                       e Zd Zd ZdS )TrialSuiteTestsc                 $    t          d           d S )Nztwisted.trial.runner.TrialSuiter   r   s    r   test_importszTrialSuiteTests.test_imports<  s    233333r!   N)r)   r*   r+   rA  r,   r!   r   r?  r?  ;  s#        4 4 4 4 4r!   r?  c                   R    e Zd Z G d dej                  Zd Zd Zd Zd Z	d Z
dS )	UntilFailureTestsc                   4    e Zd ZU dZg Zed         ed<   d ZdS )UntilFailureTests.FailAfterzC
        A test case that fails when run 3 times in a row.
        Ncountc                     | j                             d            t          | j                   dk    r|                     d           d S d S )N   zCount reached 3)rF  r&   rf   r  r   s    r   r   z$UntilFailureTests.FailAfter.test_fooI  sL    Jd###4:!##		+,,,,, $#r!   )r)   r*   r+   rZ   rF  r   __annotations__r   r,   r!   r   	FailAfterrE  B  sE         	 	 tDz	- 	- 	- 	- 	-r!   rJ  c                     g t           j        _        t                               d          | _        t	                      | _        t          j        t          j	        | j                  | _        d S )Nr   r|   )
rC  rJ  rF  rF   r   r5   r   r~   r   Reporterr   s    r   r   zUntilFailureTests.setUpN  sN    ,.#)%//
;;	jj():4;OOOr!   c                    | 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   runUntilFailurerF   rh   r\   assertFalserY   _getFailuresr   s     r   test_runUntilFailurez&UntilFailureTests.test_runUntilFailureT  s}    
 ,,TY77!,,,--//000**622A66666r!   c                 *    t          |j                  S )zL
        Get the number of failures that were reported to a result.
        )rf   r  r   s     r   rP  zUntilFailureTests._getFailures^  s     6?###r!   c                 N   g f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                 6                         | |f           | S r   r&   rF   	interface	decorateds     r   decoratez@UntilFailureTests.test_runUntilFailureDecorate.<locals>.decoratek  !    dI.///Kr!   rY  r$   N)	r0  r   r   rN  rF   rh   r\   rf   r   r   rY  r   rX  s      @r   test_runUntilFailureDecoratez.UntilFailureTests.test_runUntilFailureDecorated  s    
 		 	 	 	 	 	

8Z222,,TY77!,,,Y+++di%;$<=====r!   c                    g f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                 6                         | |f           | S r   rU  rV  s     r   rY  zGUntilFailureTests.test_runUntilFailureForceGCDecorate.<locals>.decorate}  rZ  r!   rY  Tr$   rm   N)r0  r   r   _forceGarbageCollectionrN  rF   rh   r\   rf   r   r   r[  s      @r   #test_runUntilFailureForceGCDecoratez5UntilFailureTests.test_runUntilFailureForceGCDecoratev  s    
 		 	 	 	 	 	

8Z222.2+,,TY77!,,,Y+++i#di1Q%RS	
 	
 	
 	
 	
r!   N)r)   r*   r+   r   r   rJ  r   rQ  rP  r\  r`  r,   r!   r   rC  rC  A  s        
- 
- 
- 
- 
-FO 
- 
- 
-P P P7 7 7$ $ $> > >$
 
 
 
 
r!   rC  c                       e Zd ZdZd Zd ZdS )UncleanUntilFailureTestszh
    Test that the run-until-failure feature works correctly with the unclean
    error suppressor.
    c                     t                               |            t          j        t          j        | j        d          | _        d S )NTr   )rC  r   r   r~   r   rL  r5   r   s    r   r   zUncleanUntilFailureTests.setUp  s?    %%%(dk4
 
 
r!   c                 4    t          |j        j                  S )z
        Get the number of failures that were reported to a result that
        is wrapped in an UncleanFailureWrapper.
        )rf   _originalReporterr  r   s     r   rP  z%UncleanUntilFailureTests._getFailures  s    
 6+4555r!   N)r)   r*   r+   rZ   r   rP  r,   r!   r   rb  rb    s<         

 
 
6 6 6 6 6r!   rb  c                       e Zd ZdZd ZdS )BreakingSuitez;
    A L{TestSuite} that logs an error when it is run.
    c                     	 t          d          # t           $ r) t          j        t          j                               Y d S w xY w)Nz#error that occurs outside of a test)RuntimeErrorr   errr
   Failurer   s     r   rg   zBreakingSuite.run  sR    	'DEEE 	' 	' 	'GGO%%&&&&&&	's    /AAN)r)   r*   r+   rZ   rg   r,   r!   r   rg  rg    s-         ' ' ' ' 'r!   rg  c                   $    e Zd ZdZd Zd Z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                 :    |                      t                     d S r   )flushLoggedErrorsri  r   s    r   r   zLoggedErrorsTests.tearDown  s    |,,,,,r!   c                 |    t          j                    }|                     |                                d           dS )zg
        Check that we can construct a L{runner.LoggedSuite} and that it
        starts empty.
        r   N)r   LoggedSuiterh   countTestCases)r   r   s     r   test_constructz LoggedErrorsTests.test_construct  s:    
 "$$--//33333r!   c                    t          j                    }t          j        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   rq  rg  rg   rh   rf   r  idNOT_IN_TESTrs   checkri  )r   r   r   s      r   test_capturesErrorz$LoggedErrorsTests.test_capturesError  s     $&&"MOO#455		&V]++Q///q)!,//1163EFFFa(+11,??@@@@@r!   N)r)   r*   r+   rZ   r   rs  ry  r,   r!   r   rm  rm    sP         - - -4 4 4	A 	A 	A 	A 	Ar!   rm  c                   &    e Zd Zd Zd Zd Zd ZdS )TestHolderTestsc                 P    d| _         t          j        | j                   | _        d S Nr   )r   r   
TestHolderholderr   s    r   r   zTestHolderTests.setUp  s#    ('(899r!   c                     |                      | j                                        | j                   |                      | j                                        | j                   dS )z
        Check that L{runner.TestHolder} takes a description as a parameter
        and that this description is returned by the C{id} and
        C{shortDescription} methods.
        N)rh   r  rv  r   shortDescriptionr   s    r   test_holderzTestHolderTests.test_holder  sV     	))4+;<<<55779IJJJJJr!   c                     |                      | j        t          | j                             |                     t	          t          | j                  | j        dt          d           dS )z?
        L{runner.TestHolder} implements L{ITestCase}.
        z claims to provide z but does not do so correctly.N)r   r  r   rs   r   r   s    r   test_holderImplementsITestCasez.TestHolderTests.test_holderImplementsITestCase  si     	T[)DK*@*@AAADK00{{{III'	
 	
 	
 	
 	
r!   c                     t          j                    }| j                            |           |                     |                                           |                     d|j                   dS )zc
        A L{runner.TestHolder} can run against the standard Python
        C{TestResult}.
        r$   N)r   ru  r  rg   rs   rY   rh   r\   r   s     r   test_runsWithStandardResultz+TestHolderTests.test_runsWithStandardResult  sb    
 "$$,,..///FO,,,,,r!   N)r)   r*   r+   r   r  r  r  r,   r!   r   r{  r{    sS        : : :K K K	
 	
 	
- - - - -r!   r{  c                   `    e Zd ZdZ ed          Z G d d          Zd Zd Zd Z	d Z
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                   *    e Zd ZdZd Zd Zd Zd ZdS )$ErrorHolderTestsMixin.TestResultStubz)
        Stub for L{TestResult}.
        c                     g | _         d S r   )r  r   s    r   r    z-ErrorHolderTestsMixin.TestResultStub.__init__  s    DKKKr!   c                     d S r   r,   rE   s     r   r:   z.ErrorHolderTestsMixin.TestResultStub.startTest      Dr!   c                     d S r   r,   rE   s     r   r>   z-ErrorHolderTestsMixin.TestResultStub.stopTest  r  r!   c                 >    | j                             ||f           d S r   )r  r&   rK   s      r   rM   z-ErrorHolderTestsMixin.TestResultStub.addError  s"    Ke}-----r!   N)r)   r*   r+   rZ   r    r:   r>   rM   r,   r!   r   TestResultStubr    sZ        	 		 	 		 	 		 	 		. 	. 	. 	. 	.r!   r  c                     t          j                    }| j                            |           |                     |                                           |                     d|j                   dS )zd
        A L{runner.ErrorHolder} can run against the standard Python
        C{TestResult}.
        r$   N)r   ru  r  rg   rO  rY   rh   r\   r   s     r   r  z1ErrorHolderTestsMixin.test_runsWithStandardResult  sd    
 "$$--//000FO,,,,,r!   c                     | j                             | j                   |                     | j        j        | j         | j        j        | j        j        | j        j        ffg           dS )zM
        L{runner.ErrorHolder} adds an error to the result when run.
        N)	r  rg   r   rh   r  rL   typevaluetbr   s    r   test_runzErrorHolderTestsMixin.test_run  se     	$$$KkDJOTZ-=tz}MNO	
 	
 	
 	
 	
r!   c                     |                      | j                   |                     | j        j        | j         | j        j        | j        j        | j        j        ffg           dS )zP
        L{runner.ErrorHolder} adds an error to the result when called.
        N)r  r   rh   r  rL   r  r  r  r   s    r   	test_callzErrorHolderTestsMixin.test_call"  sc     	DK   KkDJOTZ-=tz}MNO	
 	
 	
 	
 	
r!   c                 `    |                      | j                                        d           dS )zH
        L{runner.ErrorHolder.countTestCases} always returns 0.
        r   N)rh   r  rr  r   s    r   test_countTestCasesz)ErrorHolderTestsMixin.test_countTestCases,  s.     	3355q99999r!   c                     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  rL   rh   )r   expecteds     r   	test_reprzErrorHolderTestsMixin.test_repr2  sW    
 IOO"1%&&
 
 	dk**H55555r!   N)r)   r*   r+   rZ   ZeroDivisionErrorexceptionForTestsr  r  r  r  r  r  r,   r!   r   r  r    s          *)*NOO. . . . . . . ."- - -
 
 

 
 
: : :	6 	6 	6 	6 	6r!   r  c                       e Zd ZdZd ZdS )FailureHoldingErrorHolderTestsz
    Tests for L{runner.ErrorHolder} behaving similarly to L{runner.TestHolder}
    when constructed with a L{Failure} representing its error.
    c                     d| _         	 | j        # t          $ r t          j                    | _        Y nw xY wt          j        | j         | j                  | _        | 	                                | _
        d S r}  )r   r  r  r
   rk  rL   r   ErrorHolderr  r  r   r   s    r   r   z$FailureHoldingErrorHolderTests.setUpD  sv    (	+((  	+ 	+ 	+ **DJJJ	+()94:FF))++s    "55Nr   r,   r!   r   r  r  >  s-         
, , , , ,r!   r  c                       e Zd ZdZd ZdS )ExcInfoHoldingErrorHolderTestsz
    Tests for L{runner.ErrorHolder} behaving similarly to L{runner.TestHolder}
    when constructed with a C{exc_info}-style tuple representing its error.
    c                 
   d| _         	 | j        # t          $ r. t          j                    }t          j                    | _        Y nw xY wt          j	        | j         |          | _
        |                                 | _        d S r}  )r   r  r  sysexc_infor
   rk  rL   r   r  r  r  r   )r   exceptionInfos     r   r   z$ExcInfoHoldingErrorHolderTests.setUpU  s    (	+((  	+ 	+ 	+LNNM **DJJJ	+ ()9=II))++s    5AANr   r,   r!   r   r  r  O  s-         
	, 	, 	, 	, 	,r!   r  c                   P    e Zd ZdZ G d dej                  Zd Zd Zd Z	d Z
dS )	MalformedMethodTestszR
    Test that trial manages when test methods don't have correct signatures.
    c                   >    e Zd ZdZd Zd Z ej        e          ZdS )%MalformedMethodTests.ContainMalformedzV
        This TestCase holds malformed test methods that trial should handle.
        c                     d S r   r,   )r   blahs     r   r   z.MalformedMethodTests.ContainMalformed.test_fook  r  r!   c                      d S r   r,   r,   r!   r   test_barz.MalformedMethodTests.ContainMalformed.test_barn  r  r!   N)	r)   r*   r+   rZ   r   r  r   inlineCallbacks	test_spamr,   r!   r   ContainMalformedr  f  sJ        	 		 	 		 	 	 *E)(33			r!   r  c                    t                      }t          j        t          j        |          }t
                              |          }|                    |          }|                     |j	        d           | 
                    |                                           |                     t          |j                  d           dS )zL
        Wrapper for one of the test method of L{ContainMalformed}.
        r|   r$   N)r   r   r~   r   rL  r  r  rg   rh   r\   rO  rY   rf   r  )r   r<   r5   trialRunnerrF   r   s         r   _testzMalformedMethodTests._tests  s     ():6JJJ#44V<<&&!,,,--//000V]++Q/////r!   c                 0    |                      d           dS )zE
        Test when the method has extra (useless) arguments.
        r   Nr  r   s    r   test_extraArgz"MalformedMethodTests.test_extraArg       	

:r!   c                 0    |                      d           dS )zJ
        Test when the method doesn't have even self as argument.
        r  Nr  r   s    r   
test_noArgzMalformedMethodTests.test_noArg  r  r!   c                 0    |                      d           dS )z5
        Test a decorated method also fails.
        r  Nr  r   s    r   test_decoratedz#MalformedMethodTests.test_decorated  s     	

;r!   N)r)   r*   r+   rZ   r   r   r  r  r  r  r  r,   r!   r   r  r  a  s         4 4 4 4 46? 4 4 4
0 
0 
0             r!   r  c                   $    e Zd ZdZd Zd Zd ZdS )DestructiveTestSuiteTestsz2
    Test for L{runner.DestructiveTestSuite}.
    c                 z   g  G fddt           j                  } |d          }t          j                    }t	          j        |g          }|                     g            |                    |           |                     dg           |                     |                                d           dS )zL
        Thes destructive test suite should run the tests normally.
        c                       e Zd Z fdZdS )6DestructiveTestSuiteTests.test_basic.<locals>.MockTestc                 2                         d           d S r)  rU  rF   calleds    r   r   z?DestructiveTestSuiteTests.test_basic.<locals>.MockTest.test_foo  s    d#####r!   Nr   r  s   r   r   r    s.        $ $ $ $ $ $ $r!   r   r   Tr   N)	r   r   r   ru  r   DestructiveTestSuiterh   rg   rr  )r   r   rF   r   r   r  s        @r   
test_basicz$DestructiveTestSuiteTests.test_basic  s     	$ 	$ 	$ 	$ 	$ 	$ 	$v 	$ 	$ 	$ x
##$&&+TF33$$$		&$(((--//33333r!   c                    g  G fddt           j                  }t          j                    }t	          j                    }t          j        |_        |                    |          }| 	                    g            |
                    |           | 	                    dg           | 	                    |                                d           dS )zu
        Test the C{shouldStop} management: raising a C{KeyboardInterrupt} must
        interrupt the suite.
        c                   *    e Zd Z fdZd Z fdZdS );DestructiveTestSuiteTests.test_shouldStop.<locals>.MockTestc                 2                         d           d S )Nr$   rU  r  s    r   	test_foo1zEDestructiveTestSuiteTests.test_shouldStop.<locals>.MockTest.test_foo1      a     r!   c                     t                      r   )KeyboardInterruptrF   s    r   	test_foo2zEDestructiveTestSuiteTests.test_shouldStop.<locals>.MockTest.test_foo2  s    ')))r!   c                 2                         d           d S )Nrm   rU  r  s    r   	test_foo3zEDestructiveTestSuiteTests.test_shouldStop.<locals>.MockTest.test_foo3  r  r!   N)r)   r*   r+   r  r  r  r  s   r   r   r    sV        ! ! ! ! !* * *! ! ! ! ! ! !r!   r   r$   N)r   r   r   ru  r   r  r  suiteFactory	loadClassrh   rg   rr  )r   r   r   r  r   r  s        @r   test_shouldStopz)DestructiveTestSuiteTests.test_shouldStop  s    
 	! 	! 	! 	! 	! 	! 	!x( 	! 	! 	! $&&"$$$9  **$$$		&!%%%--//33333r!   c                 f    G d dt           j                  } |d          }t          j                    }t	          j        |g          }|                     |                                d           |                    |           |                     |                                d           dS )zn
        Checks that the test suite cleanups its tests during the run, so that
        it ends empty.
        c                       e Zd Zd ZdS )8DestructiveTestSuiteTests.test_cleanup.<locals>.MockTestc                     d S r   r,   r  s    r   r   zADestructiveTestSuiteTests.test_cleanup.<locals>.MockTest.test_foo  r   r!   Nr   r,   r!   r   r   r    r   r!   r   r   r$   r   N)	r   r   r   ru  r   r  rh   rr  rg   )r   r   rF   r   r   s        r   test_cleanupz&DestructiveTestSuiteTests.test_cleanup  s    	 	 	 	 	v 	 	 	 x
##$&&+TF33--//333		&--//33333r!   N)r)   r*   r+   rZ   r  r  r  r,   r!   r   r  r    sK         4 4 4$4 4 464 4 4 4 4r!   r  c                   4    e Zd Z G d dej                  ZdS )RunnerDeprecationTestsc                   6    e Zd ZdZdZdZdZd Zd Zd Z	d Z
dS )#RunnerDeprecationTests.FakeReporterz
        Fake reporter that does *not* implement done() but *does* implement
        printErrors, separator, printSummary, stream, write and writeln
        without deprecations.
        Nc                     d S r   r,   r   s     r   printErrorsz/RunnerDeprecationTests.FakeReporter.printErrors  r  r!   c                     d S r   r,   r   s     r   printSummaryz0RunnerDeprecationTests.FakeReporter.printSummary  r  r!   c                     d S r   r,   r   s     r   writez)RunnerDeprecationTests.FakeReporter.write  r  r!   c                     d S r   r,   r   s     r   writelnz+RunnerDeprecationTests.FakeReporter.writeln  r  r!   )r)   r*   r+   rZ   rH   r[   r5   r  r  r  r  r,   r!   r   FakeReporterr    sk        	 	 		 	 		 	 		 	 		 	 	 	 	r!   r  N)r)   r*   r+   r   rL  r  r,   r!   r   r  r    sA            x(     r!   r  c                       e Zd ZdZd ZdS )QualifiedNameWalkerTestsz<
    Tests for L{twisted.trial.runner._qualNameWalker}.
    c                     t          t          j        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   _qualNameWalkerrh   )r   walkerResultss     r   test_walksDownPathz+QualifiedNameWalkerTests.test_walksDownPath  sf     V34IJJKK&+(,GX./	
 	
 	
 	
 	
r!   N)r)   r*   r+   rZ   r  r,   r!   r   r  r    s-         
 
 
 
 
r!   r  c                       e Zd ZdZd ZdS )TrialMainDoesNothingTestszl
    Importing L{twisted.trial.__main__} will not run the script
    unless it is actually C{__main__}.
    c                 $    t          d           dS )zO
        If we import L{twisted.trial.__main__}, it should do nothing.
        ztwisted.trial.__main__N)
__import__r   s    r   test_importDoesNothingz0TrialMainDoesNothingTests.test_importDoesNothing  s    
 	+,,,,,r!   N)r)   r*   r+   rZ   r  r,   r!   r   r  r    s-         
- - - - -r!   r  )@r   r-  r  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.   r^   r   rz   r   r   r   r   r   r   r?  rC  rb  r   rg  rm  r{  r  r  r  r  r  r  r  r  r,   r!   r   <module>r
     s   
			 



 



                 & & & & & & . . . . . .       " " " " " " ) ) ) ) ) ) 0 0 0 0 0 0 0 0 0 0 , , , , , , + + + + + + ! ! ! ! ! ! : : : : : : : : : : : : G G G G G G 5 5 5 5 5 5 5 5% % % % % % % % YN N N N N N N Nb# # # # # # # #L5 5 5 5 5,h.J 5 5 5(3 3 3 3 3873 3 3 )' )' )' )' )' )' )' )'X( ( ( ( ([(*F ( ( (( ( ( ( (+x; ( ( (( ( ( ( (X%A ( ( (_= _= _= _= _=(. _= _= _=D	4 4 4 4 4h2 4 4 4I
 I
 I
 I
 I
4 I
 I
 I
X6 6 6 6 60 6 6 6(	' 	' 	' 	' 	'F$ 	' 	' 	'A A A A A4 A A A>!- !- !- !- !-h2 !- !- !-HK6 K6 K6 K6 K6 K6 K6 K6\, , , , ,%:O , , ,", , , , ,%:O , , ,$.  .  .  .  . 87 .  .  . bA4 A4 A4 A4 A4 < A4 A4 A4H    X9   2
 
 
 
 
x; 
 
 
.- - - - - < - - - - -r!   