o
    >h܍                     @  sH  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Z0d@ddZ1dAddZ2dBd!d"Z3dCd$d%Z4e$e4e3Z5G d&d' d'ej6Z7G d(d) d)ej6Z8G d*d+ d+ej6Z9G d,d- d-ej6Z:G d.d/ d/ej6Z;G d0d1 d1ej6Z<G d2d3 d3ej6Z=G d4d5 d5ej>Z?G d6d7 d7ej>Z@G d8d9 d9ej>ZAG d:d; d;ej>ZBG d<d= d=ej>ZCG d>d? d?ej>ZDdS )D    )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   filenamestrreturnc                 C  s   t t| S )z1
    For finding files in twisted/trial/test
    )r   sibpath__file__)r    r    ~/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/trial/test/test_script.pyr   (   s   r   Nonec                   C  s   t  d dS )z.
    Emit something to L{twisted.logger}.
    	somethingN)r
   infor    r    r    r!   logSomething/      r%   argv	List[str]trial.Optionsc                 C  s   t  }||  |S )z?
    Parse an argument list using trial's argument parser.
    )r   OptionsparseOptions)r'   configr    r    r!   parseArguments6   s   
r-   r,   c                 C  s0   t | }t |_tttg}|| | S )zM
    Run L{logSomething} as a test method using the given configuration.
    )	r   _makeRunnerr   streamr   pyunitFunctionTestCaser%   run)r,   runnersuiter    r    r!   runFromConfig?   s
   

r5   c                   @  s^   e Zd ZdZeeg ddddZeed	d
gdddZeed	d
gdddZdS )LogfileTestsz)
    Tests for the --logfile option.
    )zdir-azdir-bzdir-c/dir-dworkingDirectoryr   r   r"   c                 C  s4   t d|g}t||d }t|ttd dS )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   )selfr7   r,   logPathr    r    r!   test_defaultR      zLogfileTests.test_defaultzsomelog.txtzsomedir/somelog.txtr9   c                 C  s4   t d|g}t|d |}t|ttd dS )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>   r    r    r!   test_relativePathd   r@   zLogfileTests.test_relativePathc                 C  s6   t d|}td|jg |}t|ttd dS )z
        If the value given for the option is an absolute path then it is
        interpreted absolutely and logs are written there.
        .rA   r#   N)r   r<   r;   pathr   r   r   )r=   r9   r>   iPathr    r    r!   test_absolutePathv   s   zLogfileTests.test_absolutePathN)r7   r   r   r"   )r9   r   r   r"   )	__name__
__module____qualname____doc__r   r	   r?   rC   rG   r    r    r    r!   r6   M   s0    		
r6   c                   @  sL   e Zd ZdZdddZdddZddd	ZdddZdddZdddZ	dS )ForceGarbageCollectionTestsz*
    Tests for the --force-gc option.
    r   r"   c                 C  s>   t  | _g | _| td| j t| j	}t
||g| _d S )Ncollect)r   r*   r,   logpatchgcrM   r0   r1   
simpleTestr   test)r=   rR   r    r    r!   setUp   s
   
z!ForceGarbageCollectionTests.setUpc                 C     | j d dS )zD
        A simple test method that records that it was run.
        rR   NrN   appendr=   r    r    r!   rQ      r&   z&ForceGarbageCollectionTests.simpleTestc                 C  rT   )zI
        A replacement for gc.collect that logs calls to itself.
        rM   NrU   rW   r    r    r!   rM      r&   z#ForceGarbageCollectionTests.collectr   c                 C  s   t | j}t |_|S )zN
        Return a L{TrialRunner} object that is safe to use in tests.
        )r   r.   r,   r   r/   r=   r3   r    r    r!   
makeRunner   s   z&ForceGarbageCollectionTests.makeRunnerc                 C  s>   d| j d< | j   |  }|| j | | jg d dS )z
        Passing the --force-gc option to the trial script forces the garbage
        collector to run before and after each test.
        Tzforce-gc)rM   rR   rM   rM   rR   rM   Nr,   postOptionsrY   r2   rR   assertEqualrN   rX   r    r    r!   test_forceGc   s   


