
    Ϫf                    J   d dl mZ d dlZ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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 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&m'Z'm(Z( d dl)m*Z* ddl+m,Z,  e-d      Z.d1dZ/d2dZ0d3dZ1d4dZ2 e"e2e1      Z3 G d dejh                        Z5 G d dejh                        Z6 G d dejh                        Z7 G d d ejh                        Z8 G d! d"ejh                        Z9 G d# d$ejh                        Z: G d% d&ejv                        Z< G d' d(ejv                        Z= G d) d*ejv                        Z> G d+ d,ejv                        Z? G d- d.ejv                        Z@ G d/ d0ejv                        ZAy)5    )annotationsN)StringIO)List)assert_thatcontains_string)given)sampled_from)Logger)util)FilePath	IFilePath)
UsageError)trial)unittest)DistTrialRunner)compose)DestructiveTestSuite
TestLoader	TestSuiteTrialRunner_Runner)	testNames   )fileContentsr   c                6    t        j                  t        |       S )z1
    For finding files in twisted/trial/test
    )r   sibpath__file__)filenames    @/usr/lib/python3/dist-packages/twisted/trial/test/test_script.pyr   r   &   s     <<(++    c                 6    t               j                  d       y)z.
    Emit something to L{twisted.logger}.
    	somethingN)r
   info r    r   logSomethingr%   -   s     HMM+r    c                P    t        j                         }|j                  |        |S )z?
    Parse an argument list using trial's argument parser.
    )r   OptionsparseOptions)argvconfigs     r   parseArgumentsr+   4   s"     ]]_F
Mr    c                    t        j                  |       }t               |_        t	        t
        j                  t              g      }|j                  |       | S )zM
    Run L{logSomething} as a test method using the given configuration.
    )	r   _makeRunnerr   streamr   pyunitFunctionTestCaser%   run)r*   runnersuites      r   runFromConfigr4   =   sF     v&FJFMv..|<=>E
JJuMr    c                      e Zd ZdZ e eg d            d	d       Z e eddg            d
d       Z e eddg            d
d       Zy)LogfileTestsz)
    Tests for the --logfile option.
    )zdir-azdir-bzdir-c/dir-dc                    t        d|g      }t        |      j                  |d         }t        |t	        t        d                   y)z
        If no value is given for the option then logs are written to a log
        file constructed from a default value.
        --temp-directorylogfiler"   NrunFromArgumentsr   preauthChildr   r   r   )selfworkingDirectoryr*   logPaths       r   test_defaultzLogfileTests.test_defaultP   sD     "#57G"HI%&67DDVIEVWG\/+*FGHr    zsomelog.txtzsomedir/somelog.txtc                    t        d|g      }t        |d         j                  |      }t        |t	        t        d                   y)z
        If the value given for the option is a relative path then it is
        interpreted relative to trial's own temporary working directory and
        logs are written there.
        	--logfiletemp-directoryr"   Nr:   )r=   r9   r*   r?   s       r   test_relativePathzLogfileTests.test_relativePathb   sB     ";"89%f-=&>?LLWUG\/+*FGHr    c                    t        d      j                  |      }t        d|j                  g       |}t	        |t        t        d                   y)z
        If the value given for the option is an absolute path then it is
        interpreted absolutely and logs are written there.
        .rB   r"   N)r   r<   r;   pathr   r   r   )r=   r9   r?   iPaths       r   test_absolutePathzLogfileTests.test_absolutePatht   sB    " 3-,,W5+w||45"E<(DEFr    N)r>   strreturnNone)r9   rJ   rK   rL   )	__name__
__module____qualname____doc__r   r	   r@   rD   rI   r$   r    r   r6   r6   K   s     	
II %	
II %	
GGr    r6   c                  @    e Zd ZdZd	dZd	dZd	dZd
dZd	dZd	dZ	y)ForceGarbageCollectionTestsz*
    Tests for the --force-gc option.
    c                    t        j                         | _        g | _        | j	                  t
        d| j                         t        j                  | j                        }t        ||g      | _        y )Ncollect)r   r'   r*   logpatchgcrT   r/   r0   
simpleTestr   test)r=   rY   s     r   setUpz!ForceGarbageCollectionTests.setUp   sN    mmo 

2y$,,/&&t7tTl+	r    c                :    | j                   j                  d       y)zD
        A simple test method that records that it was run.
        rY   NrU   appendr=   s    r   rX   z&ForceGarbageCollectionTests.simpleTest   s     	r    c                :    | j                   j                  d       y)zI
        A replacement for gc.collect that logs calls to itself.
        rT   Nr\   r^   s    r   rT   z#ForceGarbageCollectionTests.collect   s     		"r    c                b    t        j                  | j                        }t               |_        |S )zN
        Return a L{TrialRunner} object that is safe to use in tests.
        )r   r-   r*   r   r.   r=   r2   s     r   
