
    tf                    (   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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          Z.d9dZ/d:dZ0d;dZ1d<d Z2 e"e2e1          Z3 G d! d"ej4                  Z5 G d# d$ej4                  Z6 G d% d&ej4                  Z7 G d' d(ej4                  Z8 G d) d*ej4                  Z9 G d+ d,ej4                  Z: G d- d.ej;                  Z< G d/ d0ej;                  Z= G d1 d2ej;                  Z> G d3 d4ej;                  Z? G d5 d6ej;                  Z@ G d7 d8ej;                  ZAdS )=    )annotationsN)StringIO)List)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                6    t          j        t          |           S )z1
    For finding files in twisted/trial/test
    )r   sibpath__file__)r   s    ]/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/trial/test/test_script.pyr   r   &   s     <(+++    Nonec                 H    t                                          d           dS )z.
    Emit something to L{twisted.logger}.
    	somethingN)r
   info r"   r!   logSomethingr(   -   s      HHMM+r"   argv	List[str]trial.Optionsc                V    t          j                    }|                    |            |S )z?
    Parse an argument list using trial's argument parser.
    )r   OptionsparseOptions)r)   configs     r!   parseArgumentsr0   4   s(     ]__F
Mr"   r/   c                    t          j        |           }t                      |_        t	          t
                              t                    g          }|                    |           | S )zM
    Run L{logSomething} as a test method using the given configuration.
    )	r   _makeRunnerr   streamr   pyunitFunctionTestCaser(   run)r/   runnersuites      r!   runFromConfigr9   =   sT     v&&FJJFMv..|<<=>>E
JJuMr"   c                      e Zd ZdZ e eg d                    dd            Z e edd	g                    dd            Z e edd	g                    dd            ZdS )LogfileTestsz)
    Tests for the --logfile option.
    )zdir-azdir-bzdir-c/dir-dworkingDirectoryr   r   r#   c                    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   )selfr<   r/   logPaths       r!   test_defaultzLogfileTests.test_defaultP   s_     "#57G"HII%&677DDVIEVWWG\/+*F*FGGHHHHHr"   zsomelog.txtzsomedir/somelog.txtr?   c                    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@   )rC   r?   r/   rD   s       r!   test_relativePathzLogfileTests.test_relativePathb   s]     ";"899%f-=&>??LLWUUG\/+*F*FGGHHHHHr"   c                    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.
        .rG   r%   N)r   rB   rA   pathr   r   r   )rC   r?   rD   iPaths       r!   test_absolutePathzLogfileTests.test_absolutePatht   s]    " 3--,,W55+w|4555"E<(D(DEEFFFFFr"   N)r<   r   r   r#   )r?   r   r   r#   )	__name__
__module____qualname____doc__r   r	   rE   rI   rN   r'   r"   r!   r;   r;   K   s         U  	
 	
 I I I I U%	
 	
 I I I I U%	
 	
 G G G G G Gr"   r;   c                  B    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.
    r   r#   c                    t          j                    | _        g | _        |                     t
          d| j                   t                              | j	                  }t          ||g          | _        d S )Ncollect)r   r-   r/   logpatchgcrV   r4   r5   