z(ForceGarbageCollectionTests.test_forceGcc                 C  s4   | j   |  }|| j | | jddg dS )z>
        By default, no garbage collection is forced.
        rR   NrZ   rX   r    r    r!   test_unforceGc   s   
z*ForceGarbageCollectionTests.test_unforceGcNr   r"   )r   r   )
rH   rI   rJ   rK   rS   rQ   rM   rY   r]   r^   r    r    r    r!   rL      s    




rL   c                   @  s.   e Zd ZdZdddZdddZddd	Zd
S )SuiteUsedTestsz?
    Check the category of tests suite used by the loader.
    r   r"   c                 C     t  | _dS )z6
        Create a trial configuration object.
        Nr   r*   r,   rW   r    r    r!   rS         zSuiteUsedTests.setUpc                 C  s   t | j}| |jt dS )zK
        By default, the loader should use L{DestructiveTestSuite}
        N)r   
_getLoaderr,   r\   suiteFactoryr   r=   loaderr    r    r!   test_defaultSuite   s   z SuiteUsedTests.test_defaultSuitec                 C  s(   d| j d< t| j }| |jt dS )zw
        The C{until-failure} configuration uses the L{TestSuite} to keep
        instances alive across runs.
        Tzuntil-failureN)r,   r   rd   r\   re   r   rf   r    r    r!   test_untilFailureSuite   s   
z%SuiteUsedTests.test_untilFailureSuiteNr_   )rH   rI   rJ   rK   rS   rh   ri   r    r    r    r!   r`      s
    

r`   c                   @  s  e Zd Zd<ddZd<ddZd<ddZd=ddZd<ddZd<ddZd<ddZ	d<ddZ
d<ddZd<ddZd<ddZd<ddZd<dd Zd<d!d"Zd<d#d$Zd<d%d&Zd<d'd(Zd<d)d*Zd<d+d,Zd<d-d.Zd<d/d0Zd<d1d2Zd<d3d4Zd<d5d6Zd<d7d8Zd<d9d:Zd;S )>TestModuleTestsr   r"   c                 C     t  | _d S Nrb   rW   r    r    r!   rS         zTestModuleTests.setUpc                 C  s
   d | _ d S rl   )r,   rW   r    r    r!   tearDown      
zTestModuleTests.tearDownc                 C  s   |  t| |  g dS )zq
        Check that the testNames helper method accurately collects the
        names of tests in suite.
        N)r\   r   idrW   r    r    r!   test_testNames   s   zTestModuleTests.test_testNamestest1r   names	list[str]c                 C  sB   t  }t|}ttt|j|}|  |  | || d S rl   )r   r   r   map
loadByNamesortr\   )r=   rr   rs   rg   names1names2r    r    r!   assertSuitesEqual   s   z!TestModuleTests.assertSuitesEqualc                 C  s   |  dt| jd  d S )Nr   tests)r\   lenr,   rW   r    r    r!   test_baseState   s   zTestModuleTests.test_baseStatec                 C  *   | j td | t| j dg dS )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   rz   r   	_getSuiterW   r    r    r!   test_testmoduleOnModule      z'TestModuleTests.test_testmoduleOnModulec                 C  s:   | j td | j td | t| j dg dS )z
        When the same module is specified with two --testmodule flags, it
        should only appear once in the suite.
        r   r   Nr   rW   r    r    r!   test_testmoduleTwice  s
   z$TestModuleTests.test_testmoduleTwicec                 C  s:   | j td | j td | t| j dg dS )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   rW   r    r    r!    test_testmoduleOnSourceAndTarget  s
   z0TestModuleTests.test_testmoduleOnSourceAndTargetc                 C  r~   )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   rW   r    r    r!   test_testmoduleOnSelfModule  r   z+TestModuleTests.test_testmoduleOnSelfModulec                 C  s,   | j td | t| j ddg dS )zm
        Check that --testmodule loads tests referred to in test-case-name
        buffer variables.
        scripttest.pyr   twisted.trial.test.test_runnerNr   rW   r    r    r!   test_testmoduleOnScript$  s
   