makeRunnerz&ForceGarbageCollectionTests.makeRunner   s&     ""4;;/ 
r    c                    d| j                   d<   | j                   j                          | j                         }|j                  | j                         | j                  | j                  g d       y)z
        Passing the --force-gc option to the trial script forces the garbage
        collector to run before and after each test.
        Tzforce-gc)rT   rY   rT   rT   rY   rT   Nr*   postOptionsrb   r1   rY   assertEqualrU   ra   s     r   test_forceGcz(ForceGarbageCollectionTests.test_forceGc   sV    
 #'J!"

499HHR	
r    c                    | j                   j                          | j                         }|j                  | j                         | j                  | j                  ddg       y)z>
        By default, no garbage collection is forced.
        rY   Nrd   ra   s     r   test_unforceGcz*ForceGarbageCollectionTests.test_unforceGc   sI     	!"

499FF#34r    NrK   rL   )rK   r   )
rM   rN   rO   rP   rZ   rX   rT   rb   rg   ri   r$   r    r   rR   rR      s%    , #
5r    rR   c                  (    e Zd ZdZddZddZddZy)SuiteUsedTestsz?
    Check the category of tests suite used by the loader.
    c                6    t        j                         | _        y)z6
        Create a trial configuration object.
        Nr   r'   r*   r^   s    r   rZ   zSuiteUsedTests.setUp   s     mmor    c                    t        j                  | j                        }| j                  |j                  t
               y)zK
        By default, the loader should use L{DestructiveTestSuite}
        N)r   
_getLoaderr*   rf   suiteFactoryr   r=   loaders     r   test_defaultSuitez SuiteUsedTests.test_defaultSuite   s/     !!$++.,,.BCr    c                    d| j                   d<   t        j                  | j                         }| j                  |j                  t
               y)zw
        The C{until-failure} configuration uses the L{TestSuite} to keep
        instances alive across runs.
        Tzuntil-failureN)r*   r   rp   rf   rq   r   rr   s     r   test_untilFailureSuitez%SuiteUsedTests.test_untilFailureSuite   s<    
 (,O$!!$++.,,i8r    Nrj   )rM   rN   rO   rP   rZ   rt   rv   r$   r    r   rl   rl      s    &D9r    rl   c                      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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y)TestModuleTestsc                6    t        j                         | _        y Nrn   r^   s    r   rZ   zTestModuleTests.setUp       mmor    c                    d | _         y rz   )r*   r^   s    r   tearDownzTestModuleTests.tearDown   s	    r    c                X    | j                  t        |       | j                         g       y)zq
        Check that the testNames helper method accurately collects the
        names of tests in suite.
        N)rf   r   idr^   s    r   test_testNameszTestModuleTests.test_testNames   s     
 	44779+6r    c                    t               }t        |      }t        t        t        |j                  |                  }|j                          |j                          | j                  ||       y rz   )r   r   r   map
loadByNamesortrf   )r=   test1namesrs   names1names2s         r   assertSuitesEqualz!TestModuleTests.assertSuitesEqual   sQ    5!9S):):E%BCD(r    c                T    | j                  dt        | j                  d                y )Nr   tests)rf   lenr*   r^   s    r   test_baseStatezTestModuleTests.test_baseState   s     CG 456r    c                    | j                   j                  t        d             | j                  t	        j
                  | j                         dg       y)z
        Check that --testmodule loads a suite which contains the tests
        referred to in test-case-name inside its parameter.
        moduletest.pytwisted.trial.test.test_logNr*   opt_testmoduler   r   r   	_getSuiter^   s    r   test_testmoduleOnModulez'TestModuleTests.test_testmoduleOnModule   s?    
 	""7?#;<OODKK(+H*I	
r    c                    | j                   j                  t        d             | j                   j                  t        d             | j                  t	        j
                  | j                         dg       y)z
        When the same module is specified with two --testmodule flags, it
        should only appear once in the suite.
        r   r   Nr   r^   s    r   test_testmoduleTwicez$TestModuleTests.test_testmoduleTwice  sV    
 	""7?#;<""7?#;<OODKK(+H*I	
r    c                    | j                   j                  t        d             | j                   j                  t        d             | j                  t	        j
                  | j                         dg       y)z
        If --testmodule is specified twice, once for module A and once for
        a module which refers to module A, then make sure module A is only
        added once.
        r   ztest_log.pyr   Nr   r^   s    r    test_testmoduleOnSourceAndTargetz0TestModuleTests.test_testmoduleOnSourceAndTarget  sV     	""7?#;<""7=#9:OODKK(+H*I	