simpleTestr   test)rC   r[   s     r!   setUpz!ForceGarbageCollectionTests.setUp   sZ    moo 

2y$,///&&t77tTl++			r"   c                :    | j                             d           dS )zD
        A simple test method that records that it was run.
        r[   NrW   appendrC   s    r!   rZ   z&ForceGarbageCollectionTests.simpleTest   s     	r"   c                :    | j                             d           dS )zI
        A replacement for gc.collect that logs calls to itself.
        rV   Nr^   r`   s    r!   rV   z#ForceGarbageCollectionTests.collect   s     		"""""r"   r   c                ^    t          j        | j                  }t                      |_        |S )zN
        Return a L{TrialRunner} object that is safe to use in tests.
        )r   r2   r/   r   r3   rC   r7   s     r!   
makeRunnerz&ForceGarbageCollectionTests.makeRunner   s&     "4;// 

r"   c                    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)rV   r[   rV   rV   r[   rV   Nr/   postOptionsrd   r6   r[   assertEqualrW   rc   s     r!   test_forceGcz(ForceGarbageCollectionTests.test_forceGc   sw    
 #'J!!!""

49HRRR	
 	
 	
 	
 	
r"   c                    | j                                          |                                 }|                    | j                   |                     | j        ddg           dS )z>
        By default, no garbage collection is forced.
        r[   Nrf   rc   s     r!   test_unforceGcz*ForceGarbageCollectionTests.test_unforceGc   s^     	!!!""

49FF#344444r"   Nr   r#   )r   r   )
rO   rP   rQ   rR   r\   rZ   rV   rd   ri   rk   r'   r"   r!   rT   rT      s         , , , ,       # # # #   
 
 
 
5 5 5 5 5 5r"   rT   c                  *    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.
    r   r#   c                6    t          j                    | _        dS )z6
        Create a trial configuration object.
        Nr   r-   r/   r`   s    r!   r\   zSuiteUsedTests.setUp   s     moor"   c                x    t          j        | j                  }|                     |j        t
                     dS )zK
        By default, the loader should use L{DestructiveTestSuite}
        N)r   
_getLoaderr/   rh   suiteFactoryr   rC   loaders     r!   test_defaultSuitez SuiteUsedTests.test_defaultSuite   s6     !$+..,.BCCCCCr"   c                    d| j         d<   t          j        | 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   rr   rh   rs   r   rt   s     r!   test_untilFailureSuitez%SuiteUsedTests.test_untilFailureSuite   sA    
 (,O$!$+..,i88888r"   Nrl   )rO   rP   rQ   rR   r\   rv   rx   r'   r"   r!   rn   rn      s^         & & & &D D D D9 9 9 9 9 9r"   rn   c                      e Zd Zd"dZd"dZd"dZd#d
Zd"dZd"dZd"dZ	d"dZ
d"dZd"dZd"dZd"dZd"dZd"dZd"dZd"dZd"dZd"dZd"dZd"dZd"dZd"dZd"dZd"dZd"dZd"d Zd!S )$TestModuleTestsr   r#   c                6    t          j                    | _        d S Nrp   r`   s    r!   r\   zTestModuleTests.setUp       moor"   c                    d | _         d S r|   )r/   r`   s    r!   tearDownzTestModuleTests.tearDown   s    r"   c                r    |                      t          |           |                                 g           dS )zq
        Check that the testNames helper method accurately collects the
        names of tests in suite.
        N)rh   r   idr`   s    r!   test_testNameszTestModuleTests.test_testNames   s0    
 	447799+66666r"   test1r   names	list[str]c                   t                      }t          |          }t          t          t          |j        |                              }|                                 |                                 |                     ||           d S r|   )r   r   r   map
loadByNamesortrh   )rC   r   r   ru   names1names2s         r!   assertSuitesEqualz!TestModuleTests.assertSuitesEqual   sp    5!!9S):E%B%BCCDD(((((r"   c                b    |                      dt          | j        d                              d S )Nr   tests)rh   lenr/   r`   s    r!   test_baseStatezTestModuleTests.test_baseState   s-    CG 45566666r"   c                    | j                             t          d                     |                     t	          j        | 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   r   r   	_getSuiter`   s    r!   test_testmoduleOnModulez'TestModuleTests.test_testmoduleOnModule   sY    
 	""7?#;#;<<<ODK((+H*I	
 	
 	
 	
 	
r"   c                    | j                             t          d                     | j                             t          d                     |                     t	          j        | 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   r`   s    r!   test_testmoduleTwicez$TestModuleTests.test_testmoduleTwice  sw    
 	""7?#;#;<<<""7?#;#;<<<ODK((+H*I	
 	
 	
 	
 	
r"   c                    | j                             t          d                     | j                             t          d                     |                     t	          j        | 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   r`   s    r!    test_testmoduleOnSourceAndTargetz0TestModuleTests.test_testmoduleOnSourceAndTarget  sw     	""7?#;#;<<<""7=#9#9:::ODK((+H*I	
 	
 	
 	
 	
r"   c                    | j                             t          d                     |                     t	          j        | 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.moduleselfNr   r`   s    r!   test_testmoduleOnSelfModulez+TestModuleTests.test_testmoduleOnSelfModule  sY    
 	""7?#;#;<<<ODK((+J*K	
 	
 	
 	
 	