z'TestModuleTests.test_testmoduleOnScriptc                 C  h   t  }tj|}t_d}z#| j| | dt| jd  | d|d|  W |t_dS |t_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   r\   r|   getvalue)r=   buffyr   r   r    r    r!    test_testmoduleOnNonexistentFile/     z0TestModuleTests.test_testmoduleOnNonexistentFilec                 C  s*   | j td | dt| j d  dS )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   r\   r|   rW   r    r    r!   test_testmoduleOnEmptyVars>  s   z*TestModuleTests.test_testmoduleOnEmptyVarsc                 C  r   )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   
moduleNamer    r    r!   test_testmoduleOnModuleNameF  r   z+TestModuleTests.test_testmoduleOnModuleNamec                 C  "   d}t |}| ddi| d S )Nz5-*- test-case-name: twisted.trial.test.test_tests -*-test-case-nametwisted.trial.test.test_testsr   _parseLocalVariablesr\   r=   declaration	localVarsr    r    r!   test_parseLocalVariableU     
z'TestModuleTests.test_parseLocalVariablec                 C  r   )Nz6-*- test-case-name: twisted.trial.test.test_tests; -*-r   r   r   r   r    r    r!   test_trailingSemicolonZ  r   z&TestModuleTests.test_trailingSemicolonc                 C  s$   d}t |}| ddd| d S )Nz?-*- test-case-name: twisted.trial.test.test_tests; foo: bar -*-r   bar)r   foor   r   r    r    r!   test_parseLocalVariables_  s   

z(TestModuleTests.test_parseLocalVariablesc                 C  r   )Nz:## -*- test-case-name: twisted.trial.test.test_tests -*- #r   r   r   r   r    r    r!   test_surroundingGuffh  r   z$TestModuleTests.test_surroundingGuffc                 C  s   |  ttjd d S Nr   assertRaises
ValueErrorr   r   rW   r    r    r!   test_invalidLinem  s   z TestModuleTests.test_invalidLinec                 C  s4   |  ttjd |  ttjd |  ttjd d S )Nz-*- foo -*-z-*- foo: bar; qux -*-z-*- foo: bar: baz; qux: qax -*-r   rW   r    r    r!   test_invalidDeclarationp  s   z'TestModuleTests.test_invalidDeclarationc                 C  "   t td}| ddi| d S )Nr   r   r   r   loadLocalVariablesr   r\   r=   r   r    r    r!   test_variablesFromFiley     z&TestModuleTests.test_variablesFromFilec                 C  s   t td}| i | d S )Nr   r   r   r    r    r!   test_noVariablesInFile}  s   z&TestModuleTests.test_noVariablesInFilec                 C  r   )Nr   r   z:twisted.trial.test.test_log,twisted.trial.test.test_runnerr   r   r    r    r!   test_variablesFromScript  s   z(TestModuleTests.test_variablesFromScriptc                 C  s    t td}| |dg d S )Nr   r   )r   getTestModulesr   r\   r=   modulesr    r    r!   test_getTestModules  s   z#TestModuleTests.test_getTestModulesc                 C  s"   t td}| t|d d S )Nr   r   )r   r   r   r\   r|   r   r    r    r!   test_getTestModules_noVars  r   z*TestModuleTests.test_getTestModules_noVarsc                 C  s&   t td}| t|ddh d S )Nr   r   r   )r   r   r   r\   setr   r    r    r!   test_getTestModules_multiple  s
   z,TestModuleTests.test_getTestModules_multiplec                 C  sV   dD ]}|  t||d qdtdtdfD ]}| t||d qd S )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   r    r    r!   test_looksLikeTestModule  s   z(TestModuleTests.test_looksLikeTestModuleNr_   )rr   r   rs   rt   r   r"   )rH   rI   rJ   rS   rn   rq   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!   rj      s6    


















	


	




rj   c                   @  sV   e Zd ZdZdddZdddZdd	d
ZdddZdddZdddZ	dddZ
dS )WithoutModuleTestsz*
    Test the C{without-module} flag.
    r   r"   c                 C  s   t  | _ttj| _dS )zl
        Create a L{trial.Options} object to be used in the tests, and save
        C{sys.modules}.
        N)r   r*   r,   dictr   r   savedModulesrW   r    r    r!   rS     s   