r    c                    | j                   j                  t        d             | j                  t	        j
                  | j                         dg       y)z
        When given a module that refers to *itself* in the test-case-name
        variable, check that --testmodule only adds the tests once.
        zmoduleself.pyztwisted.trial.test.moduleselfNr   r^   s    r   test_testmoduleOnSelfModulez+TestModuleTests.test_testmoduleOnSelfModule  s?    
 	""7?#;<OODKK(+J*K	
r    c                    | j                   j                  t        d             | j                  t	        j
                  | j                         ddg       y)zm
        Check that --testmodule loads tests referred to in test-case-name
        buffer variables.
        scripttest.pyr   twisted.trial.test.test_runnerNr   r^   s    r   test_testmoduleOnScriptz'TestModuleTests.test_testmoduleOnScript"  sB    
 	""7?#;<OODKK(*,LM	
r    c                Z   t               }t        j                  |c}t        _        d}	 | j                  j	                  |       | j                  dt        | j                  d                | j                  d|d|j                                |t        _        y# |t        _        w xY w)zz
        Check that --testmodule displays a meaningful error message when
        passed a non-existent filename.
        ztest_thisbetternoteverexist.pyr   r   File  doesn't exist
Nr   sysstderrr*   r   rf   r   getvalue)r=   buffyr   r   s       r    test_testmoduleOnNonexistentFilez0TestModuleTests.test_testmoduleOnNonexistentFile-  s    
 
 ZZ
3	 KK&&x0QDKK$8 9:uXL0@A5>>CSTCJCJ   A'B B*c                    | j                   j                  t        d             | j                  dt	        | j                   d                y)z
        Check that --testmodule adds no tests to the suite for modules
        which lack test-case-name buffer variables.
        	novars.pyr   r   N)r*   r   r   rf   r   r^   s    r   test_testmoduleOnEmptyVarsz*TestModuleTests.test_testmoduleOnEmptyVars<  s9    
 	""7;#78CG 456r    c                Z   t               }t        j                  |c}t        _        d}	 | j                  j	                  |       | j                  dt        | j                  d                | j                  d|d|j                                |t        _        y# |t        _        w xY w)z
        Check that --testmodule does *not* support module names as arguments
        and that it displays a meaningful error message.
        ztwisted.trial.test.test_scriptr   r   r   r   Nr   )r=   r   r   
moduleNames       r   test_testmoduleOnModuleNamez+TestModuleTests.test_testmoduleOnModuleNameD  s    
 
 ZZ
5
	 KK&&z2QDKK$8 9:uZN2BCU^^EUVCJCJr   c                Z    d}t        j                  |      }| j                  ddi|       y )Nz5-*- test-case-name: twisted.trial.test.test_tests -*-test-case-nametwisted.trial.test.test_testsr   _parseLocalVariablesrf   r=   declaration	localVarss      r   test_parseLocalVariablez'TestModuleTests.test_parseLocalVariableS  s.    M..{;	*,KLiXr    c                Z    d}t        j                  |      }| j                  ddi|       y )Nz6-*- test-case-name: twisted.trial.test.test_tests; -*-r   r   r   r   s      r   test_trailingSemicolonz&TestModuleTests.test_trailingSemicolonX  s.    N..{;	*,KLiXr    c                \    d}t        j                  |      }| j                  ddd|       y )Nz?-*- test-case-name: twisted.trial.test.test_tests; foo: bar -*-r   bar)r   foor   r   s      r   test_parseLocalVariablesz(TestModuleTests.test_parseLocalVariables]  s4    P 	 ..{;	>uMy	
r    c                Z    d}t        j                  |      }| j                  ddi|       y )Nz:## -*- test-case-name: twisted.trial.test.test_tests -*- #r   r   r   r   s      r   test_surroundingGuffz$TestModuleTests.test_surroundingGufff  s.    U..{;	*,KLiXr    c                N    | j                  t        t        j                  d       y Nr   assertRaises
ValueErrorr   r   r^   s    r   test_invalidLinez TestModuleTests.test_invalidLinek  s    *e&@&@%Hr    c                    | j                  t        t        j                  d       | j                  t        t        j                  d       | j                  t        t        j                  d       y )Nz-*- foo -*-z-*- foo: bar; qux -*-z-*- foo: bar: baz; qux: qax -*-r   r^   s    r   test_invalidDeclarationz'TestModuleTests.test_invalidDeclarationn  sT    *e&@&@-P224K	
 	224U	