r"   c                    | j                             t          d                     |                     t	          j        | 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   r`   s    r!   test_testmoduleOnScriptz'TestModuleTests.test_testmoduleOnScript"  s\    
 	""7?#;#;<<<ODK((*,LM	
 	
 	
 	
 	
r"   c                |   t                      }t          j        |c}t          _        d}	 | j                            |           |                     dt          | j        d                              |                     d|d|                                           |t          _        dS # |t          _        w xY w)zz
        Check that --testmodule displays a meaningful error message when
        passed a non-existent filename.
        ztest_thisbetternoteverexist.pyr   r   File  doesn't exist
Nr   sysstderrr/   r   rh   r   getvalue)rC   buffyr   r   s       r!    test_testmoduleOnNonexistentFilez0TestModuleTests.test_testmoduleOnNonexistentFile-  s    
 

 Z
3	 K&&x000QDK$8 9 9:::AXAAA5>>CSCSTTTCJJJCJ   A4B- -B;c                    | j                             t          d                     |                     dt	          | j         d                              dS )z
        Check that --testmodule adds no tests to the suite for modules
        which lack test-case-name buffer variables.
        	novars.pyr   r   N)r/   r   r   rh   r   r`   s    r!   test_testmoduleOnEmptyVarsz*TestModuleTests.test_testmoduleOnEmptyVars<  sM    
 	""7;#7#7888CG 45566666r"   c                |   t                      }t          j        |c}t          _        d}	 | j                            |           |                     dt          | j        d                              |                     d|d|                                           |t          _        dS # |t          _        w xY w)z
        Check that --testmodule does *not* support module names as arguments
        and that it displays a meaningful error message.
        ztwisted.trial.test.test_scriptr   r   r   r   Nr   )rC   r   r   
moduleNames       r!   test_testmoduleOnModuleNamez+TestModuleTests.test_testmoduleOnModuleNameD  s    
 

 Z
5
	 K&&z222QDK$8 9 9:::CZCCCU^^EUEUVVVCJJJCJr   c                b    d}t          j        |          }|                     ddi|           d S )Nz5-*- test-case-name: twisted.trial.test.test_tests -*-test-case-nametwisted.trial.test.test_testsr   _parseLocalVariablesrh   rC   declaration	localVarss      r!   test_parseLocalVariablez'TestModuleTests.test_parseLocalVariableS  s:    M.{;;	*,KLiXXXXXr"   c                b    d}t          j        |          }|                     ddi|           d S )Nz6-*- test-case-name: twisted.trial.test.test_tests; -*-r   r   r   r   s      r!   test_trailingSemicolonz&TestModuleTests.test_trailingSemicolonX  s:    N.{;;	*,KLiXXXXXr"   c                d    d}t          j        |          }|                     ddd|           d S )Nz?-*- test-case-name: twisted.trial.test.test_tests; foo: bar -*-r   bar)r   foor   r   s      r!   test_parseLocalVariablesz(TestModuleTests.test_parseLocalVariables]  sK    P 	 .{;;	>uMMy	
 	
 	
 	
 	
r"   c                b    d}t          j        |          }|                     ddi|           d S )Nz:## -*- test-case-name: twisted.trial.test.test_tests -*- #r   r   r   r   s      r!   test_surroundingGuffz$TestModuleTests.test_surroundingGufff  s:    U.{;;	*,KLiXXXXXr"   c                R    |                      t          t          j        d           d S Nr   assertRaises
ValueErrorr   r   r`   s    r!   test_invalidLinez TestModuleTests.test_invalidLinek  s#    *e&@%HHHHHr"   c                    |                      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`   s    r!   test_invalidDeclarationz'TestModuleTests.test_invalidDeclarationn  so    *e&@-PPP24K	
 	
 	
 	24U	
 	
 	
 	
 	
