U
    òÀMft  ã                   @   s’  d dl mZmZ d dlZd dlZd dlZd dlZd dlZd dlm	Z	 d dl
mZ d dlmZ 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 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 )&é    )Úabsolute_importÚdivisionN)Úutil)ÚNativeStringIO)ÚFilePath)Ú
UsageError)Útrial)Úunittest)ÚDistTrialRunner)Ú
TestLoader)ÚTrialRunnerÚ	TestSuiteÚDestructiveTestSuite)Ú	testNamesr	   c                 C   s   t  t| ¡S )z1
    For finding files in twisted/trial/test
    )r   ÚsibpathÚ__file__)Úfilename© r   úB/tmp/pip-unpacked-wheel-c7c47867/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   ÚpyunitZFunctionTestCaseÚ
simpleTestr   Útest)Úselfr   r   r   r   ÚsetUp'   s
    
z!ForceGarbageCollectionTests.setUpc                 C   s   | j  d¡ dS )zD
        A simple test method that records that it was run.
        r   N©r   Úappend©r   r   r   r   r   /   s    z&ForceGarbageCollectionTests.simpleTestc                 C   s   | j  d¡ dS )zI
        A replacement for gc.collect that logs calls to itself.
        r   Nr!   r#   r   r   r   r   6   s    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   sF   d| j d< | j  ¡  |  ¡ }| | j¡ |  | jddddddg¡ 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-gcr   r   N©r   ZpostOptionsr(   Úrunr   ÚassertEqualr   r&   r   r   r   Útest_forceGcF   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_unforceGcS   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   s   t  ¡ | _dS )z6
        Create a trial configuration object.
        N©r   r   r   r#   r   r   r   r    c   s    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_defaultSuitej   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   r4   r+   r5   r   r6   r   r   r   Útest_untilFailureSuiter   s    
z%SuiteUsedTests.test_untilFailureSuiteN)r.   r/   r0   r1   r    r8   r9   r   r   r   r   r2   ^   s   r2   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   s   t  ¡ | _d S ©Nr3   r#   r   r   r   r    ~   s    zTestModuleTests.setUpc                 C   s
   d | _ d S r;   )r   r#   r   r   r   ÚtearDown   s    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   Ztest1Únamesr7   Znames1Z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   s*   | 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   rC   r   Ú	_getSuiter#   r   r   r   Útest_testmoduleOnModule–   s    ÿ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.
        rG   rH   NrI   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.
        rG   ztest_log.pyrH   NrI   r#   r   r   r   Ú test_testmoduleOnSourceAndTarget©   s
    ÿz0TestModuleTests.test_testmoduleOnSourceAndTargetc                 C   s*   | j  tdƒ¡ |  t | j ¡dg¡ dS )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.moduleselfNrI   r#   r   r   r   Útest_testmoduleOnSelfModule´   s    ÿ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.pyrH   útwisted.trial.test.test_runnerNrI   r#   r   r   r   Útest_testmoduleOnScript½   s    ÿÿz'TestModuleTests.test_testmoduleOnScriptc                 C   sb   t ƒ }tj| }t_d}z<| j |¡ |  dt| jd ƒ¡ |  d|f | ¡ ¡ W 5 |t_X dS )zz
        Check that --testmodule displays a meaningful error message when
        passed a non-existent filename.
        ztest_thisbetternoteverexist.pyr   rD   úFile %r doesn't exist
