o
    Óó·iÜ�  ã                   @  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
    N)r   ÚsibpathÚ__file__)r   © r    údC:\Users\psant\Downloads\PAF backend\school\venv\Lib\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.
    N)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.
    N)	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>   Z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   rF   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ÚgcrL   r0   r1   Ú
simpleTestr   Útest)r=   rQ   r    r    r!   ÚsetUp’   s
   
z!ForceGarbageCollectionTests.setUpc                 C  ó   | j  d¡ dS )zD
        A simple test method that records that it was run.
        rQ   N©rM   Úappend©r=   r    r    r!   rP   ™   r&   z&ForceGarbageCollectionTests.simpleTestc                 C  rS   )zI
        A replacement for gc.collect that logs calls to itself.
        rL   NrT   rV   r    r    r!   rL   Ÿ   r&   z#ForceGarbageCollectionTests.collectr   c                 C  s   t  | j¡}tƒ |_|S )zN
        Return a L{TrialRunner} object that is safe to use in tests.
        N)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)rL   rQ   rL   rL   rQ   rL   N©r,   ZpostOptionsrX   r2   rQ   ÚassertEqualrM   rW   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.
        rQ   NrY   rW   r    r    r!   Útest_unforceGcº   s   
z*ForceGarbageCollectionTests.test_unforceGcN©r   r"   )r   r   )
rG   rH   rI   rJ   rR   rP   rL   rX   r[   r\   r    r    r    r!   rK   �   s    




rK   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,   rV   r    r    r!   rR   É   ó   zSuiteUsedTests.setUpc                 C  s   t  | j¡}|  |jt¡ dS )zK
        By default, the loader should use L{DestructiveTestSuite}
        N)r   Ú