r    c                h    t        j                  t        d            }| j                  ddi|       y )Nr   r   r   r   loadLocalVariablesr   rf   r=   r   s     r   test_variablesFromFilez&TestModuleTests.test_variablesFromFilew  s.    ,,W_-EF	*,IJIVr    c                d    t        j                  t        d            }| j                  i |       y )Nr   r   r   s     r   test_noVariablesInFilez&TestModuleTests.test_noVariablesInFile{  s'    ,,W[-AB	Y'r    c                h    t        j                  t        d            }| j                  ddi|       y )Nr   r   z:twisted.trial.test.test_log,twisted.trial.test.test_runnerr   r   s     r   test_variablesFromScriptz(TestModuleTests.test_variablesFromScript  s5    ,,W_-EF	 S
 	
r    c                f    t        j                  t        d            }| j                  |dg       y )Nr   r   )r   getTestModulesr   rf   r=   moduless     r   test_getTestModulesz#TestModuleTests.test_getTestModules  s+    &&w'?@#@"ABr    c                v    t        j                  t        d            }| j                  t	        |      d       y )Nr   r   )r   r   r   rf   r   r   s     r   test_getTestModules_noVarsz*TestModuleTests.test_getTestModules_noVars  s+    &&w{';<Wq)r    c                z    t        j                  t        d            }| j                  t	        |      ddh       y )Nr   r   r   )r   r   r   rf   setr   s     r   test_getTestModules_multiplez,TestModuleTests.test_getTestModules_multiple  s5    &&w'?@L*,LM	
r    c                    dD ]*  }| j                  t        j                  |      |d       , dt        d      t        d      fD ]*  }| j	                  t        j                  |      |d       , y )N)ztest_script.pyz!twisted/trial/test/test_script.pyz should be a test filez twisted/trial/test/moduletest.pyr   ztest_foo.batz should *not* be a test file)
assertTruer   
isTestFiler   assertFalse)r=   r   s     r   test_looksLikeTestModulez(TestModuleTests.test_looksLikeTestModule  s    O 	HOO  *,45	 /O$N#
 	H
   *,:;	r    Nrj   )r   r   r   z	list[str]rK   rL   )rM   rN   rO   rZ   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r$   r    r   rx   rx      s    &7)7
	



	
 7 Y
Y

Y
I
W(	
C*
r    rx   c                  H    e Zd ZdZd
dZd
dZddZddZd
dZd
dZ	d
dZ
y	)WithoutModuleTestsz*
    Test the C{without-module} flag.
    c                r    t        j                         | _        t        t        j
                        | _        y)zl
        Create a L{trial.Options} object to be used in the tests, and save
        C{sys.modules}.
        N)r   r'   r*   dictr   r   savedModulesr^   s    r   rZ   zWithoutModuleTests.setUp  s"    
 mmo -r    c                    dD ]Q  }|| j                   v r!| j                   |   t        j                  |<   2t        j                  j                  |d       S y)z)
        Restore C{sys.modules}.
        )imaplibsmtplibN)r   r   r   pop)r=   modules     r   r}   zWithoutModuleTests.tearDown  sL     - 	.F***&*&7&7&?F#-		.r    c                    ddl }|S )zE
        Try to import the C{smtplib} module, and return it.
        r   N)r   )r=   r   s     r   
_checkSMTPzWithoutModuleTests._checkSMTP       	r    c                    ddl }|S )zE
        Try to import the C{imaplib} module, and return it.
        r   N)r   )r=   r   s     r   
_checkIMAPzWithoutModuleTests._checkIMAP  r   r    c                    | j                   j                  ddg       | j                  t        | j                         t
        j                  d= | j                  | j	                         t        j                         y)zT
        Check that after disabling a module, it can't be imported anymore.
        --without-moduler   N)
r*   r(   r   ImportErrorr   r   r   assertIsInstancetypes
ModuleTyper^   s    r   test_disableOneModulez(WithoutModuleTests.test_disableOneModule  sY     	  "4i!@A+t7KK	"doo/1A1ABr    c                   | j                   j                  ddg       | j                  t        | j                         | j                  t        | j
                         t        j                  d= t        j                  d= | j                  | j	                         t        j                         | j                  | j                         t        j                         y)zE
        Check that several modules can be disabled at once.
        r   zsmtplib,imaplibr   r   N)r*   r(   r   r   r   r   r   r   r   r   r   r^   s    r   test_disableMultipleModulesz.WithoutModuleTests.test_disableMultipleModules  s     	  "46G!HI+t7+t7KK	"KK	"doo/1A1ABdoo/1A1ABr    c                   | j                  | j                         t        j                         | j	                  t
        dt        j                  | j                  j                  ddg       | j                  t        | j                         y)zP
        Disabling an already imported module should produce a warning.
        z4Module 'smtplib' already imported, disabling anyway.r   r   N)r   r   r   r   assertWarnsRuntimeWarningr   r   r*   r(   r   r   r^   s    r   !test_disableAlreadyImportedModulez4WithoutModuleTests.test_disableAlreadyImportedModule  sg     	doo/1A1ABBNNKK$$+	
 	+t7r    Nrj   )rK   object)rM   rN   rO   rP   rZ   r}   r   r   r   r   r   r$   r    r   r   r     s,    ..	CC8r    r   c                  H    e Zd ZdZ eedd      dZd	dZd	dZd	dZ	d	dZ
