
    Vh܍                       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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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      Z0d4dZ1d5dZ2d6dZ3d7dZ4 e$e4e3      Z5 G d dejl                        Z7 G d dejl                        Z8 G d dejl                        Z9 G d  d!ejl                        Z: G d" d#ejl                        Z; G d$ d%ejl                        Z< G d& d'ejl                        Z= G d( d)ej|                        Z? G d* d+ej|                        Z@ G d, d-ej|                        ZA G d. d/ej|                        ZB G d0 d1ej|                        ZC G d2 d3ej|                        ZDy)8    )annotationsN)StringIO)List)skipIf)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    N/home/dcms/DCMS/lib/python3.12/site-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,   6   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    runFromConfigr5   ?   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_defaultR   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>   r:   r+   r@   s       r    test_relativePathzLogfileTests.test_relativePathd   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.
        .rC   r#   N)r   r=   r<   pathr   r   r   )r>   r:   r@   iPaths       r    test_absolutePathzLogfileTests.test_absolutePathv   sB    " 3-,,W5+w||45"E<(DEFr!   N)r?   strreturnNone)r:   rK   rL   rM   )	__name__
__module____qualname____doc__r	   r
   rA   rE   rJ   r%   r!   r    r7   r7   M   s     	
II %	
II %	
GGr!   r7   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gcrU   r0   r1   
simpleTestr   test)r>   rZ   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.
        rZ   NrV   appendr>   s    r    rY   z&ForceGarbageCollectionTests.simpleTest   s     	r!   c                :    | j                   j                  d       y)zI
        A replacement for gc.collect that logs calls to itself.
        rU   Nr]   r_   s    r    rU   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>   r3   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)rU   rZ   rU   rU   rZ   rU   Nr+   postOptionsrc   r2   rZ   assertEqualrV   rb   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.
        rZ   Nre   rb   s     r    test_unforceGcz*ForceGarbageCollectionTests.test_unforceGc   sI     	!"

499FF#34r!   NrL   rM   )rL   r   )
rN   rO   rP   rQ   r[   rY   rU   rc   rh   rj   r%   r!   r    rS   rS      s%    , #
5r!   rS   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    r[   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+   rg   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   rq   rg   rr   r   rs   s     r    test_untilFailureSuitez%SuiteUsedTests.test_untilFailureSuite   s<    
 (,O$!!$++.,,i8r!   Nrk   )rN   rO   rP   rQ   r[   ru   rw   r%   r!   r    rm   rm      s    &D9r!   rm   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 Nro   r_   s    r    r[   zTestModuleTests.setUp       mmor!   c                    d | _         y r{   )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)rg   r   idr_   s    r    test_testNameszTestModuleTests.test_testNames   s     
 	44779+6r!   c                    t               }t        |      }t        t        t        |j                  |                  }|j                          |j                          | j                  ||       y r{   )r   r   r   map
loadByNamesortrg   )r>   test1namesrt   names1names2s         r    assertSuitesEqualz!TestModuleTests.assertSuitesEqual   sQ    5!9S):):E%BCD(r!   c                T    | j                  dt        | j                  d                y )Nr   tests)rg   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   rg   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   rg   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_testmoduleOnModuleNameF  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   _parseLocalVariablesrg   r>   declaration	localVarss      r    test_parseLocalVariablez'TestModuleTests.test_parseLocalVariableU  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_trailingSemicolonZ  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_surroundingGuffh  s.    U..{;	*,KLiXr!   c                N    | j                  t        t        j                  d       y Nr   assertRaises
ValueErrorr   r   r_   s    r    test_invalidLinez TestModuleTests.test_invalidLinem  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_invalidDeclarationp  sT    *e&@&@-P224K	
 	224U	
r!   c                h    t        j                  t        d            }| j                  ddi|       y )Nr   r   r   r   loadLocalVariablesr   rg   r>   r   s     r    test_variablesFromFilez&TestModuleTests.test_variablesFromFiley  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   rg   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   rg   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   rg   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!   Nrk   )r   r   r   z	list[str]rL   rM   )rN   rO   rP   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!   r    ry   ry      s    &7)7
	



	
 7 Y