zWithoutModuleTests.setUpc                 C  s8   dD ]}|| j v r| j | tj|< qtj|d qdS )z)
        Restore C{sys.modules}.
        )imaplibsmtplibN)r   r   r   pop)r=   moduler    r    r!   rn     s
   
zWithoutModuleTests.tearDownobjectc                 C     ddl }|S )zE
        Try to import the C{smtplib} module, and return it.
        r   N)r   )r=   r   r    r    r!   
_checkSMTP     zWithoutModuleTests._checkSMTPc                 C  r   )zE
        Try to import the C{imaplib} module, and return it.
        r   N)r   )r=   r   r    r    r!   
_checkIMAP  r   zWithoutModuleTests._checkIMAPc                 C  s<   | j ddg | t| j tjd= | |  tj	 dS )zT
        Check that after disabling a module, it can't be imported anymore.
        --without-moduler   N)
r,   r+   r   ImportErrorr   r   r   assertIsInstancetypes
ModuleTyperW   r    r    r!   test_disableOneModule  s   z(WithoutModuleTests.test_disableOneModulec                 C  sd   | j ddg | t| j | t| j tjd= tjd= | |  t	j
 | |  t	j
 dS )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   rW   r    r    r!   test_disableMultipleModules  s   z.WithoutModuleTests.test_disableMultipleModulesc                 C  s@   |  |  tj | tdtj| jj	ddg | 
t| j dS )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   rW   r    r    r!   !test_disableAlreadyImportedModule  s   z4WithoutModuleTests.test_disableAlreadyImportedModuleNr_   )r   r   )rH   rI   rJ   rK   rS   rn   r   r   r   r   r   r    r    r    r!   r     s    






r   c                   @  sv   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	d
Ze
ep'e	 ddddZdddZdddZdS )AutoJobsTestsz0
    Test {twisted.scripts.trial._autoJobs}
    N   )      sched_getaffinityzRequires os.process_cpu_count()r   r"   c                 C  s   t  }| t | dS )zt
        When `os.process_cpu_count()` is available (Python 3.13+), `_autoJobs`
        returns its result.
        N)osprocess_cpu_countr\   r   	_autoJobs)r=   countr    r    r!   test_processCpuCount  s   z"AutoJobsTests.test_processCpuCountz>Requires os.sched_getaffinity() without os.process_cpu_count()c                 C  s   |  t ttd dS )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)r\   r   r   r|   r   r   rW   r    r    r!   test_schedGetAffinity  s   z#AutoJobsTests.test_schedGetAffinityc                 C  s   |  t t  dS )zb
        When only `os.cpu_count()` is available, `_autoJobs` returns
        its result.
        N)r\   r   r   r   	cpu_countrW   r    r    r!   test_cpuCount  s   zAutoJobsTests.test_cpuCountc                 C  sV   | j r| tddd  | jr| tddd  | tddd  | t d d	S )
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                   S     d S rl   r    r    r    r    r!   <lambda>)      z4AutoJobsTests.test_cpuCountUnknown.<locals>.<lambda>r   c                 S  s   t  S rl   )r   )pidr    r    r!   r   +  s    r   c                   S  r   rl   r    r    r    r    r!   r   ,  r   r   N)hasProcessCpuCountrO   r   hasSchedGetaffinityr\   r   r   rW   r    r    r!   test_cpuCountUnknown   s   z"AutoJobsTests.test_cpuCountUnknownr_   )rH   rI   rJ   rK   r   version_infor   getattrr   r   r   r   r   r   r   r    r    r    r!   r     s    

	r   c                   @  sL   e Zd ZdZeedddu rdZdddZdd	d
ZdddZ	dddZ
dS )CoverageTestsz+
    Tests for the I{coverage} option.
    gettraceNz;Cannot test trace hook installation without inspection API.r   r"   c                 C  s   |  tjt  dS )zf
        Arrange for the current trace hook to be restored when the
        test is complete.
        N)