y)
CoverageTestsz+
    Tests for the I{coverage} option.
    gettraceNz;Cannot test trace hook installation without inspection API.c                h    | j                  t        j                  t        j                                y)zf
        Arrange for the current trace hook to be restored when the
        test is complete.
        N)
addCleanupr   settracer   r^   s    r   rZ   zCoverageTests.setUp  s    
 	clln5r    c                    t        j                         }|j                  dg       |j                  J | j	                  t        j                         |j                  j                         y)z}
        L{trial.Options} handles C{"--coverage"} by installing a trace
        hook to record coverage information.
        z
--coverageN)r   r'   r(   tracerrf   r   r   globaltracer=   optionss     r   test_tracerInstalledz"CoverageTests.test_tracerInstalled  sS    
 --/l^,~~)))LLNNN&&	
r    c                    t        j                         }| j                  |j                         t	        d      j                  |d   dg             y)z
        L{trial.Options.coverdir} returns a L{FilePath} based on the default
        for the I{temp-directory} option if that option is not specified.
        rF   rC   coverageN)r   r'   rf   coverdirr   
descendantr  s     r   test_coverdirDefaultz"CoverageTests.test_coverdirDefault  sF    
 --/SM$$g.>&?%LM	
r    c                    | j                         }t        j                         }|j                  d|g       | j	                  |j                         t        |      j                  d             y)z
        If a value is specified for the I{temp-directory} option,
        L{trial.Options.coverdir} returns a child of that path.
        r8   r
  N)mktempr   r'   r(   rf   r  r   child)r=   rG   r  s      r   test_coverdirOverriddenz%CoverageTests.test_coverdirOverridden!  sV    
 {{}--/0$78))+Xd^-A-A*-MNr    rj   )rM   rN   rO   rP   getattrr   skiprZ   r  r  r  r$   r    r   r   r     s2     sJ%-L6
	
Or    r   c                  @    e Zd ZdZd	dZd	dZd	dZd	dZd	dZd	dZ	y)
OptionsTestsz%
    Tests for L{trial.Options}.
    c                6    t        j                         | _        y)zE
        Build an L{Options} object to be used in the tests.
        Nr   r'   r  r^   s    r   rZ   zOptionsTests.setUp1  s     }}r    c                   | j                  t        j                  t        j                                t	        j
                         r| j                  t        j                         | j                  j                  g d       | j                  j                         }| j                  d|       |j                  d       | j                  ddg|       y)z
        C{_getWorkerArguments} discards options like C{random} as they only
        matter in the manager, and forwards options like C{recursionlimit} or
        C{disablegc}.
        )--recursionlimit2000--random4--disablegcr  r  r  N)r  r   setrecursionlimitgetrecursionlimitrW   	isenabledenabler  r(   _getWorkerArgumentsassertInremoverf   )r=   argss     r   test_getWorkerArgumentsz$OptionsTests.test_getWorkerArguments7  s     	--s/D/D/FG<<>OOBII&!!H	
 ||//1mT*M",f5t<r    c                    | j                  t        | j                  j                  g d      }| j	                  dt        |             y)z
        C{parseOptions} raises a C{UsageError} when C{--debug} is passed along
        C{--jobs} as it's not supported yet.

        @see: U{http://twistedmatrix.com/trac/ticket/5825}
        )--jobsr  --debugz+You can't specify --debug when using --jobsNr   r   r  r(   rf   rJ   r=   errors     r   test_jobsConflictWithDebugz'OptionsTests.test_jobsConflictWithDebugI  s=     !!113M
 	FE
Sr    c                    | j                  t        | j                  j                  g d      }| j	                  dt        |             y)z
        C{parseOptions} raises a C{UsageError} when C{--profile} is passed
        along C{--jobs} as it's not supported yet.

        @see: U{http://twistedmatrix.com/trac/ticket/5827}
        )r(  r  z	--profilez-You can't specify --profile when using --jobsNr*  r+  s     r   test_jobsConflictWithProfilez)OptionsTests.test_jobsConflictWithProfileU  s=     !!113O
 	H#e*Ur    c                    | j                  t        | j                  j                  g d      }| j	                  dt        |             y)z
        C{parseOptions} raises a C{UsageError} when C{--debug-stacktraces} is
        passed along C{--jobs} as it's not supported yet.

        @see: U{http://twistedmatrix.com/trac/ticket/5826}
        )r(  r  z--debug-stacktracesz7You can't specify --debug-stacktraces when using --jobsNr*  r+  s     r   %test_jobsConflictWithDebugStackTracesz2OptionsTests.test_jobsConflictWithDebugStackTracesa  s@     !!LL%%2

 	Es5z	
r    c                    | j                  t        | j                  j                  g d      }| j	                  dt        |             y)zr
        C{parseOptions} raises a C{UsageError} when C{--order} is passed along
        with C{--random}.
        )--orderalphabeticalr  1234z-You can't specify --random when using --orderNr*  r+  s     r   test_orderConflictWithRandomz)OptionsTests.test_orderConflictWithRandomq  s>    
 !!LL%%;

 	H#e*Ur    Nrj   )