Y

Y
I
W(	
C*
r!   ry   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    r[   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!   Nrk   )rL   object)rN   rO   rP   rQ   r[   r~   r   r   r   r   r   r%   r!   r    r   r     s,    ..	CC8r!   r   c                      e Zd ZdZej
                  dd dk\  Z eedd      duZ	 e
e d      dd       Z e
exs e	 d      dd	       Zdd
ZddZy)AutoJobsTestsz0
    Test {twisted.scripts.trial._autoJobs}
    N   )      sched_getaffinityzRequires os.process_cpu_count()c                t    t        j                         }| j                  t        j                         |       y)zt
        When `os.process_cpu_count()` is available (Python 3.13+), `_autoJobs`
        returns its result.
        N)osprocess_cpu_countrg   r   	_autoJobs)r>   counts     r    test_processCpuCountz"AutoJobsTests.test_processCpuCount  s)     $$&*E2r!   z>Requires os.sched_getaffinity() without os.process_cpu_count()c                    | j                  t        j                         t        t	        j
                  d                   y)a  
        When `os.sched_getaffinity()` is available but `os.process_cpu_count()`
        is not (Python 3.3 through Python 3.12 on "some Unix platforms"),
        `_autoJobs` uses it to returns the number of CPUs that the current
        process is restricted to.
        r   N)rg   r   r  r   r  r  r_   s    r    test_schedGetAffinityz#AutoJobsTests.test_schedGetAffinity  s+     	*C0D0DQ0G,HIr!   c                p    | j                  t        j                         t        j                                y)zb
        When only `os.cpu_count()` is available, `_autoJobs` returns
        its result.
        N)rg   r   r  r  	cpu_countr_   s    r    test_cpuCountzAutoJobsTests.test_cpuCount  s!    
 	*BLLN;r!   c                   | j                   r| j                  t        dd        | j                  r| j                  t        dd        | j                  t        dd        | j	                  t        j                         d       y)	z
        When `os.cpu_count()` returns L{None}, `_autoJobs`
        rounds up to 1.

        This test relies on patching because all platforms currently
        supported by Twisted provide a functioning `os.cpu_count()`.
        r  c                      y r{   r%   r%   r!   r    <lambda>z4AutoJobsTests.test_cpuCountUnknown.<locals>.<lambda>)      r!   r  c                    t               S r{   )r   )pids    r    r  z4AutoJobsTests.test_cpuCountUnknown.<locals>.<lambda>+  s    CE r!   r  c                      y r{   r%   r%   r!   r    r  z4AutoJobsTests.test_cpuCountUnknown.<locals>.<lambda>,  r  r!   r   N)hasProcessCpuCountrW   r  hasSchedGetaffinityrg   r   r  r_   s    r    test_cpuCountUnknownz"AutoJobsTests.test_cpuCountUnknown   s`     ""JJr.=##JJr.0AB

2{L1*A.r!   rk   )rN   rO   rP   rQ   r   version_infor  getattrr  r  r   r	  r  r  r  r%   r!   r    r   r     s     ))"1-8!"&94@L""$EF3 G3 5"55HJ	J</r!   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    r[   zCoverageTests.setUp9  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)   tracerrg   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.
        rG   rD   coverageN)r   r(   rg   coverdirr   
descendantr$  s     r    test_coverdirDefaultz"CoverageTests.test_coverdirDefaultN  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.
        r9   r(  N)mktempr   r(   r)   rg   r)  r   child)r>   rH   r%  s      r    test_coverdirOverriddenz%CoverageTests.test_coverdirOverriddenY  sV    
 {{}--/0$78))+Xd^-A-A*-MNr!   rk   )rN   rO   rP   rQ   r  r   skipr[   r&  r+  r/  r%   r!   r    r  r  1  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    r[   zOptionsTests.setUpi  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:  r6  r7  N)r  r   setrecursionlimitgetrecursionlimitrX   	isenabledenabler%  r)   _getWorkerArgumentsassertInremoverg   )r>   argss     r    test_getWorkerArgumentsz$OptionsTests.test_getWorkerArgumentso  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}
        )--jobsr9  --debugz+You can't specify --debug when using --jobsNr   r   r%  r)   rg   rK   r>   errors     r    test_jobsConflictWithDebugz'OptionsTests.test_jobsConflictWithDebug  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}
        )rE  r9  z	--profilez-You can't specify --profile when using --jobsNrG  rH  s     r    test_jobsConflictWithProfilez)OptionsTests.test_jobsConflictWithProfile  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}
        )rE  r9  z--debug-stacktracesz7You can't specify --debug-stacktraces when using --jobsNrG  rH  s     r    %test_jobsConflictWithDebugStackTracesz2OptionsTests.test_jobsConflictWithDebugStackTraces  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alphabeticalr8  1234z-You can't specify --random when using --orderNrG  rH  s     r    test_orderConflictWithRandomz)OptionsTests.test_orderConflictWithRandom  s>    
 !!LL%%;

 	H#e*Ur!   Nrk   )
