o
    ¯bÁr  ã                   @   sz  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 d dlmZ d dlmZ d dlmZ d d	lmZmZmZmZ d d
lmZ edƒZdd„ ZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZ G dd„ dejƒZ!G dd„ dejƒZ"G dd„ dej#ƒZ$G dd„ dej#ƒZ%G dd„ dej#ƒZ&G dd„ dej#ƒZ'G d d!„ d!ej#ƒZ(G d"d#„ d#ej#ƒZ)dS )$é    N)ÚStringIO)Úutil)ÚFilePath)Ú
UsageError)Útrial)Úunittest)ÚDistTrialRunner)ÚDestructiveTestSuiteÚ
TestLoaderÚ	TestSuiteÚTrialRunner)Ú	testNamesr   c                 C   s   t  t| ¡S )z1
    For finding files in twisted/trial/test
    )r   ÚsibpathÚ__file__)Úfilename© r   ú@/usr/lib/python3/dist-packages/twisted/trial/test/test_script.pyr      s   r   c                   @   s@   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S )ÚForceGarbageCollectionTestsz*
    Tests for the --force-gc option.
    c                 C   s>   t  ¡ | _g | _|  td| j¡ t | j	¡}t
||gƒ| _d S )NÚcollect)r   ÚOptionsÚconfigÚlogÚpatchÚgcr   ÚpyunitÚFunctionTestCaseÚ
simpleTestr   Útest)Úselfr   r   r   r   ÚsetUp)   s
   
z!ForceGarbageCollectionTests.setUpc                 C   ó   | j  d¡ dS )zD
        A simple test method that records that it was run.
        r   N©r   Úappend©r   r   r   r   r   0   ó   z&ForceGarbageCollectionTests.simpleTestc                 C   r    )zI
        A replacement for gc.collect that logs calls to itself.
        r   Nr!   r#   r   r   r   r   6   r$   z#ForceGarbageCollectionTests.collectc                 C   s   t  | j¡}tƒ |_|S )zN
        Return a L{TrialRunner} object that is safe to use in tests.
        )r   Ú_makeRunnerr   r   Ústream©r   Úrunnerr   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)r   r   r   r   r   r   N©r   ÚpostOptionsr)   Úrunr   ÚassertEqualr   r'   r   r   r   Útest_forceGcD   s   


ÿz(ForceGarbageCollectionTests.test_forceGcc                 C   s4   | j  ¡  |  ¡ }| | j¡ |  | jddg¡ dS )z>
        By default, no garbage collection is forced.
        r   Nr*   r'   r   r   r   Útest_unforceGcQ   s   
z*ForceGarbageCollectionTests.test_unforceGcN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r)   r.   r/   r   r   r   r   r   $   s    r   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚSuiteUsedTestsz?
    Check the category of tests suite used by the loader.
    c                 C   ó   t  ¡ | _dS )z6
        Create a trial configuration object.
        N©r   r   r   r#   r   r   r   r   `   ó   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_defaultSuitef   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   r8   r-   r9   r   r:   r   r   r   Útest_untilFailureSuitem   s   
z%SuiteUsedTests.test_untilFailureSuiteN)r0   r1   r2   r3   r   r<   r=   r   r   r   r   r4   [   s
    r4   c                   @   sÜ   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/d0„ Zd1d2„ Zd3d4„ Zd5S )6ÚTestModuleTestsc                 C   ó   t  ¡ | _d S ©Nr6   r#   r   r   r   r   x   ó   zTestModuleTests.setUpc                 C   s
   d | _ d S r@   )r   r#   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   Úidr#   r   r   r   Útest_testNames~   s   zTestModuleTests.test_testNamesc                 C   sB   t ƒ }t|ƒ}ttt|j|ƒƒƒ}| ¡  | ¡  |  ||¡ d S r@   )r
   r   r   ÚmapÚ
loadByNameÚsortr-   )r   Útest1Únamesr;   Únames1Únames2r   r   r   ÚassertSuitesEqual…   s   z!TestModuleTests.assertSuitesEqualc                 C   s   |   dt| jd ƒ¡ d S )Nr   Útests)r-   Úlenr   r#   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   rM   r   Ú	_getSuiter#   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.
        rR   rS   NrT   r#   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.
        rR   ztest_log.pyrS   NrT   r#   r   r   r   Ú test_testmoduleOnSourceAndTarget¥   s
   ÿz0TestModuleTests.test_testmoduleOnSourceAndTargetc                 C   rQ   )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.moduleselfNrT   r#   r   r   r   Útest_testmoduleOnSelfModule±   rX   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.pyrS   útwisted.trial.test.test_runnerNrT   r#   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   rN   úFile ú doesn't exist