r"   c                x    t          j        t          d                    }|                     ddi|           d S )Nr   r   r   r   loadLocalVariablesr   rh   rC   r   s     r!   test_variablesFromFilez&TestModuleTests.test_variablesFromFilew  s=    ,W_-E-EFF	*,IJIVVVVVr"   c                t    t          j        t          d                    }|                     i |           d S )Nr   r   r   s     r!   test_noVariablesInFilez&TestModuleTests.test_noVariablesInFile{  s6    ,W[-A-ABB	Y'''''r"   c                x    t          j        t          d                    }|                     ddi|           d S )Nr   r   z:twisted.trial.test.test_log,twisted.trial.test.test_runnerr   r   s     r!   test_variablesFromScriptz(TestModuleTests.test_variablesFromScript  sL    ,W_-E-EFF	 S
 	
 	
 	
 	
 	
r"   c                v    t          j        t          d                    }|                     |dg           d S )Nr   r   )r   getTestModulesr   rh   rC   moduless     r!   test_getTestModulesz#TestModuleTests.test_getTestModules  s:    &w'?'?@@#@"ABBBBBr"   c                    t          j        t          d                    }|                     t	          |          d           d S )Nr   r   )r   r   r   rh   r   r   s     r!   test_getTestModules_noVarsz*TestModuleTests.test_getTestModules_noVars  s<    &w{';';<<Wq)))))r"   c                    t          j        t          d                    }|                     t	          |          ddh           d S )Nr   r   r   )r   r   r   rh   setr   s     r!   test_getTestModules_multiplez,TestModuleTests.test_getTestModules_multiple  sN    &w'?'?@@LL*,LM	
 	
 	
 	
 	
r"   c                    dD ]-}|                      t          j        |          |d           .dt          d          t          d          fD ]-}|                     t          j        |          |d           .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)rC   r   s     r!   test_looksLikeTestModulez(TestModuleTests.test_looksLikeTestModule  s    O 	 	HOO **555   
 /O$$N##
 	 	H
  **;;;   	 	r"   Nrl   )r   r   r   r   r   r#   )rO   rP   rQ   r\   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r'   r"   r!   rz   rz      s4       & & & &   7 7 7 7) ) ) )7 7 7 7
 
 
 
	
 	
 	
 	


 

 

 


 
 
 
	
 	
 	
 	
       7 7 7 7       Y Y Y Y
Y Y Y Y

 
 
 
Y Y Y Y
I I I I
 
 
 
W W W W( ( ( (	
 	
 	
 	
C C C C* * * *
 
 
 
     r"   rz   c                  J    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.
    r   r#   c                r    t          j                    | _        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   savedModulesr`   s    r!   r\   zWithoutModuleTests.setUp  s)    
 moo --r"   c                    dD ]F}|| j         v r| j         |         t          j        |<   &t          j                            |d           GdS )z)
        Restore C{sys.modules}.
        )imaplibsmtplibN)r   r   r   pop)rC   modules     r!   r   zWithoutModuleTests.tearDown  s[     - 	. 	.F***&*&7&?F##----		. 	.r"   objectc                    ddl }|S )zE
        Try to import the C{smtplib} module, and return it.
        r   N)r   )rC   r   s     r!   
_checkSMTPzWithoutModuleTests._checkSMTP       	r"   c                    ddl }|S )zE
        Try to import the C{imaplib} module, and return it.
        r   N)r   )rC   r   s     r!   
_checkIMAPzWithoutModuleTests._checkIMAP  r   r"   c                    | 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
ModuleTyper`   s    r!   test_disableOneModulez(WithoutModuleTests.test_disableOneModule  sk     	  "4i!@AAA+t777K	"doo//1ABBBBBr"   c                   | 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   r`   s    r!   test_disableMultipleModulesz.WithoutModuleTests.test_disableMultipleModules  s     	  "46G!HIII+t777+t777K	"K	"doo//1ABBBdoo//1ABBBBBr"   c                   |                      |                                 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`   s    r!   !test_disableAlreadyImportedModulez4WithoutModuleTests.test_disableAlreadyImportedModule  sz     	doo//1ABBBBNK$+	
 	
 	
 	+t77777r"   Nrl   )r   r   )rO   rP   rQ   rR   r\   r   r   r   r   r   r   r'   r"   r!   r   r     s         . . . .. . . .      	C 	C 	C 	CC C C C8 8 8 8 8 8r"   r   c                  P    e Zd ZdZ eedd          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.r   r#   c                h    |                      t          j        t          j                               dS )zf
        Arrange for the current trace hook to be restored when the
        test is complete.
        N)
addCleanupr   settracer  r`   s    r!   r\   zCoverageTests.setUp  s&    
 	clnn55555r"   c                    t          j                    }|                    dg           |j        J |                     t          j                    |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.   tracerrh   r   r  globaltracerC   optionss     r!   test_tracerInstalledz"CoverageTests.test_tracerInstalled  sf    
 -//l^,,,~)))LNNN&	
 	
 	
 	
 	
r"   c                    t          j                    }|                     |                                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.
        rK   rH   coverageN)r   r-   rh   coverdirr   
descendantr	  s     r!   test_coverdirDefaultz"CoverageTests.test_coverdirDefault  sb    
 -//SMM$$g.>&?%LMM	
 	
 	
 	
 	
r"   c                   |                                  }t          j                    }|                    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.
        r>   r  N)mktempr   r-   r.   rh   r  r   child)rC   rL   r
  s      r!   test_coverdirOverriddenz%CoverageTests.test_coverdirOverridden!  sr    
 {{}}-//0$7888))++Xd^^-A-A*-M-MNNNNNr"   rl   )rO   rP   rQ   rR   getattrr   skipr\   r  r  r  r'   r"   r!   r  r    s          wsJ%%-L6 6 6 6
 
 
 
	
 	
 	
 	
O O O O O Or"   r  c                  B    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 )OptionsTestsz%
    Tests for L{trial.Options}.
    r   r#   c                6    t          j                    | _        dS )zE
        Build an L{Options} object to be used in the tests.
        Nr   r-   r
  r`   s    r!   r\   zOptionsTests.setUp1  s     }r"   c                   |                      t          j        t          j                               t	          j                    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getrecursionlimitrY   	isenabledenabler
  r.   _getWorkerArgumentsassertInremoverh   )rC   argss     r!   test_getWorkerArgumentsz$OptionsTests.test_getWorkerArguments7  s     	-s/D/F/FGGG<>> 	'OOBI&&&!!HHH	
 	
 	
 |//11mT***M""",f5t<<<<<r"   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.   rh   r   rC   errors     r!   test_jobsConflictWithDebugz'OptionsTests.test_jobsConflictWithDebugI  sQ     !!13M3M3M
 
 	FE

SSSSSr"   c                    |                      t          | j        j        g d          }|                     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.  s     r!   test_jobsConflictWithProfilez)OptionsTests.test_jobsConflictWithProfileU  sQ     !!13O3O3O
 
 	H#e**UUUUUr"   c                    |                      t          | j        j        g d          }|                     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.  s     r!   %test_jobsConflictWithDebugStackTracesz2OptionsTests.test_jobsConflictWithDebugStackTracesa  s\     !!L%222
 

 	Es5zz	
 	
 	
 	
 	
r"   c                    |                      t          | j        j        g d          }|                     dt          |                     dS )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.  s     r!   test_orderConflictWithRandomz)OptionsTests.test_orderConflictWithRandomq  sR    
 !!L%;;;
 

 	H#e**UUUUUr"   Nrl   )
rO   rP   rQ   rR   r\   r)  r0  r2  r4  r9  r'   r"   r!   r  r  ,  s         ' ' ' '= = = =$
T 
T 
T 
T
V 
V 
V 
V
 
 
 
 
V 
V 
V 
V 
V 
Vr"   r  c                  :    e Zd ZdZd
dZd
dZd
dZd
dZd
dZd	S )MakeRunnerTestsz.
    Tests for the L{_makeRunner} helper.
    r   r#   c                6    t          j                    | _        d S r|   r  r`   s    r!   r\   zMakeRunnerTests.setUp  s    }r"   c                B   | j                             g d           t          j        | 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   r2   
isinstancer   r   rh   _maxWorkers_workerArgumentsrc   s     r!   	test_jobszMakeRunnerTests.test_jobs  s     	!!"?"?"?@@@"4<00&/22222fo666F.///,)@AAAAAr"   c                   | j                             g d           t          j        | 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   r2   r@  r   r   rh   DRY_RUNmoderc   s     r!   test_dryRunWithJobsz#MakeRunnerTests.test_dryRunWithJobs  s    
 	!!">">">???"4<00&+.....fk222,fk:::::r"   c                "   t           j        j        dfd}|                     t           j        d|           t          j                    }|                    g d           |                     t           j        t           j        |           d S )	Nfqnr   r   r   c                d    | dk    rt           j                            |            |           S )N	doNotFind)r   reflectModuleNotFound)rI  namedAnys    r!   namedAnyExceptdoNotFindzFMakeRunnerTests.test_DebuggerNotFound.<locals>.namedAnyExceptdoNotFind  s2    k!!m2237778C== r"   rN  )r,  z
--debuggerrK  )rI  r   r   r   )	r   rL  rN  rX   r-   r.   r   _DebuggerNotFoundr2   )rC   rO  r
  rN  s      @r!   test_DebuggerNotFoundz%MakeRunnerTests.test_DebuggerNotFound  s    =)	! 	! 	! 	! 	! 	!
 	

5=*.EFFF-//CCCDDD%153DgNNNNNr"   c                    | j                             dg           t          j        | 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   r2   r@  r   r   
_exitFirstrc   s     r!   test_exitfirstzMakeRunnerTests.test_exitfirst  s_    
 	!!=/222"4<00&+.....)*****r"   Nrl   )	rO   rP   rQ   rR   r\   rC  rG  rQ  rT  r'   r"   r!   r;  r;  ~  s         ' ' ' 'B B B B	; 	; 	; 	;O O O O+ + + + + +r"   r;  c                  "    e Zd ZdZddZddZdS )RunTestsz(
    Tests for the L{run} function.
    r   r#   c                J    |                      t          j        dd            d S )Nr.   c                    d S r|   r'   r`   s    r!   <lambda>z RunTests.setUp.<locals>.<lambda>  s    t r"   )rX   r   r-   r`   s    r!   r\   zRunTests.setUp  s&     	

5=.2C2CDDDDDr"   c                   dd}|                      t          d|           	 t          j                     |                     d           d
S # t          $ r.}|                     d	t          |                     Y d
}~d
S d
}~ww xY w)zY
        When a debugger is not found, an error message is printed to the user.

        r(  r   kwargsr   r#   c                 *    t          j        d          r   )r   rP  )r(  r[  s     r!   r2   z3RunTests.test_debuggerNotFound.<locals>._makeRunner  s    )%000r"   r2   z0Should have exited due to non-existent debugger!r   N)r(  r   r[  r   r   r#   )rX   r   r6   fail
SystemExitr&  r   )rC   r2   es      r!   test_debuggerNotFoundzRunTests.test_debuggerNotFound  s    	1 	1 	1 	1 	

5-555	JIKKK IIHIIIII  	) 	) 	)MM%Q(((((((((	)s   A 
B#A??BNrl   )rO   rP   rQ   rR   r\   r`  r'   r"   r!   rV  rV    sP         E E E E
J J J J J Jr"   rV  c                  "    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.
    r   r#   c                \    t          j                    | _        t                      | _        d S r|   )r   r-   r/   r   ru   r`   s    r!   r\   zTestArgumentOrderTests.setUp  s    moo llr"   c                *   g d}| j                             |           t          j        | 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   r   ru   r   rh   )rC   r   r8   r   expectedSuiteexpectedNamess         r!   test_preserveArgumentOrderz1TestArgumentOrderTests.test_preserveArgumentOrder  s    
 
 

 	  ''',,%  !#dk&<e"D"DEE!-00.....r"   Nrl   )rO   rP   rQ   rR   r\   rg  r'   r"   r!   rb  rb    sF         # # # #/ / / / / /r"   rb  c                  Z    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.
    r   r#   c                6    t          j                    | _        d S r|   rp   r`   s    r!   r\   zOrderTests.setUp  r}   r"   c                    | j                             g d           t          j        | j                   }|                    | j         d                   }|                     t          |          g d           dS )zn
        --order=alphabetical causes trial to run tests alphabetically within
        each test case.
        )r6  r7  %twisted.trial.test.ordertests.FooTestr   )0twisted.trial.test.ordertests.FooTest.test_first1twisted.trial.test.ordertests.FooTest.test_fourth1twisted.trial.test.ordertests.FooTest.test_second0twisted.trial.test.ordertests.FooTest.test_thirdNr/   r.   r   rr   loadByNamesrh   r   rC   ru   r8   s      r!   test_alphabeticalzOrderTests.test_alphabetical  s    
 	  PPP	
 	
 	
 !$+..""4;w#788e  	
 	
 	
 	
 	