rN   rO   rP   rQ   r[   rC  rJ  rL  rN  rS  r%   r!   r    r2  r2  d  s(    '=$
T
V
 
Vr!   r2  c                  P    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y
)MakeRunnerTestsz.
    Tests for the L{_makeRunner} helper.
    c                6    t        j                         | _        y r{   r4  r_   s    r    r[   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.
        )rE  r9  
--force-gc   rX  N)
r%  r)   r   r.   
isinstancer   r   rg   _maxWorkers_workerArgumentsrb   s     r    	test_jobszMakeRunnerTests.test_jobs  sy     	!!"?@""4<<0&/222fo6F../,)@)@Ar!   c                    | j                  t        | j                  j                  ddg      }| j	                  dt        |             y)z`
        C{parseOptions} raises a C{UsageError} when C{--jobs} is passed a non-integer.
        rE  nanz-Expecting integer argument to jobs, got 'nan'NrG  r>   excs     r    test_jobsNotANumberz#MakeRunnerTests.test_jobsNotANumber  sA     11He3D
 	H#c(Sr!   c                    | j                  t        | j                  j                  ddg      }| j	                  dt        |             y)zq
        C{parseOptions} raises a C{UsageError} when C{--jobs} is passed a non-positive
        integer.
        rE  0z>Argument to jobs must be a strictly positive integer or 'auto'NrG  r`  s     r    test_jobsNonPositivez$MakeRunnerTests.test_jobsNonPositive  s?    
 
DLL,E,ERUWLcRUh	
r!   c                   | j                  t        dd        t        j                         }|j                  ddg       t        j                  |      }t        |t              sJ | j                  d|j                         y)zF
        C{--jobs auto} guesses the number of workers to use.
        r  c                      y)NM   r%   r%   r!   r    r  zEMakeRunnerTests.test_autoDetectAvailableCpusForJobs.<locals>.<lambda>  r  r!   rE  autorh  N)	rW   r   r(   r)   r.   rZ  r   rg   r[  )r>   r%  r3   s      r    #test_autoDetectAvailableCpusForJobsz3MakeRunnerTests.test_autoDetectAvailableCpusForJobs  sh     	

5+z2--/h/0""7+&/222V//0r!   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.
        )rE  r9  z	--dry-runN)
r%  r)   r   r.   rZ  r   r   rg   DRY_RUNmoderb   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!   ru  )rF  z
--debuggerrq  )rt  rK   rL   r   )	r   rr  ru  rW   r(   r)   r   _DebuggerNotFoundr.   )r>   rv  r%  ru  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.   rZ  r   r   
_exitFirstrb   s     r    test_exitfirstzMakeRunnerTests.test_exitfirst  sN    
 	!!=/2""4<<0&+...))*r!   Nrk   )rN   rO   rP   rQ   r[   r]  rb  re  rj  rn  rx  r{  r%   r!   r    rU  rU    s2    'BT
1	;O+r!   rU  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 r{   r%   r_   s    r    r  z RunTests.setUp.<locals>.<lambda>  r  r!   )rW   r   r(   r_   s    r    r[   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   rw  )rB  kwargss     r    r.   z3RunTests.test_debuggerNotFound.<locals>._makeRunner   s    ))%00r!   r.   z0Should have exited due to non-existent debugger!r   N)rB  r   r  r   rL   rM   )rW   r   r2   fail
SystemExitr@  rK   )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Nrk   )rN   rO   rP   rQ   r[   r  r%   r!   r    r}  r}    s    E
Jr!   r}  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 r{   )r   r(   r+   r   rt   r_   s    r    r[   zTestArgumentOrderTests.setUp2  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   rt   r   rg   )r>   r   r4   r   expectedSuiteexpectedNamess         r    test_preserveArgumentOrderz1TestArgumentOrderTests.test_preserveArgumentOrder6  sn    

 	  ',% !#dkk&<&<e"DE!-0.r!   Nrk   )rN   rO   rP   rQ   r[   r  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 r{   ro   r_   s    r    r[   zOrderTests.setUpO  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.
        )rP  rQ  %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   rq   loadByNamesrg   r   r>   rt   r4   s      r    test_alphabeticalzOrderTests.test_alphabeticalR  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.
        )rP  rQ  twisted.trial.test.ordertestsr   ).twisted.trial.test.ordertests.BarTest.test_bar.twisted.trial.test.ordertests.BazTest.test_bazr  r  r  r  Nr  r  s      r    test_alphabeticalModulez"OrderTests.test_alphabeticalModuleh  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.
        )rP  rQ  twisted.trial.testr   zFailed to load any tests!msgN)	r+   r)   r   rq   r  r   r   rg   sortedr>   rt   r4   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.
        )rP  toptobottomr  r   )r  r  r  r  Nr  r  s      r    test_toptobottomzOrderTests.test_toptobottom  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.
        rP  r  r  r   )r  r  r  r  r  r  Nr  r  s      r    test_toptobottomModulez!OrderTests.test_toptobottomModule  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.
        )rP  r  r  r   c                *    | j                  d      d d S )NrG   rY  )split)names    r    r  z4OrderTests.test_toptobottomPackage.<locals>.<lambda>  s    4::c?2A+> r!   )keyN)r+   r)   r   rq   r  r   rg   r  r  s       r    test_toptobottomPackagez"OrderTests.test_toptobottomPackage  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parentrH   r   insertr  rA  r  r  r   r   rN   r+   r)   r   rq   
loadModulerg   r   )r>   tempdirpackage	pathEntryr  rt   r4   s          r    test_toptobottomMissingSourcez(OrderTests.test_toptobottomMissingSource  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}.
        rP  zI don't existN)r   r   r+   r)   r_   s    r    test_unknownOrderzOrderTests.test_unknownOrder  s(    
 	009o2N	
r!   Nrk   )rN   rO   rP   rQ   r[   r  r  r  r  r  r  r  r  r%   r!   r    r  r  J  s5    &
,
./
.
.
$.
`
r!   r  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.*r  N)rW   r   r   r   r  r   r(   r)   rg   coder   
_runOrdersitemsresearchescaper   )	r>   r  ra  outputr  	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!   Nrk   )rN   rO   rP   rQ   r  r%   r!   r    r  r    s    Br!   r  )r   rK   rL   rK   rk   )r*   z	List[str]rL   trial.Options)r+   r  rL   r  )E
__future__r   rX   r  r  r   r  r   ior   typingr   r   r   hamcrestr   r   
hypothesisr	   hypothesis.strategiesr
   twisted.loggerr   twisted.pythonr   twisted.python.filepathr   r   twisted.python.usager   twisted.scriptsr   twisted.trialtwisted.trial._dist.disttrialr   twisted.trial._dist.functionalr   twisted.trial.runnerr   r   r   r   r   twisted.trial.test.test_loaderr   matchersr   
__import__r0   r   r&   r,   r5   r<   SynchronousTestCaser7   rS   rm   ry   r   r   r  TestCaser2  rU  r}  r  r  r  r%   r!   r    <module>r     s   # 	 	 	 
      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^3/H00 3/l0OH00 0OfOV8$$ OVdW+h'' W+tJx   J:/X.. /:y
"" y
xBX&& Br!   