addCleanupr   settracer   rW   r    r    r!   rS   9  s   zCoverageTests.setUpc                 C  s:   t  }|dg |jdusJ | t |jj dS )z}
        L{trial.Options} handles C{"--coverage"} by installing a trace
        hook to record coverage information.
        z
--coverageN)r   r*   r+   tracerr\   r   r   globaltracer=   optionsr    r    r!   test_tracerInstalled@  s   z"CoverageTests.test_tracerInstalledc                 C  s.   t  }| | td|d dg dS )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.
        rD   rB   coverageN)r   r*   r\   coverdirr   
descendantr   r    r    r!   test_coverdirDefaultN  s
   z"CoverageTests.test_coverdirDefaultc                 C  s<   |   }t }|d|g | | t|d dS )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+   r\   r   r   child)r=   rE   r   r    r    r!   test_coverdirOverriddenY  s   z%CoverageTests.test_coverdirOverriddenr_   )rH   rI   rJ   rK   r   r   skiprS   r   r   r   r    r    r    r!   r   1  s    


r   c                   @  sL   e Zd ZdZdddZdddZddd	Zdd
dZdddZdddZ	dS )OptionsTestsz%
    Tests for L{trial.Options}.
    r   r"   c                 C  ra   )zE
        Build an L{Options} object to be used in the tests.
        Nr   r*   r   rW   r    r    r!   rS   i  rc   zOptionsTests.setUpc                 C  sj   |  tjt  t r|  tj | jg d | j	 }| 
d| |d | ddg| dS )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getrecursionlimitrP   	isenabledenabler   r+   _getWorkerArgumentsassertInremover\   )r=   argsr    r    r!   test_getWorkerArgumentso  s   

z$OptionsTests.test_getWorkerArgumentsc                 C  *   |  t| jjg d}| dt| dS )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+   r\   r   r=   errorr    r    r!   test_jobsConflictWithDebug     z'OptionsTests.test_jobsConflictWithDebugc                 C  r  )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  r    r    r!   test_jobsConflictWithProfile  r  z)OptionsTests.test_jobsConflictWithProfilec                 C  r  )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  r    r    r!   %test_jobsConflictWithDebugStackTraces  s   z2OptionsTests.test_jobsConflictWithDebugStackTracesc                 C  r  )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  r    r    r!   test_orderConflictWithRandom  s   z)OptionsTests.test_orderConflictWithRandomNr_   )
rH   rI   rJ   rK   rS   r  r  r  r  r  r    r    r    r!   r   d  s    




r   c                   @  s`   e Zd ZdZdddZdddZddd	Zdd
dZdddZdddZ	dddZ
dddZdS )MakeRunnerTestsz.
    Tests for the L{_makeRunner} helper.
    r   r"   c                 C  rk   rl   r   rW   r    r    r!   rS     rm   zMakeRunnerTests.setUpc                 C  sX   | j g d t| j }t|tsJ | |t | d|j | dg|j	 dS )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   r\   _maxWorkers_workerArgumentsrX   r    r    r!   	test_jobs  s   zMakeRunnerTests.test_jobsc                 C  *   |  t| jjddg}| dt| dS )z`
        C{parseOptions} raises a C{UsageError} when C{--jobs} is passed a non-integer.
        r  nanz-Expecting integer argument to jobs, got 'nan'Nr  r=   excr    r    r!   test_jobsNotANumber  s   z#MakeRunnerTests.test_jobsNotANumberc                 C  r$  )zq
        C{parseOptions} raises a C{UsageError} when C{--jobs} is passed a non-positive
        integer.
        r  0z>Argument to jobs must be a strictly positive integer or 'auto'Nr  r&  r    r    r!   test_jobsNonPositive  s   z$MakeRunnerTests.test_jobsNonPositivec                 C  sR   |  tddd  t }|ddg t|}t|ts J | d|j dS )zF
        C{--jobs auto} guesses the number of workers to use.
        r   c                   S  s   dS )NM   r    r    r    r    r!   r     r   zEMakeRunnerTests.test_autoDetectAvailableCpusForJobs.<locals>.<lambda>r  autor+  N)	rO   r   r*   r+   r.   r   r   r\   r!  )r=   r   r3   r    r    r!   #test_autoDetectAvailableCpusForJobs  s   