r"   c                    | j                             g d           t          j        | j                   }|                    | j         d                   }|                     t          |          g d           dS )zu
        --order=alphabetical causes trial to run test classes within a given
        module alphabetically.
        )r6  r7  twisted.trial.test.ordertestsr   ).twisted.trial.test.ordertests.BarTest.test_bar.twisted.trial.test.ordertests.BazTest.test_bazrm  rn  ro  rp  Nrq  rs  s      r!   test_alphabeticalModulez"OrderTests.test_alphabeticalModule  s    
 	  HHH	
 	
 	
 !$+..""4;w#788e  
	
 
	
 
	
 
	
 
	
r"   c                B   | j                             g d           t          j        | j                   }|                    | j         d                   }t          |          }|                     |d           |                     |t          |                     dS )z
        --order=alphabetical causes trial to run test modules within a given
        package alphabetically, with tests within each module alphabetized.
        )r6  r7  twisted.trial.testr   zFailed to load any tests!msgN)	r/   r.   r   rr   rr  r   r   rh   sortedrC   ru   r8   r   s       r!   test_alphabeticalPackagez#OrderTests.test_alphabeticalPackage'  s    
 	  !R!R!RSSS!$+..""4;w#788%  #>???u.....r"   c                    | j                             g d           t          j        | j                   }|                    | j         d                   }|                     t          |          g d           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.
        )r6  toptobottomrl  r   )rm  ro  rp  rn  Nrq  rs  s      r!   test_toptobottomzOrderTests.test_toptobottom4  s     	  OOO	
 	
 	
 !$+..""4;w#788e  	
 	
 	
 	
 	