rM   rN   rO   rP   rZ   r&  r-  r/  r1  r6  r$   r    r   r  r  ,  s(    '=$
T
V
 
Vr    r  c                  8    e Zd ZdZddZddZddZddZddZy)	MakeRunnerTestsz.
    Tests for the L{_makeRunner} helper.
    c                6    t        j                         | _        y rz   r  r^   s    r   rZ   zMakeRunnerTests.setUp  s    }}r    c                >   | j                   j                  g d       t        j                  | j                         }t	        |t
              sJ | j                  |t
               | j                  d|j                         | j                  dg|j                         y)z
        L{_makeRunner} returns a L{DistTrialRunner} instance when the C{--jobs}
        option is passed.  The L{DistTrialRunner} knows how many workers to
        run and the C{workerArguments} to pass to them.
        )r(  r  
--force-gc   r;  N)
r  r(   r   r-   
isinstancer   r   rf   _maxWorkers_workerArgumentsra   s     r   	test_jobszMakeRunnerTests.test_jobs  sy     	!!"?@""4<<0&/222fo6F../,)@)@Ar    c                    | j                   j                  g d       t        j                  | j                         }t	        |t
              sJ | j                  |t
               | j                  t
        j                  |j                         y)z
        L{_makeRunner} returns a L{TrialRunner} instance in C{DRY_RUN} mode
        when the C{--dry-run} option is passed, even if C{--jobs} is set.
        )r(  r  z	--dry-runN)
r  r(   r   r-   r=  r   r   rf   DRY_RUNmodera   s     r   test_dryRunWithJobsz#MakeRunnerTests.test_dryRunWithJobs  se    
 	!!">?""4<<0&+...fk2,,fkk:r    c                4   t         j                  j                  dfd}| j                  t         j                  d|       t        j                         }|j                  g d       | j                  t         j                  t         j                  |       y )Nc                \    | dk(  rt         j                  j                  |        |       S )N	doNotFind)r   reflectModuleNotFound)fqnnamedAnys    r   namedAnyExceptdoNotFindzFMakeRunnerTests.test_DebuggerNotFound.<locals>.namedAnyExceptdoNotFind  s*    k!mm22377C= r    rK  )r)  z
--debuggerrG  )rJ  rJ   rK   r   )	r   rH  rK  rV   r'   r(   r   _DebuggerNotFoundr-   )r=   rL  r  rK  s      @r   test_DebuggerNotFoundz%MakeRunnerTests.test_DebuggerNotFound  sf    ==))	!
 	

5==*.EF--/CD%1153D3DgNr    c                    | j                   j                  dg       t        j                  | j                         }t	        |t
              sJ | j                  |j                         y)z
        Passing C{--exitfirst} wraps the reporter with a
        L{reporter._ExitWrapper} that stops on any non-success.
        z--exitfirstN)r  r(   r   r-   r=  r   r   
_exitFirstra   s     r   test_exitfirstzMakeRunnerTests.test_exitfirst  sN    
 	!!=/2""4<<0&+...))*r    Nrj   )	rM   rN   rO   rP   rZ   r@  rD  rN  rQ  r$   r    r   r8  r8  ~  s"    'B	;O+r    r8  c                       e Zd ZdZddZddZy)RunTestsz(
    Tests for the L{run} function.
    c                H    | j                  t        j                  dd        y )Nr(   c                     y rz   r$   r^   s    r   <lambda>z RunTests.setUp.<locals>.<lambda>  s    r    )rV   r   r'   r^   s    r   rZ   zRunTests.setUp  s     	

5==.2CDr    c                    dd}| j                  t        d|       	 t        j                          | j                  d       y# t        $ r%}| j                  dt        |             Y d}~yd}~ww xY w)zY
        When a debugger is not found, an error message is printed to the user.

        c                 ,    t        j                  d      r   )r   rM  )r%  kwargss     r   r-   z3RunTests.test_debuggerNotFound.<locals>._makeRunner  s    ))%00r    r-   z0Should have exited due to non-existent debugger!r   N)r%  r   rY  r   rK   rL   )rV   r   r1   fail
SystemExitr#  rJ   )r=   r-   es      r   test_debuggerNotFoundzRunTests.test_debuggerNotFound  s^    	1 	