z3MakeRunnerTests.test_autoDetectAvailableCpusForJobsc                 C  sJ   | j g d t| j }t|tsJ | |t | tj|j	 dS )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   r\   DRY_RUNmoderX   r    r    r!   test_dryRunWithJobs  s
   z#MakeRunnerTests.test_dryRunWithJobsc                   sR   t jj d	 fdd}| t jd| t  }|g d | t jt j| d S )
Nfqnr   r   r   c                   s   | dkr
t j|  | S )N	doNotFind)r   reflectModuleNotFound)r1  namedAnyr    r!   namedAnyExceptdoNotFind  s   zFMakeRunnerTests.test_DebuggerNotFound.<locals>.namedAnyExceptdoNotFindr6  )r  z
--debuggerr2  )r1  r   r   r   )	r   r3  r6  rO   r*   r+   r   _DebuggerNotFoundr.   )r=   r7  r   r    r5  r!   test_DebuggerNotFound  s   z%MakeRunnerTests.test_DebuggerNotFoundc                 C  s8   | j dg t| j }t|tsJ | |j dS )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   
_exitFirstrX   r    r    r!   test_exitfirst  s   zMakeRunnerTests.test_exitfirstNr_   )rH   rI   rJ   rK   rS   r#  r(  r*  r-  r0  r9  r;  r    r    r    r!   r    s    



	



r  c                   @  $   e Zd ZdZd	ddZd	ddZdS )
RunTestsz(
    Tests for the L{run} function.
    r   r"   c                 C  s   |  tjddd  d S )Nr+   c                 S  r   rl   r    rW   r    r    r!   r     r   z RunTests.setUp.<locals>.<lambda>)rO   r   r*   rW   r    r    r!   rS     s   zRunTests.setUpc              
   C  sj   ddd}|  td| zt  W n ty- } z| d	t| W Y d
}~d
S d
}~ww | d d
S )zY
        When a debugger is not found, an error message is printed to the user.

        r  r   kwargsr   r"   c                  _  s
   t dr   )r   r8  )r  r>  r    r    r!   r.      ro   z3RunTests.test_debuggerNotFound.<locals>._makeRunnerr.   r   Nz0Should have exited due to non-existent debugger!)r  r   r>  r   r   r"   )rO   r   r2   
SystemExitr  r   fail)r=   r.   er    r    r!   test_debuggerNotFound  s   
zRunTests.test_debuggerNotFoundNr_   )rH   rI   rJ   rK   rS   rB  r    r    r    r!   r=    s    
r=  c                   @  r<  )
TestArgumentOrderTestszQ
    Tests for the order-preserving behavior on provided command-line tests.
    r   r"   c                 C  s   t  | _t | _d S rl   )r   r*   r,   r   rg   rW   r    r    r!   rS   2  s   