N©r   ÚsysÚstderrr   rU   r-   rO   Úgetvalue)r   Úbuffyrd   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   rN   N)r   rU   r   r-   rO   r#   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   rN   r`   ra   Nrb   )r   rf   rd   Ú
moduleNamer   r   r   Útest_testmoduleOnModuleNameÝ   rh   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_parseLocalVariableì   ó   
z'TestModuleTests.test_parseLocalVariablec                 C   rm   )Nz6-*- test-case-name: twisted.trial.test.test_tests; -*-rn   ro   rp   rr   r   r   r   Útest_trailingSemicolonñ   rv   z&TestModuleTests.test_trailingSemicolonc                 C   s$   d}t  |¡}|  dddœ|¡ d S )Nz?-*- test-case-name: twisted.trial.test.test_tests; foo: bar -*-ro   Úbar)rn   Úfoorp   rr   r   r   r   Útest_parseLocalVariablesö   s   ÿ

ÿz(TestModuleTests.test_parseLocalVariablesc                 C   rm   )Nz:## -*- test-case-name: twisted.trial.test.test_tests -*- #rn   ro   rp   rr   r   r   r   Útest_surroundingGuffÿ   rv   z$TestModuleTests.test_surroundingGuffc                 C   s   |   ttjd¡ d S ©Nry   ©ÚassertRaisesÚ
ValueErrorr   rq   r#   r   r   r   Útest_invalidLine  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}   r#   r   r   r   Útest_invalidDeclaration  s   ÿÿz'TestModuleTests.test_invalidDeclarationc                 C   ó"   t  tdƒ¡}|  ddi|¡ d S )NrR   rn   rS   ©r   ÚloadLocalVariablesr   r-   ©r   rt   r   r   r   Útest_variablesFromFile  ó   z&TestModuleTests.test_variablesFromFilec                 C   s   t  tdƒ¡}|  i |¡ d S )Nri   rƒ   r…   r   r   r   Útest_noVariablesInFile  s   z&TestModuleTests.test_noVariablesInFilec                 C   r‚   )Nr\   rn   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 )NrR   rS   )r   ÚgetTestModulesr   r-   ©r   Úmodulesr   r   r   Útest_getTestModules#  s   z#TestModuleTests.test_getTestModulesc                 C   s"   t  tdƒ¡}|  t|ƒd¡ d S )Nri   r   )r   rŠ   r   r-   rO   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\   rS   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_looksLikeTestModule2  s   þýþûz(TestModuleTests.test_looksLikeTestModuleN)r0   r1   r2   r   rB   rE   rM   rP   rW   rY   rZ   r[   r^   rg   rj   rl   ru   rw   rz   r{   r€   r�   r†   rˆ   r‰   r�   rŽ   r�   r”   r   r   r   r   r>   w   s6    

		r>   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
dS )ÚWithoutModuleTestsz*
    Test the C{without-module} flag.
    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   Údictrc   rŒ   ÚsavedModulesr#   r   r   r   r   H  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˜   rc   rŒ   Úpop)r   Úmoduler   r   r   rB   P  s
   
üzWithoutModuleTests.tearDownc                 C   ó   ddl }|S )zE
        Try to import the C{smtplib} module, and return it.
        r   N)rš   )r   rš   r   r   r   Ú
_checkSMTPZ  ó   zWithoutModuleTests._checkSMTPc                 C   r�   )zE
        Try to import the C{imaplib} module, and return it.
        r   N)r™   )r   r™   r   r   r   Ú
_checkIMAPb  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   ÚparseOptionsr~   ÚImportErrorrž   rc   rŒ   ÚassertIsInstanceÚtypesÚ
ModuleTyper#   r   r   r   Útest_disableOneModulej  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    rc   rŒ   r¤   r¥   r¦   r#   r   r   r   Útest_disableMultipleModulesu  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£   r#   r   r   r   Ú!test_disableAlreadyImportedModuleƒ  s   ûz4WithoutModuleTests.test_disableAlreadyImportedModuleN)r0   r1   r2   r3   r   rB   rž   r    r§   r¨   r«   r   r   r   r   r–   C  s    
r–   c                   @   sD   e Zd ZdZeeddƒdu rdZdd„ Zdd„ Zd	d
„ Z	dd„ Z
dS )ÚCoverageTestsz+
    Tests for the I{coverage} option.
    ÚgettraceNz;Cannot test trace hook installation without inspection API.c                 C   s   |   tjt ¡ ¡ dS )zf
        Arrange for the current trace hook to be restored when the
        test is complete.
        N)Ú
addCleanuprc   Úsettracer­   r#   r   r   r   r   š  s   zCoverageTests.setUpc                 C   s,   t  ¡ }| dg¡ |  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¢   r-   rc   r­   ÚtracerÚ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.
        Ú.ztemp-directoryÚcoverageN)r   r   r-   Úcoverdirr   Ú