_getLoaderr,   rZ   Ú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   rb   rZ   rc   r   rd   r    r    r!   Útest_untilFailureSuiteÖ   s   
z%SuiteUsedTests.test_untilFailureSuiteNr]   )rG   rH   rI   rJ   rR   rf   rg   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 ©Nr`   rV   r    r    r!   rR   á   ó   zTestModuleTests.setUpc                 C  s
   d | _ d S rj   )r,   rV   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)rZ   r   ÚidrV   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 rj   )r   r   r   ÚmapÚ
loadByNameÚsortrZ   )r=   rp   rq   re   Znames1Znames2r    r    r!   ÚassertSuitesEqualî   s   z!TestModuleTests.assertSuitesEqualc                 C  s   |   dt| jd ƒ¡ d S )Nr   Útests)rZ   Úlenr,   rV   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   rv   r   Ú	_getSuiterV   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}   rV   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}   rV   r    r    r!   Ú test_testmoduleOnSourceAndTarget  s
   ÿz0TestModuleTests.test_testmoduleOnSourceAndTargetc                 C  rz   )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}   rV   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}   rV   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   rw   úFile ú doesn't exist
N©r   ÚsysÚstderrr,   r~   rZ   rx   Ú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   rw   N)r,   r~   r   rZ   rx   rV   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   rw   r‰   rŠ   Nr‹   )r=   r�   r�   Z
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   Ú_parseLocalVariablesrZ   ©r=   Z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™   rV   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¤   rV   r    r    r!   Útest_invalidDeclarationp  s   ÿÿz'TestModuleTests.test_invalidDeclarationc                 C  ó"   t  tdƒ¡}|  ddi|¡ d S )Nr{   r–   r|   ©r   ZloadLocalVariablesr   rZ   ©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   rZ   ©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   rZ   rx   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   rZ   Ú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   Z
isTestFiler   ZassertFalse)r=   r   r    r    r!   Útest_looksLikeTestModule›  s   þýþûz(TestModuleTests.test_looksLikeTestModuleNr]   )rp   r   rq   rr   r   r"   )rG   rH   rI   rR   rl   ro   rv   ry   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!   rh   à   s6    


















	


	




rh   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²   ÚsavedModulesrV   r    r    r!   rR   ±  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!   rl   ¹  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Ú
ModuleTyperV   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É   rV   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É   ZassertWarnsÚRuntimeWarningr   r   r,   r+   r¥   rÆ   rV   r    r    r!   Ú!test_disableAlreadyImportedModuleì  s   ûz4WithoutModuleTests.test_disableAlreadyImportedModuleNr]   )r   rÀ   )rG   rH   rI   rJ   rR   rl   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_countrZ   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)rZ   r   rÕ   rx   rÓ   rÒ   rV   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)rZ   r   rÕ   rÓ   Ú	cpu_countrV   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 rj   r    r    r    r    r!   Ú<lambda>)  ó    z4AutoJobsTests.test_cpuCountUnknown.<locals>.<lambda>rÒ   c                 S  s   t ƒ S rj   )rµ   )Úpidr    r    r!   rÜ   +  s    rÙ   c                   S  rÛ   rj   r    r    r    r    r!   rÜ   ,  rÝ   r   N)ÚhasProcessCpuCountrN   rÓ   ÚhasSchedGetaffinityrZ   r   rÕ   rV   r    r    r!   Útest_cpuCountUnknown   s   z"AutoJobsTests.test_cpuCountUnknownr]   )rG   rH   rI   rJ   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å   rV   r    r    r!   rR   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+   ZtracerrZ   rŒ   rå   Z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*   rZ   Úcoverdirr   Z
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+   rZ   rì   r   Úchild)r=   rE   ré   r    r    r!   Útest_coverdirOverriddenY  s   z%CoverageTests.test_coverdirOverriddenr]   )rG   rH   rI   rJ   rã   rŒ   ÚskiprR   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  r_   )zE
        Build an L{Options} object to be used in the tests.
        N©r   r*   ré   rV   r    r    r!   rR   i  ra   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ÚgetrecursionlimitrO   Ú	isenabledÚenableré   r+   Z_getWorkerArgumentsÚassertInÚremoverZ   )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+   rZ   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ö   Z1234z-You can't specify --random when using --orderNr  r  r    r    r!   Útest_orderConflictWithRandom©  s   ýz)OptionsTests.test_orderConflictWithRandomNr]   )
rG   rH   rI   rJ   rR   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  ri   rj   ró   rV   r    r    r!   rR   »  rk   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Ç   rZ   Ú_maxWorkersZ_workerArgumentsrW   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 )NéM   r    r    r    r    r!   rÜ   â  rÝ   zEMakeRunnerTests.test_autoDetectAvailableCpusForJobs.<locals>.<lambda>r  Úautor  N)	rN   r   r*   r+   r.   r  r   rZ   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Ç   rZ   ZDRY_RUNÚmoderW   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   ÚreflectZModuleNotFound)r   ©ÚnamedAnyr    r!   ÚnamedAnyExceptdoNotFindù  s   zFMakeRunnerTests.test_DebuggerNotFound.<locals>.namedAnyExceptdoNotFindr$  )r  z
--debuggerr!  )r   r   r   rÀ   )	r   r"  r$  rN   r*   r+   r¥   Ú_DebuggerNotFoundr.   )r=   r%  ré   r    r#  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·   Z
_exitFirstrW   r    r    r!   Útest_exitfirst  s   zMakeRunnerTests.test_exitfirstNr]   )rG   rH   rI   rJ   rR   r  r  r  r  r  r'  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Û   rj   r    rV   r    r    r!   rÜ     rÝ   z RunTests.setUp.<locals>.<lambda>)rN   r   r*   rV   r    r    r!   rR     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   r&  )rÿ   r+  r    r    r!   r.      rm   z3RunTests.test_debuggerNotFound.<locals>._makeRunnerr.   r    Nz0Should have exited due to non-existent debugger!)rÿ   rÀ   r+  rÀ   r   r"   )rN   r   r2   Ú
SystemExitrý   r   Zfail)r=   r.   Úer    r    r!   Útest_debuggerNotFound  s   
€ÿzRunTests.test_debuggerNotFoundNr]   )rG   rH   rI   rJ   rR   r.  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 rj   )r   r*   r,   r   re   rV   r    r    r!   rR   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   rs   re   rt   rZ   )r=   rw   r4   rq   ZexpectedSuiteZexpectedNamesr    r    r!   Útest_preserveArgumentOrder6  s   z1TestArgumentOrderTests.test_preserveArgumentOrderNr]   )rG   rH   rI   rJ   rR   r0  r    r    r    r!   r/  -  s    
r/  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  ri   rj   r`   rV   r    r    r!   rR   O  rk   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.FooTestrw   )ú0twisted.trial.test.ordertests.FooTest.test_firstú1twisted.trial.test.ordertests.FooTest.test_fourthú1twisted.trial.test.ordertests.FooTest.test_secondú0twisted.trial.test.ordertests.FooTest.test_thirdN©r,   r+   r   rb   ÚloadByNamesrZ   r   ©r=   re   r4   r    r    r!   Útest_alphabeticalR  s   ÿþzOrderTests.test_alphabeticalc                 C  r2  )zu
        --order=alphabetical causes trial to run test classes within a given
        module alphabetically.
        )r  r  útwisted.trial.test.ordertestsrw   )ú.twisted.trial.test.ordertests.BarTest.test_barú.twisted.trial.test.ordertests.BazTest.test_bazr4  r5  r6  r7  Nr8  r:  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.testrw   zFailed to load any tests!©ÚmsgN)	r,   r+   r   rb   r9  r   r·   rZ   Úsorted©r=   re   r4   rq   r    r    r!   Útest_alphabeticalPackage  s   z#OrderTests.test_alphabeticalPackagec                 C  r2  )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  Útoptobottomr3  rw   )r4  r6  r7  r5  Nr8  r:  r    r    r!   Útest_toptobottomŒ  s   ÿþzOrderTests.test_toptobottomc                 C  r2  )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  rG  r<  rw   )r4  r6  r7  r5  r>  r=  Nr8  r:  r    r    r!   Útest_toptobottomModule£  r@  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  rG  rA  rw   c                 S  s   |   d¡d d… S )NrD   r  )Úsplit)Únamer    r    r!   rÜ   É  s    z4OrderTests.test_toptobottomPackage.<locals>.<lambda>)ÚkeyN)r,   r+   r   rb   r9  r   rZ   rD  rE  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_missingrI  )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ï   ÚmakedirsZ