zTestArgumentOrderTests.setUpc                 C  sR   g d}| j | t| j }t|}tt| jj|}t|}| 	|| dS )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   ru   rg   rv   r\   )r=   r{   r4   rs   expectedSuiteexpectedNamesr    r    r!   test_preserveArgumentOrder6  s   z1TestArgumentOrderTests.test_preserveArgumentOrderNr_   )rH   rI   rJ   rK   rS   rF  r    r    r    r!   rC  -  s    
rC  c                   @  sj   e Zd ZdZdddZdddZddd	Zdd
dZdddZdddZ	dddZ
dddZdddZdS )
OrderTestsz'
    Tests for the --order option.
    r   r"   c                 C  rk   rl   rb   rW   r    r    r!   rS   O  rm   zOrderTests.setUpc                 C  D   | j g d t| j }|| j d }| t|g d dS )zn
        --order=alphabetical causes trial to run tests alphabetically within
        each test case.
        )r  r  %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   rd   loadByNamesr\   r   r=   rg   r4   r    r    r!   test_alphabeticalR  s   zOrderTests.test_alphabeticalc                 C  rH  )zu
        --order=alphabetical causes trial to run test classes within a given
        module alphabetically.
        )r  r  twisted.trial.test.ordertestsr{   ).twisted.trial.test.ordertests.BarTest.test_bar.twisted.trial.test.ordertests.BazTest.test_bazrJ  rK  rL  rM  NrN  rP  r    r    r!   test_alphabeticalModuleh     z"OrderTests.test_alphabeticalModulec                 C  sV   | j g d t| j }|| j d }t|}| j|dd | |t| dS )z
        --order=alphabetical causes trial to run test modules within a given
        package alphabetically, with tests within each module alphabetized.
        )r  r  twisted.trial.testr{   zFailed to load any tests!msgN)	r,   r+   r   rd   rO  r   r   r\   sortedr=   rg   r4   rs   r    r    r!   test_alphabeticalPackage  s   z#OrderTests.test_alphabeticalPackagec                 C  rH  )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.
        )r  toptobottomrI  r{   )rJ  rL  rM  rK  NrN  rP  r    r    r!   test_toptobottom  s   zOrderTests.test_toptobottomc                 C  rH  )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.
        r  r]  rR  r{   )rJ  rL  rM  rK  rT  rS  NrN  rP  r    r    r!   test_toptobottomModule  rV  z!OrderTests.test_toptobottomModulec                 C  sP   | j g d t| j }|| j d }t|}| |t|dd d dS )z
        --order=toptobottom causes trial to run test modules within a given
        package alphabetically, with tests within each module run top to
        bottom.
        )r  r]  rW  r{   c                 S  s   |  dd d S )NrD   r  )split)namer    r    r!   r     s    z4OrderTests.test_toptobottomPackage.<locals>.<lambda>)keyN)r,   r+   r   rd   rO  r   r\   rZ  r[  r    r    r!   test_toptobottomPackage  s   z"OrderTests.test_toptobottomPackagec                 C  s   |   }t|d}|  |dd |dtdd | j	}t
j	d| | t
j	j| ddlm} | t
jjd | t
jj|j |d  | jg d	 t| j}||}| t|g d
 dS )z{
        --order=toptobottom detects the source line of methods from modules
        whose source file is missing.
        twisted_toptobottom_tempz__init__.py    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parentrE   r   insertr   r  re  rh  r   r   rH   r,   r+   r   rd   
loadModuler\   r   )r=   tempdirpackage	pathEntryrh  rg   r4   r    r    r!   test_toptobottomMissingSource  s4   
	

z(OrderTests.test_toptobottomMissingSourcec                 C  s   |  t| jjddg dS )zL
        An unknown order passed to --order raises a L{UsageError}.
        r  zI don't existN)r   r   r,   r+   rW   r    r    r!   test_unknownOrder  s   zOrderTests.test_unknownOrderNr_   )rH   rI   rJ   rK   rS   rQ  rU  r\  r^  r`  rd  rt  ru  r    r    r    r!   rG  J  s    







0rG  c                   @  s   e Zd ZdZdddZdS )HelpOrderTestsz+
    Tests for the --help-orders flag.
    r   r"   c           	      C  s   |  tdt  } | tt jdg}| |j	d |
 }d}tj D ]"\}\}}tt| dt| |}| j||||f d q'dS )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.*rX  N)rO   r   r   r   r?  r   r*   r+   r\   coder   
_runOrdersitemsresearchescaper   )	r=   rw  r'  outputrY  	orderName	orderDesc_matchr    r    r!   &test_help_ordersPrintsSynopsisAndQuits  s   z5HelpOrderTests.test_help_ordersPrintsSynopsisAndQuitsNr_   )rH   rI   rJ   rK   r  r    r    r    r!   rv    s    rv  )r   r   r   r   r_   )r'   r(   r   r)   )r,   r)   r   r)   )E
__future__r   rP   r   r{  r   rk  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;   SynchronousTestCaser6   rL   r`   rj   r   r   r   TestCaser   r  r=  rC  rG  rv  r    r    r    r!   <module>   sZ   



	
@7 MO63RZ =