5-5	JIIK IIHI  	)MM%Q((	)s   A 	A1A,,A1Nrj   )rM   rN   rO   rP   rZ   r]  r$   r    r   rS  rS    s    E
Jr    rS  c                       e Zd ZdZddZddZy)TestArgumentOrderTestszQ
    Tests for the order-preserving behavior on provided command-line tests.
    c                T    t        j                         | _        t               | _        y rz   )r   r'   r*   r   rs   r^   s    r   rZ   zTestArgumentOrderTests.setUp  s    mmo lr    c                "   g d}| j                   j                  |       t        j                  | j                         }t	        |      }t        t        | j                  j                  |            }t	        |      }| j                  ||       y)zN
        Multiple tests passed on the command line are not reordered.
        )r   z"twisted.trial.test.test_assertionsz twisted.trial.test.test_deferredN)
r*   r(   r   r   r   r   r   rs   r   rf   )r=   r   r3   r   expectedSuiteexpectedNamess         r   test_preserveArgumentOrderz1TestArgumentOrderTests.test_preserveArgumentOrder  sn    

 	  ',% !#dkk&<&<e"DE!-0.r    Nrj   )rM   rN   rO   rP   rZ   rd  r$   r    r   r_  r_    s    #/r    r_  c                  X    e Zd ZdZddZddZddZddZddZddZ	ddZ
dd	Zdd
Zy)
OrderTestsz'
    Tests for the --order option.
    c                6    t        j                         | _        y rz   rn   r^   s    r   rZ   zOrderTests.setUp  r{   r    c                    | j                   j                  g d       t        j                  | j                         }|j	                  | j                   d         }| j                  t        |      g d       y)zn
        --order=alphabetical causes trial to run tests alphabetically within
        each test case.
        )r3  r4  %twisted.trial.test.ordertests.FooTestr   )0twisted.trial.test.ordertests.FooTest.test_first1twisted.trial.test.ordertests.FooTest.test_fourth1twisted.trial.test.ordertests.FooTest.test_second0twisted.trial.test.ordertests.FooTest.test_thirdNr*   r(   r   rp   loadByNamesrf   r   r=   rs   r3   s      r   test_alphabeticalzOrderTests.test_alphabetical  sc    
 	  P	
 !!$++.""4;;w#78e	
r    c                    | j                   j                  g d       t        j                  | j                         }|j	                  | j                   d         }| j                  t        |      g d       y)zu
        --order=alphabetical causes trial to run test classes within a given
        module alphabetically.
        )r3  r4  twisted.trial.test.ordertestsr   ).twisted.trial.test.ordertests.BarTest.test_bar.twisted.trial.test.ordertests.BazTest.test_bazrj  rk  rl  rm  Nrn  rp  s      r   test_alphabeticalModulez"OrderTests.test_alphabeticalModule  sc    
 	  H	
 !!$++.""4;;w#78e
	
r    c                *   | j                   j                  g d       t        j                  | j                         }|j	                  | j                   d         }t        |      }| j                  |d       | j                  |t        |             y)z
        --order=alphabetical causes trial to run test modules within a given
        package alphabetically, with tests within each module alphabetized.
        )r3  r4  twisted.trial.testr   zFailed to load any tests!msgN)	r*   r(   r   rp   ro  r   r   rf   sortedr=   rs   r3   r   s       r   test_alphabeticalPackagez#OrderTests.test_alphabeticalPackage'  ss    
 	  !RS!!$++.""4;;w#78% #>?u.r    c                    | j                   j                  g d       t        j                  | j                         }|j	                  | j                   d         }| j                  t        |      g d       y)z
        --order=toptobottom causes trial to run test methods within a given
        test case from top to bottom as they are defined in the body of the
        class.
        )r3  toptobottomri  r   )rj  rl  rm  rk  Nrn  rp  s      r   test_toptobottomzOrderTests.test_toptobottom4  sc     	  O	
 !!$++.""4;;w#78e	
r    c                    | j                   j                  g d       t        j                  | j                         }|j	                  | j                   d         }| j                  t        |      g d       y)z
        --order=toptobottom causes trial to run test classes within a given
        module from top to bottom as they are defined in the module's source.
        r3  r  rs  r   )rj  rl  rm  rk  ru  rt  Nrn  rp  s      r   test_toptobottomModulez!OrderTests.test_toptobottomModuleK  sc    
 	  G	
 !!$++.""4;;w#78e
	