setContentÚtextwrapÚdedentÚencodeÚparentrE   rŒ   Úinsertræ   rþ   rO  rR  r²   r¾   rG   r,   r+   r   rb   Z
loadModulerZ   r   )r=   ÚtempdirÚpackageZ	pathEntryrR  re   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+   rV   r    r    r!   Útest_unknownOrderü  s   ÿzOrderTests.test_unknownOrderNr]   )rG   rH   rI   rJ   rR   r;  r?  rF  rH  rJ  rN  r[  r\  r    r    r    r!   r1  J  s    







0r1  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.*rB  N)rN   rŒ   r   r¥   r,  r   r*   r+   rZ   ÚcoderŽ   Z
_runOrdersÚitemsÚreÚsearchÚescaper·   )	r=   r^  r  ÚoutputrC  Z	orderNameZ	orderDescÚ_Úmatchr    r    r!   Ú&test_help_ordersPrintsSynopsisAndQuits  s   ÿþúz5HelpOrderTests.test_help_ordersPrintsSynopsisAndQuitsNr]   )rG   rH   rI   rJ   rg  r    r    r    r!   r]    s    r]  )r   r   r   r   r]   )r'   r(   r   r)   )r,   r)   r   r)   )EÚ
__future__r   rO   rÓ   ra  rŒ   rT  rÈ   Úior   Útypingr   r   r   Zhamcrestr   r   Z
hypothesisr   Zhypothesis.strategiesr	   Ztwisted.loggerr
   Ztwisted.pythonr   Ztwisted.python.filepathr   r   Ztwisted.python.usager   Ztwisted.scriptsr   Ztwisted.trialZtwisted.trial._dist.disttrialr   Ztwisted.trial._dist.functionalr   Ztwisted.trial.runnerr   r   r   r   r   Ztwisted.trial.test.test_loaderr   Zmatchersr   Ú
__import__r0   r   r%   r-   r5   r;   ZSynchronousTestCaser6   rK   r^   rh   r¹   rÎ   rä   ZTestCaserò   r  r*  r/  r1  r]  r    r    r    r!   Ú<module>   sZ   



	
@7 MO63RZ =