descendantr²   r   r   r   Útest_coverdirDefaultª  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.
        z--temp-directoryr¶   N)Úmktempr   r   r¢   r-   r·   r   Úchild)r   Úpathr³   r   r   r   Útest_coverdirOverriddenµ  s   z%CoverageTests.test_coverdirOverridden)r0   r1   r2   r3   Úgetattrrc   Úskipr   r´   r¹   r½   r   r   r   r   r¬   ’  s    	r¬   c                   @   r•   )ÚOptionsTestsz%
    Tests for L{trial.Options}.
    c                 C   r5   )zE
        Build an L{Options} object to be used in the tests.
        N©r   r   r³   r#   r   r   r   r   Å  r7   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®   rc   ÚsetrecursionlimitÚgetrecursionlimitr   Ú	isenabledÚenabler³   r¢   Ú_getWorkerArgumentsÚassertInÚremover-   )r   Úargsr   r   r   Útest_getWorkerArgumentsË  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-   Ústr©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Ð   )zÅ
        C{parseOptions} raises a C{UsageError} when C{--exitfirst} is passed
        along C{--jobs} as it's not supported yet.

        @see: U{http://twistedmatrix.com/trac/ticket/6436}
        )rÑ   rÅ   ú--exitfirstz/You can't specify --exitfirst when using --jobsNrÓ   rÕ   r   r   r   Útest_jobsConflictWithExitFirst  rØ   z+OptionsTests.test_jobsConflictWithExitFirstc                 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_orderConflictWithRandomN)r0   r1   r2   r3   r   rÏ   r×   rÙ   rÚ   rÜ   rà   r   r   r   r   rÀ   À  s    rÀ   c                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚMakeRunnerTestsz.
    Tests for the L{_makeRunner} helper.
    c                 C   r?   r@   rÁ   r#   r   r   r   r   #  rA   zMakeRunnerTests.setUpc                 C   sJ   | j  g d¢¡ t | j ¡}|  |t¡ |  d|j¡ |  dg|j¡ dS )zÃ
        L{_makeRunner} returns a L{DistTrialRunner} instance when the C{--jobs}
        option is passed, and passes the C{workerNumber} and C{workerArguments}
        parameters to it.
        )rÑ   rÅ   ú
--force-gcé   râ   N)	r³   r¢   r   r%   r¤   r   r-   Ú_workerNumberÚ_workerArgumentsr'   r   r   r   Ú	test_jobs&  s
   zMakeRunnerTests.test_jobsc                 C   s<   | j  g d¢¡ t | 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-   ÚDRY_RUNÚmoder'   r   r   r   Útest_dryRunWithJobs2  s   z#MakeRunnerTests.test_dryRunWithJobsc                    sP   t jj‰ ‡ fdd„}|  t jd|¡ t  ¡ }| g d¢¡ |  t jt j|¡ d S )Nc                    s   | dkr
t j | ¡‚ˆ | ƒS )NÚ	doNotFind)r   ÚreflectÚModuleNotFound)Úfqn©ÚnamedAnyr   r   ÚnamedAnyExceptdoNotFind?  s   zFMakeRunnerTests.test_DebuggerNotFound.<locals>.namedAnyExceptdoNotFindrï   )rÒ   z
--debuggerrê   )	r   rë   rï   r   r   r¢   r~   Ú_DebuggerNotFoundr%   )r   rð   r³   r   rî   r   Útest_DebuggerNotFound<  s   z%MakeRunnerTests.test_DebuggerNotFoundc                 C   s*   | j  dg¡ t | j ¡}|  |j¡ dS )z‚
        Passing C{--exitfirst} wraps the reporter with a
        L{reporter._ExitWrapper} that stops on any non-success.
        rÛ   N)r³   r¢   r   r%   r‘   Ú
_exitFirstr'   r   r   r   Útest_exitfirstK  s   zMakeRunnerTests.test_exitfirstN)	r0   r1   r2   r3   r   ræ   ré   rò   rô   r   r   r   r   rá     s    
rá   c                   @   ó    e Zd ZdZdd„ Zdd„ ZdS )ÚRunTestsz(
    Tests for the L{run} function.
    c                 C   s   |   tjddd„ ¡ d S )Nr¢   c                 S   s   d S r@   r   r#   r   r   r   Ú<lambda>]  s    z RunTests.setUp.<locals>.<lambda>)r   r   r   r#   r   r   r   r   Z  s   zRunTests.setUpc              
   C   sh   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.

        c                  _   s
   t  d¡‚r|   )r   rñ   )rÎ   Úkwargsr   r   r   r%   e  rC   z3RunTests.test_debuggerNotFound.<locals>._makeRunnerr%   ry   Nz0Should have exited due to non-existent debugger!)r   r   r,   Ú