r"   c                    | j                             g d           t          j        | j                   }|                    | j         d                   }|                     t          |          g d           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.
        r6  r  rv  r   )rm  ro  rp  rn  rx  rw  Nrq  rs  s      r!   test_toptobottomModulez!OrderTests.test_toptobottomModuleK  s    
 	  GGG	
 	
 	
 !$+..""4;w#788e  
	
 
	
 
	
 
	
 
	
r"   c                   | j                             g d           t          j        | j                   }|                    | j         d                   }t          |          }|                     |t          |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.
        )r6  r  r{  r   c                <    |                      d          d d         S )NrK   r?  )split)names    r!   rY  z4OrderTests.test_toptobottomPackage.<locals>.<lambda>q  s    4::c??2A2+> r"   )keyN)r/   r.   r   rr   rr  r   rh   r~  r  s       r!   test_toptobottomPackagez"OrderTests.test_toptobottomPackageb  s     	  !Q!Q!QRRR!$+..""4;w#788%   	5>>???	
 	
 	
 	
 	
r"   c                   |                                  }t          |                              d          }|                                 |                    d                              d           |                    d                              t          j        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        | j                  }|                    |          }|                     t3          |          g d
           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) -> None: pass
            def test_third(self) -> None: pass
            def test_fourth(self) -> None: pass
            def test_first(self) -> None: pass
        utf8r   )test_missingr  )z=twisted_toptobottom_temp.test_missing.TestMissing.test_secondz<twisted_toptobottom_temp.test_missing.TestMissing.test_thirdz=twisted_toptobottom_temp.test_missing.TestMissing.test_fourthz<twisted_toptobottom_temp.test_missing.TestMissing.test_firstN)r  r   r  makedirs