N©r   ÚsysÚstderrr   rJ   r+   rE   Úgetvalue)r   ÚbuffyrV   r   r   r   r   Ú test_testmoduleOnNonexistentFileÇ   s    ÿ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   rD   N)r   rJ   r   r+   rE   r#   r   r   r   Útest_testmoduleOnEmptyVars×   s    z*TestModuleTests.test_testmoduleOnEmptyVarsc                 C   sb   t ƒ }tj| }t_d}z<| j |¡ |  dt| jd ƒ¡ |  d|f | ¡ ¡ W 5 |t_X dS )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   rD   rS   NrT   )r   rX   rV   Z
moduleNamer   r   r   Útest_testmoduleOnModuleNameß   s    ÿz+TestModuleTests.test_testmoduleOnModuleNamec                 C   s"   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   ZdeclarationÚ	localVarsr   r   r   Útest_parseLocalVariableï   s    
ÿþz'TestModuleTests.test_parseLocalVariablec                 C   s"   d}t  |¡}|  ddi|¡ d S )Nz6-*- test-case-name: twisted.trial.test.test_tests; -*-r]   r^   r_   ra   r   r   r   Útest_trailingSemicolonö   s    
ÿþ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_   ra   r   r   r   Útest_parseLocalVariablesý   s    
þýz(TestModuleTests.test_parseLocalVariablesc                 C   s"   d}t  |¡}|  ddi|¡ d S )Nz:## -*- test-case-name: twisted.trial.test.test_tests -*- #r]   r^   r_   ra   r   r   r   Útest_surroundingGuff  s    
ÿþz$TestModuleTests.test_surroundingGuffc                 C   s   |   ttjd¡ d S ©Nrf   ©ÚassertRaisesÚ
ValueErrorr   r`   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 -*-rj   r#   r   r   r   Útest_invalidDeclaration  s    
ÿ
ÿ
ÿz'TestModuleTests.test_invalidDeclarationc                 C   s"   t  tdƒ¡}|  ddi|¡ d S )NrG   r]   rH   ©r   ZloadLocalVariablesr   r+   ©r   rb   r   r   r   Útest_variablesFromFile  s    ÿþz&TestModuleTests.test_variablesFromFilec                 C   s   t  tdƒ¡}|  i |¡ d S )NrZ   ro   rp   r   r   r   Útest_noVariablesInFile   s    z&TestModuleTests.test_noVariablesInFilec                 C   s"   t  tdƒ¡}|  ddi|¡ d S )NrP   r]   z:twisted.trial.test.test_log,twisted.trial.test.test_runnerro   rp   r   r   r   Útest_variablesFromScript$  s
    ýz(TestModuleTests.test_variablesFromScriptc                 C   s    t  tdƒ¡}|  |dg¡ d S )NrG   rH   )r   ÚgetTestModulesr   r+   ©r   Úmodulesr   r   r   Útest_getTestModules+  s    z#TestModuleTests.test_getTestModulesc                 C   s"   t  tdƒ¡}|  t|ƒd¡ d S )NrZ   r   )r   rt   r   r+   rE   ru   r   r   r   Útest_getTestModules_noVars/  s    z*TestModuleTests.test_getTestModules_noVarsc                 C   s*   t  tdƒ¡}|  t|ƒtddgƒ¡ d S )NrP   rH   rQ   )r   rt   r   r+   Úsetru   r   r   r   Útest_getTestModules_multiple3  s    
ÿÿz,TestModuleTests.test_getTestModules_multiplec                 C   sV   dD ]}|   t |¡d|f ¡ qdtdƒtdƒfD ]}|  t |¡d|f ¡ q4d S )N)ztest_script.pyz!twisted/trial/test/test_script.pyz%r should be a test filez twisted/trial/test/moduletest.pyrP   ztest_foo.batz%r should *not* be a test file)Ú
assertTruer   Z
isTestFiler   ZassertFalse)r   r   r   r   r   Útest_looksLikeTestModule9  s    ÿ ÿÿz(TestModuleTests.test_looksLikeTestModuleN)r.   r/   r0   r    r<   r>   rC   rF   rL   rM   rN   rO   rR   rY   r[   r\   rc   rd   rg   rh   rm   rn   rq   rr   rs   rw   rx   rz   r|   r   r   r   r   r:   }   s4   	
	
	r:   c                   @   sH   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   ÚdictrU   rv   ÚsavedModulesr#   r   r   r   r    H  s    
zWithoutModuleTests.setUpc                 C   s8   dD ].}|| j kr$| j | tj|< qtj |d¡ qdS )z)
        Restore C{sys.modules}.
        )ÚimaplibÚsmtplibN)r   rU   rv   Úpop)r   Úmoduler   r   r   r<   Q  s    
zWithoutModuleTests.tearDownc                 C   s   ddl }|S )zE
        Try to import the C{smtplib} module, and return it.
        r   N)r   )r   r   r   r   r   Ú
_checkSMTP\  s    zWithoutModuleTests._checkSMTPc                 C   s   ddl }|S )zE
        Try to import the C{imaplib} module, and return it.
        r   N)r€   )r   r€   r   r   r   Ú
_checkIMAPd  s    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   ÚparseOptionsrk   ÚImportErrorr„   rU   rv   ÚassertIsInstanceÚtypesÚ
ModuleTyper#   r   r   r   Útest_disableOneModulel  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‡   rk   rˆ   r„   r…   rU   rv   r‰   rŠ   r‹   r#   r   r   r   Útest_disableMultipleModulesx  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‡   rk   rˆ   r#   r   r   r   Ú!test_disableAlreadyImportedModule‡  s     ýz4WithoutModuleTests.test_disableAlreadyImportedModuleN)r.   r/   r0   r1   r    r<   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k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)Ú
addCleanuprU   Ú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+   rU   r‘   ZtracerZ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   Z
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)r.   r/   r0   r1   ÚgetattrrU   Úskipr    r–   rš   rž   r   r   r   r   r   ”  s   ÿ
r   c                   @   sH   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 )ÚOptionsTestsz%
    Tests for L{trial.Options}.
    c                 C   s   t  ¡ | _dS )zE
        Build an L{Options} object to be used in the tests.
        N©r   r   r•   r#   r   r   r   r    Ë  s    zOptionsTests.setUpc                 C   sp   |   tjt ¡ ¡ t ¡ r&|   tj¡ | j dddddg¡ | 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}.
        z--recursionlimitÚ2000ú--randomÚ4z--disablegcN)r’   rU   ÚsetrecursionlimitÚgetrecursionlimitr   Ú	isenabledÚenabler•   r‡   Z_getWorkerArgumentsÚassertInÚremover+   )r   Úargsr   r   r   Útest_getWorkerArgumentsÒ  s     ÿ

z$OptionsTests.test_getWorkerArgumentsc                 C   s,   |   t| jjdddg¡}|  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©rk   r   r•   r‡   r+   Ústr©r   Úerrorr   r   r   Útest_jobsConflictWithDebugä  s      ÿÿz'OptionsTests.test_jobsConflictWithDebugc                 C   s,   |   t| jjdddg¡}|  dt|ƒ¡ dS )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ñ  s     þÿz)OptionsTests.test_jobsConflictWithProfilec                 C   s,   |   t| jjdddg¡}|  dt|ƒ¡ dS )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   s,   |   t| jjdddg¡}|  dt|ƒ¡ dS )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  s     þþz+OptionsTests.test_jobsConflictWithExitFirstc                 C   s.   |   t| jjddddg¡}|  dt|ƒ¡ dS )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_orderConflictWithRandomN)r.   r/   r0   r1   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   s   t  ¡ | _d S r;   r¢   r#   r   r   r   r    0  s    zMakeRunnerTests.setUpc                 C   sL   | j  dddg¡ 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¥   z
--force-gcé   N)	r•   r‡   r   r$   r‰   r
   r+   Z_workerNumberZ_workerArgumentsr&   r   r   r   Ú	test_jobs3  s
    zMakeRunnerTests.test_jobsc                 C   s>   | j  dddg¡ 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+   ZDRY_RUNÚmoder&   r   r   r   Útest_dryRunWithJobs@  s    z#MakeRunnerTests.test_dryRunWithJobsc                    sR   t jj‰ ‡ fdd„}|  t jd|¡ t  ¡ }| dddg¡ |  t jt j|¡ d S )Nc                    s   | dkrt j | ¡‚ˆ | ƒS )NÚ	doNotFind)r   ÚreflectZModuleNotFound)Zfqn©ÚnamedAnyr   r   ÚnamedAnyExceptdoNotFindN  s    zFMakeRunnerTests.test_DebuggerNotFound.<locals>.namedAnyExceptdoNotFindrÄ   r¯   z
--debuggerrÁ   )	r   rÂ   rÄ   r   r   r‡   rk   Ú_DebuggerNotFoundr$   )r   rÅ   r•   r   rÃ   r   Útest_DebuggerNotFoundK  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{   Z
_exitFirstr&   r   r   r   Útest_exitfirst[  s    zMakeRunnerTests.test_exitfirstN)	r.   r/   r0   r1   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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>m  ó    z RunTests.setUp.<locals>.<lambda>)r   r   r   r#   r   r   r   r    j  s    zRunTests.setUpc              
   C   sd   dd„ }|   td|¡ zt ¡  W n2 tk
rT } z|  dt|ƒ¡ W 5 d}~X Y nX |  d¡ dS )zY
        When a debugger is not found, an error message is printed to the user.

        c                  _   s   t  d¡‚d S ri   )r   rÆ   )r¬   Úkwargsr   r   r   r$   v  s    z3RunTests.test_debuggerNotFound.<locals>._makeRunnerr$   rf   Nz0Should have exited due to non-existent debugger!)r   r   r*   Ú
SystemExitrª   r±   Zfail)r   r$   Úer   r   r   Útest_debuggerNotFoundp  s    "zRunTests.test_debuggerNotFoundN)r.   r/   r0   r1   r    rÏ   r   r   r   r   rÉ   e  s   rÉ   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTestArgumentOrderTestszQ
    Tests for the order-preserving behavior on provided command-line tests.
    c                 C   s   t  ¡ | _tƒ | _d S r;   )r   r   r   r   r7   r#   r   r   r   r    ˆ  s    
zTestArgumentOrderTests.setUpc                 C   sT   dddg}| 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   rK   r   r   r?   r7   r@   r+   )r   rD   ÚsuiterB   ZexpectedSuiteZexpectedNamesr   r   r   Útest_preserveArgumentOrder  s    ýz1TestArgumentOrderTests.test_preserveArgumentOrderN)r.   r/   r0   r1   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   s   t  ¡ | _d S r;   r3   r#   r   r   r   r    ¦  s    zOrderTests.setUpc                 C   sJ   | j  dddg¡ t | j ¡}| | j d ¡}|  t|ƒddddg¡ d	S )
zn
        --order=alphabetical causes trial to run tests alphabetically within
        each test case.
        r¹   rº   ú%twisted.trial.test.ordertests.FooTestrD   ú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   r4   ÚloadByNamesr+   r   ©r   r7   rÑ   r   r   r   Útest_alphabeticalª  s     þüÿzOrderTests.test_alphabeticalc              	   C   sN   | j  dddg¡ t | j ¡}| | j d ¡}|  t|ƒddddd	d
g¡ dS )zu
        --order=alphabetical causes trial to run test classes within a given
        module alphabetically.
        r¹   rº   útwisted.trial.test.ordertestsrD   ú.twisted.trial.test.ordertests.BarTest.test_barú.twisted.trial.test.ordertests.BazTest.test_bazrÕ   rÖ   r×   rØ   NrÙ   rÛ   r   r   r   Útest_alphabeticalModule¾  s"      ÿúÿz"OrderTests.test_alphabeticalModulec                 C   sX   | j  dddg¡ 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.testrD   zFailed to load any tests!©ÚmsgN)	r   r‡   r   r4   rÚ   r   r{   r+   Úsorted©r   r7   rÑ   rB   r   r   r   Útest_alphabeticalPackageÒ  s      ÿz#OrderTests.test_alphabeticalPackagec                 C   sJ   | j  dddg¡ t | j ¡}| | j d ¡}|  t|ƒddddg¡ d	S )
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Ô   rD   rÕ   r×   rØ   rÖ   NrÙ   rÛ   r   r   r   Útest_toptobottomá  s     þüÿzOrderTests.test_toptobottomc              	   C   sN   | j  dddg¡ t | j ¡}| | j d ¡}|  t|ƒddddd	d
g¡ dS )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Ý   rD   rÕ   r×   rØ   rÖ   rß   rÞ   NrÙ   rÛ   r   r   r   Útest_toptobottomModuleö  s"      ÿúÿz!OrderTests.test_toptobottomModulec                 C   sR   | j  dddg¡ 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á   rD   c                 S   s   |   d¡d d… S )Nr—   r½   )Úsplit)Únamer   r   r   rÊ     rË   z4OrderTests.test_toptobottomPackage.<locals>.<lambda>)ÚkeyN)r   r‡   r   r4   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 d	d
dg¡ t | j¡}| |¡}|  t|ƒddddg¡ dS )z{
        --order=toptobottom detects the source line of methods from modules
        whose source file is missing.
        Útwisted_toptobottom_tempz__init__.pyrË   ztest_missing.pya   
        from twisted.trial.unittest import TestCase
        class TestMissing(TestCase):
            def test_second(self): pass
            def test_third(self): pass
            def test_fourth(self): pass
            def test_first(self): pass
        Úutf8r   )Útest_missingr¹   rç   rÝ   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Úparentr   rU   Úinsertr’   r«   rî   rð   rv   r‚   r.   r   r‡   r   r4   Z
loadModuler+   r   )r   ÚtempdirÚpackageZ	pathEntryrð   r7   rÑ   r   r   r   Útest_toptobottomMissingSource  s:    ù
  ÿ
üÿ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)rk   r   r   r‡   r#   r   r   r   Útest_unknownOrderC  s
      ÿzOrderTests.test_unknownOrderN)r.   r/   r0   r1   r    rÜ   rà   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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 ]B\}\}}t dt |¡t |¡f |¡}| j||||f d qLd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%s.*%srâ   N)r   rU   r   rk   rÍ   r   r   r‡   r+   Úcoderü   rW   Z
_runOrdersÚitemsÚreÚsearchÚescaper{   )r   ÚexcÚoutputrã   Z	orderNameZ	orderDescÚ_Úmatchr   r   r   Ú&test_help_ordersPrintsSynopsisAndQuitsQ  s      ÿ
þz5HelpOrderTests.test_help_ordersPrintsSynopsisAndQuitsN)r.   r/   r0   r1   r  r   r   r   r   rû   M  s   rû   )-Ú
__future__r   r   r   rÿ   rU   rò   rŠ   Ztwisted.pythonr   Ztwisted.python.compatr   Ztwisted.python.filepathr   Ztwisted.python.usager   Ztwisted.scriptsr   Ztwisted.trialr	   Ztwisted.trial._dist.disttrialr
   Ztwisted.trial.runnerr   r   r   r   Ztwisted.trial.test.test_loaderr   Ú
__import__r   r   ZSynchronousTestCaser   r2   r:   r}   r   ZTestCaser¡   r¼   rÉ   rÐ   rÓ   rû   r   r   r   r   Ú<module>   s<   < GQ2e: ,