SystemExitrÌ   rÔ   Úfail)r   r%   Úer   r   r   Útest_debuggerNotFound_  s   €ÿzRunTests.test_debuggerNotFoundN)r0   r1   r2   r3   r   rü   r   r   r   r   rö   U  s    rö   c                   @   rõ   )ÚTestArgumentOrderTestszQ
    Tests for the order-preserving behavior on provided command-line tests.
    c                 C   s   t  ¡ | _tƒ | _d S r@   )r   r   r   r
   r;   r#   r   r   r   r   w  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.
        )ro   z"twisted.trial.test.test_assertionsz twisted.trial.test.test_deferredN)
r   r¢   r   rV   r   r   rF   r;   rG   r-   )r   rN   ÚsuiterJ   ÚexpectedSuiteÚexpectedNamesr   r   r   Útest_preserveArgumentOrder{  s   z1TestArgumentOrderTests.test_preserveArgumentOrderN)r0   r1   r2   r3   r   r  r   r   r   r   rý   r  s    rý   c                   @   sX   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dS )Ú
OrderTestsz'
    Tests for the --order option.
    c                 C   r?   r@   r6   r#   r   r   r   r   ”  rA   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.FooTestrN   )ú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   r8   ÚloadByNamesr-   r   ©r   r;   rþ   r   r   r   Útest_alphabetical—  s   ÿþzOrderTests.test_alphabeticalc                 C   r  )zu
        --order=alphabetical causes trial to run test classes within a given
        module alphabetically.
        )rÝ   rÞ   útwisted.trial.test.ordertestsrN   )ú.twisted.trial.test.ordertests.BarTest.test_barú.twisted.trial.test.ordertests.BazTest.test_bazr  r  r  r  Nr	  r  r   r   r   Útest_alphabeticalModule­  ó   ÿþ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.testrN   zFailed to load any tests!©ÚmsgN)	r   r¢   r   r8   r
  r   r‘   r-   Úsorted©r   r;   rþ   rJ   r   r   r   Útest_alphabeticalPackageÄ  s   z#OrderTests.test_alphabeticalPackagec                 C   r  )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Ý   Útoptobottomr  rN   )r  r  r  r  Nr	  r  r   r   r   Útest_toptobottomÑ  s   ÿþzOrderTests.test_toptobottomc                 C   r  )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  r  rN   )r  r  r  r  r  r  Nr	  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Ý   r  r  rN   c                 S   s   |   d¡d d… S )Nrµ   rã   )Úsplit)Únamer   r   r   r÷     s    z4OrderTests.test_toptobottomPackage.<locals>.<lambda>)ÚkeyN)r   r¢   r   r8   r
  r   r-   r  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): pass
            def test_third(self): pass
            def test_fourth(self): pass
            def test_first(self): 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Úparentr¼   rc   Úinsertr®   rÍ   r   r#  rŒ   r›   r0   r   r¢   r   r8   Ú
loadModuler-   r   )r   ÚtempdirÚpackageÚ	pathEntryr#  r;   rþ   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¢   r#   r   r   r   Útest_unknownOrder?  s   ÿzOrderTests.test_unknownOrderN)r0   r1   r2   r3   r   r  r  r  r  r  r  r/  r0  r   r   r   r   r  �  s    .r  c                   @   s   e Zd ZdZdd„ ZdS )ÚHelpOrderTestsz+
    Tests for the --help-orders flag.
    c                 C   s–   |   tdtƒ ¡ |  tt ¡ jdg¡}|  |j	d¡ tj
 ¡ }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.*r  N)r   rc   r   r~   rù   r   r   r¢   r-   Úcoder2  re   Ú
_runOrdersÚitemsÚreÚsearchÚescaper‘   )r   ÚexcÚoutputr  Ú	orderNameÚ	orderDescÚ_Úmatchr   r   r   Ú&test_help_ordersPrintsSynopsisAndQuitsN  s   ÿ
þúz5HelpOrderTests.test_help_ordersPrintsSynopsisAndQuitsN)r0   r1   r2   r3   r?  r   r   r   r   r1  I  s    r1  )*r   r6  rc   r&  r¥   Úior   Útwisted.pythonr   Útwisted.python.filepathr   Útwisted.python.usager   Útwisted.scriptsr   Útwisted.trialr   Útwisted.trial._dist.disttrialr   Útwisted.trial.runnerr	   r
   r   r   Útwisted.trial.test.test_loaderr   Ú
__import__r   r   ÚSynchronousTestCaser   r4   r>   r–   r¬   ÚTestCaserÀ   rá   rö   rý   r  r1  r   r   r   r   Ú<module>   s:   7 MO.^7 ;