setContenttextwrapdedentencodeparentrL   r   insertr  r'  r  r  r   r   rO   r/   r.   r   rr   
loadModulerh   r   )rC   tempdirpackage	pathEntryr  ru   r8   s          r!   test_toptobottomMissingSourcez(OrderTests.test_toptobottomMissingSourcet  s   
 ++--7##))*DEEm$$//444'((33O	 	 fVnn	
 	
 	
 NN$$)	9%%%333	
 	
 	
 	
 	
 	
 	)CDDD)>???'((//111  GGG	
 	
 	
 !$+..!!,//e  	
 	
 	
 	
 	
r"   c                V    |                      t          | j        j        ddg           dS )zL
        An unknown order passed to --order raises a L{UsageError}.
        r6  zI don't existN)r   r   r/   r.   r`   s    r!   test_unknownOrderzOrderTests.test_unknownOrder  s7    
 	09o2N	
 	
 	
 	
 	
r"   Nrl   )rO   rP   rQ   rR   r\   rt  ry  r  r  r  r  r  r  r'   r"   r!   ri  ri    s         & & & &
 
 
 
,
 
 
 
./ / / /
 
 
 
.
 
 
 
.
 
 
 
$.
 .
 .
 .
`
 
 
 
 
 
r"   ri  c                      e Zd ZdZddZdS )HelpOrderTestsz+
    Tests for the --help-orders flag.
    r   r#   c                $   |                      t          dt                      x}           |                     t          t          j                    j        dg          }|                     |j	        d           |
                                }d}t
          j                                        D ]b\  }\  }}t          j        t          j        |           dt          j        |           |          }|                     ||||fz             cd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)rX   r   r   r   r^  r   r-   r.   rh   coder   
_runOrdersitemsresearchescaper   )	rC   r  excoutputr}  	orderName	orderDesc_matchs	            r!   &test_help_ordersPrintsSynopsisAndQuitsz5HelpOrderTests.test_help_ordersPrintsSynopsisAndQuits  s    	

3HJJ"6&77746G
 
 	1%%%""D).)9)?)?)A)A 	B 	B%I~	1I9Y''AA29Y+?+?AA E
 OOEsi-@'@OAAAA	B 	Br"   Nrl   )rO   rP   rQ   rR   r  r'   r"   r!   r  r    s8         B B B B B Br"   r  )r   r   r   r   rl   )r)   r*   r   r+   )r/   r+   r   r+   )B
__future__r   rY   r  r   r  r   ior   typingr   hamcrestr   r   
hypothesisr   hypothesis.strategiesr	   twisted.loggerr
   twisted.pythonr   twisted.python.filepathr   r   twisted.python.usager   twisted.scriptsr   twisted.trialr   twisted.trial._dist.disttrialr   twisted.trial._dist.functionalr   twisted.trial.runnerr   r   r   r   r   twisted.trial.test.test_loaderr   matchersr   
__import__r4   r   r(   r0   r9   rA   SynchronousTestCaser;   rT   rn   rz   r   r  TestCaser  r;  rV  rb  ri  r  r'   r"   r!   <module>r     s   # " " " " " 				 				 



               1 1 1 1 1 1 1 1       . . . . . . ! ! ! ! ! !       7 7 7 7 7 7 7 7 + + + + + + ! ! ! ! ! ! " " " " " " 9 9 9 9 9 9 2 2 2 2 2 2              5 4 4 4 4 4 " " " " " "	J		, , , ,          7=.99 =G =G =G =G =G8/ =G =G =G@45 45 45 45 45("> 45 45 45n9 9 9 9 9X1 9 9 98I I I I Ih2 I I IXL8 L8 L8 L8 L85 L8 L8 L8^0O 0O 0O 0O 0OH0 0O 0O 0OfOV OV OV OV OV8$ OV OV OVd7+ 7+ 7+ 7+ 7+h' 7+ 7+ 7+tJ J J J Jx  J J J:/ / / / /X. / / /:y
 y
 y
 y
 y
" y
 y
 y
xB B B B BX& B B B B Br"   