r    c                
   | j                   j                  g d       t        j                  | j                         }|j	                  | j                   d         }t        |      }| j                  |t        |d              y)z
        --order=toptobottom causes trial to run test modules within a given
        package alphabetically, with tests within each module run top to
        bottom.
        )r3  r  rx  r   c                *    | j                  d      d d S )NrF   r<  )split)names    r   rV  z4OrderTests.test_toptobottomPackage.<locals>.<lambda>q  s    4::c?2A+> r    )keyN)r*   r(   r   rp   ro  r   rf   r{  r|  s       r   test_toptobottomPackagez"OrderTests.test_toptobottomPackageb  sl     	  !QR!!$++.""4;;w#78%  	5>?	
r    c                   | j                         }t        |      j                  d      }|j                          |j                  d      j	                  d       |j                  d      j	                  t        j                  d      j                  d             |j                         j                  }t        j                  j                  d|       | j                  t        j                  j                  |       ddlm} | j                  t        j                   j"                  d       | j                  t        j                   j"                  |j$                         |j                  d      j                          | j&                  j)                  g d	       t+        j,                  | j&                        }|j/                  |      }| j1                  t3        |      g d
       y)z{
        --order=toptobottom detects the source line of methods from modules
        whose source file is missing.
        twisted_toptobottom_tempz__init__.pyr    ztest_missing.pya   
        from twisted.trial.unittest import TestCase
        class TestMissing(TestCase):
            def test_second(self) -> None: pass
            def test_third(self) -> None: pass
            def test_fourth(self) -> None: pass
            def test_first(self) -> None: pass
        utf8r   )test_missingr  )z=twisted_toptobottom_temp.test_missing.TestMissing.test_secondz<twisted_toptobottom_temp.test_missing.TestMissing.test_thirdz=twisted_toptobottom_temp.test_missing.TestMissing.test_fourthz<twisted_toptobottom_temp.test_missing.TestMissing.test_firstN)r  r   r  makedirs
setContenttextwrapdedentencodeparentrG   r   insertr  r$  r  r  r   r   rM   r*   r(   r   rp   
loadModulerf   r   )r=   tempdirpackage	pathEntryr  rs   r3   s          r   test_toptobottomMissingSourcez(OrderTests.test_toptobottomMissingSourcet  s^   
 ++-7#))*DEm$//4'(33OO	 fVn	
 NN$))	9%3	
 	)CD)>)>?'(//1  G	
 !!$++.!!,/e	
r    c                ^    | j                  t        | j                  j                  ddg       y)zL
        An unknown order passed to --order raises a L{UsageError}.
        r3  zI don't existN)r   r   r*   r(   r^   s    r   test_unknownOrderzOrderTests.test_unknownOrder  s(    
 	009o2N	
r    Nrj   )rM   rN   rO   rP   rZ   rq  rv  r}  r  r  r  r  r  r$   r    r   rf  rf    s5    &
,
./
.
.
$.
`
r    rf  c                      e Zd ZdZddZy)HelpOrderTestsz+
    Tests for the --help-orders flag.
    c                   | j                  t        dt               x}       | j                  t        t        j                         j                  dg      }| j                  |j                  d       |j                         }d}t
        j                  j                         D ]a  \  }\  }}t        j                  t        j                  |       dt        j                  |       |      }| j!                  ||||fz         c y)zS
        --help-orders prints each of the available orders and then exits.
        stdoutz--help-ordersr   z4%r with its description not properly described in %rz.*ry  N)rV   r   r   r   r[  r   r'   r(   rf   coder   
_runOrdersitemsresearchescaper   )	r=   r  excoutputrz  	orderName	orderDesc_matchs	            r   &test_help_ordersPrintsSynopsisAndQuitsz5HelpOrderTests.test_help_ordersPrintsSynopsisAndQuits  s     	

3HJ"6&7446G
 	1%"D).)9)9)?)?)A 	B%I~	1II99Y'(299Y+?*@AE
 OOEsi-@'@OA	Br    Nrj   )rM   rN   rO   rP   r  r$   r    r   r  r    s    Br    r  )r   rJ   rK   rJ   rj   )r)   z	List[str]rK   trial.Options)r*   r  rK   r  )B
__future__r   rW   r  r   r  r   ior   typingr   hamcrestr   r   
hypothesisr   hypothesis.strategiesr	   twisted.loggerr
   twisted.pythonr   twisted.python.filepathr   r   twisted.python.usager   twisted.scriptsr   twisted.trialr   twisted.trial._dist.disttrialr   twisted.trial._dist.functionalr   twisted.trial.runnerr   r   r   r   r   twisted.trial.test.test_loaderr   matchersr   
__import__r/   r   r%   r+   r4   r;   SynchronousTestCaser6   rR   rl   rx   r   r   TestCaser  r8  rS  r_  rf  r  r$   r    r   <module>r     sq   # 	 	 
     1  . !  7 + ! " 9 2  5 "	J	, =.9 =G8// =G@45(">"> 45n9X11 98Ih22 IXL855 L8^0OH00 0OfOV8$$ OVd7+h'' 7+tJx   J:/X.. /:y
"" y
xBX&& Br    