
    tf_                       d Z ddlmZ ddlZddlZddlZddlmZ ddl	m
Z
 ddlmZ ddlmZmZmZ ddlmZmZmZ dd	lmZ dd
lmZmZ ddlmZmZmZ ddlmZ ddl m!Z!m"Z"mZ ddl#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z* erddl+m,Z, d'dZ- G d de(j.                  Z/d(dZ0 G d d e(j.                  Z1 G d! d"e(j.                  Z2 G d# d$e2          Z3 G d% d&e(j.                  Z4dS ))z"
Tests for loading tests by name.
    )annotationsN)md5)
attrgetter)
ModuleType)TYPE_CHECKINGCallable	Generator)assert_thatequal_tohas_properties)Matcher)filepathutil)PythonAttributePythonModule	getModule)ModuleNotFound)reporterrunnerunittest)_iterateTests)	ITestCase)packages   )after)SupportsRichComparisontests"pyunit.TestCase | pyunit.TestSuitereturn	list[str]c                |    g }t          |           D ])}|                    |                                           *|S )zI
    Return the id of each test within the given test suite or case.
    )r   appendid)r   namestests      ]/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/trial/test/test_loader.py	testNamesr'   !   sB     Ee$$    TWWYYL    c                  @     e Zd Zd fdZddZddZddZddZ xZS )	FinderPy3Testsr   Nonec                x    t                                                       t          j                    | _        d S N)supersetUpr   
TestLoaderloader)self	__class__s    r&   r/   zFinderPy3Tests.setUp,   s(    '))r(   c                R    |                      t          | j        j        d           dS )z
        findByName, if given something findable up until the last entry, will
        raise AttributeError (as it cannot tell if 'nonexistent' here is
        supposed to be a module or a class).
        ztwisted.trial.test.nonexistentN)assertRaisesAttributeErrorr1   
findByNamer2   s    r&   test_findNonModulez!FinderPy3Tests.test_findNonModule0   s3     	DK24T	
 	
 	
 	
 	
r(   c                R    |                      t          | j        j        d           d S )N	nonextant)r5   r   r1   r7   r8   s    r&   test_findNonPackagez"FinderPy3Tests.test_findNonPackage:   s%    .$+*@+NNNNNr(   c                    t          j        t          d          }|                     t          | j        j        |           dS )z
        findByName, given a file path that doesn't exist, will raise a
        ValueError saying that it is not a Python file.
        znonexistent.pyN)r   sibpath__file__r5   
ValueErrorr1   r7   )r2   paths     r&   test_findNonFilezFinderPy3Tests.test_findNonFile=   s9    
 |H&677*dk&<dCCCCCr(   c                R    |                      t          | j        j        d           dS )zn
        findByName will re-raise ImportErrors inside modules that it has found
        and imported.
        zunimportablepackage.test_moduleN)r5   ImportErrorr1   r7   r8   s    r&   test_findFileWithImportErrorz+FinderPy3Tests.test_findFileWithImportErrorE   s3    
 	/1R	
 	
 	
 	
 	
r(   r   r+   )	__name__
__module____qualname__r/   r9   r<   rB   rE   __classcell__)r3   s   @r&   r*   r*   +   s        * * * * * *
 
 
 
O O O OD D D D
 
 
 
 
 
 
 
r(   r*   moduler   Matcher[ModuleType]c                   | j         }|J t          t          |j                  t	          t
          j        t          t          j        |j                                      d          }t	          t          d          |          S )a  
    Match a module with a L{ModuleSpec} like that of the given module.

    @return: A matcher for a module spec that has the same name and origin as
        the given module spec, though the origin may be structurally inequal
        as long as it is semantically equal.
    N)nameorigin__spec__)	rP   r   r   rN   r   r   FilePathrO   r   )rK   expected
match_specs      r&   looselyResemblesrT   O   s     H X]++!*8?;;<< 	
 	
 J J''444r(   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 )	FileTestsz/
    Tests for L{runner.filenameToModule}.
    r   r+   c                    |                      t          t          j        d          }|                     t          |          d           dS )zo
        L{runner.filenameToModule} raises a C{ValueError} when a non-existing
        file is passed.
        itz'it' doesn't existN)r5   r@   r   filenameToModuleassertEqualstr)r2   errs     r&   test_notFilezFileTests.test_notFilel   sA    
 
F,CTJJS#788888r(   c                    t          j        t          j        t          d                    }ddlm} |                     ||           dS )z
        If the file in question is a module on the Python path, then it should
        properly import and return that module.
        z	sample.pyr   sampleN)r   rY   r   r>   r?   twisted.trial.testr`   rZ   r2   sample1sample2s      r&   test_moduleInPathzFileTests.test_moduleInPatht   sN    
 )$,x*M*MNN888888'*****r(   c                   |                      | j                   t          j        t          j                            | j        dd                    }|                     |j	        d           | 
                                 |                      | j                   ddlm} |                     ||           t          |t!          |                     dS )a  
        If passed the path to a file containing the implementation of a
        module within a package which is not on the import path,
        L{runner.filenameToModule} returns a module object loosely
        resembling the module defined by that file anyway.
        goodpackageztest_sample.pyzgoodpackage.test_sampler   )test_sampleN)mangleSysPatholdPathr   rY   osrA   joinparentrZ   rG   cleanUpModulesnewPathrg   rh   assertIsNotr
   rT   rb   s      r&   test_moduleNotInPathzFileTests.test_moduleNotInPath~   s     	4<((()GLLm5EFF
 
 	)+DEEE4<(((666666'***G-g6677777r(   c                    t          j        t          j                            | j        d                    }|                     |t          j        d                    dS )z
        If the file in question is a package on the Python path, then it should
        properly import and return that package.
        rg   N)	r   rY   rk   rA   rl   rm   assertIssysmodules)r2   package1s     r&   test_packageInPathzFileTests.test_packageInPath   sG    
 *27<<]+S+STThM :;;;;;r(   c                   |                      | j                   t          j        t          j                            | j        d                    }|                     |j	        d           | 
                                 |                      | j                   ddl}|                     ||           t          |t          |                     dS )z
        If passed the path to a directory which represents a package which
        is not on the import path, L{runner.filenameToModule} returns a
        module object loosely resembling the package defined by that
        directory anyway.
        rg   r   N)ri   rj   r   rY   rk   rA   rl   rm   rZ   rG   rn   ro   rg   rp   r
   rT   )r2   rv   rg   s      r&   test_packageNotInPathzFileTests.test_packageNotInPath   s     	4<(((*27<<]+S+STT*M:::4<(((;///H.{;;<<<<<r(   c                2   t          j        | j                                      d          }|                                 |                     t          t          j        |j	                  }| 
                    t          |          |j	        d           dS )z
        L{runner.filenameToModule} raises a C{ValueError} when the name of an
        empty directory is passed that isn't considered a valid Python package
        because it doesn't contain a C{__init__.py} file.
        emptyDirectoryz is not a package directoryN)r   rQ   rm   childcreateDirectoryr5   r@   r   rY   rA   rZ   r[   )r2   emptyDirr\   s      r&   test_directoryNotPackagez"FileTests.test_directoryNotPackage   s     $T[11778HII  """
F,CX]SSShm#R#R#RSSSSSr(   c                    t          j        | j                                      d          }|                    d           |                     t          t          j        |j	                   dS )zn
        L{runner.filenameToModule} raises a C{SyntaxError} when a non-Python
        file is passed.
        	notpythons   This isn't pythonN)
r   rQ   rm   r|   
setContentr5   SyntaxErrorr   rY   rA   )r2   filenames     r&   test_filenameNotPythonz FileTests.test_filenameNotPython   s\    
 $T[1177DD0111+v'>NNNNNr(   c                   t          j        | j                                      d          }|                    t
          j                            d                     	 t          j	        |j
                  }|                     |j
        |j                   |                                 dS # |                                 w xY w)zX
        The C{__file__} attribute of the module should match the package name.
        zgoodpackage.pyutf8N)r   rQ   rm   r|   r   r   
testModuleencoder   rY   rA   rZ   r?   remove)r2   r   rK   s      r&   test_filenameMatchesPackagez%FileTests.test_filenameMatchesPackage   s     $T[11778HIIH/66v>>???	,X];;FX]FO<<<OOHOOs    9B/ /Cc                n   t          j        | j                                      d          }|                                 |                    d                              d           	 t          j        |j                  }| 	                    |j
                            d                     t          j        |j        t          j        j        z             }| 	                    |j
                            d                     |                                 dS # |                                 w xY w)z
        Test loader against a filesystem directory containing an empty
        C{__init__.py} file. It should handle 'path' and 'path/' the same way.
        goodDirectory__init__.pyr(   N)r   rQ   rm   r|   r}   r   r   rY   rA   
assertTruerG   endswithrk   sepr   )r2   goodDirrK   s      r&   test_directoryzFileTests.test_directory   s    
 #DK0066GG!!!m$$//444	,W\::FOOFO44_EEFFF,W\BGK-GHHFOOFO44_EEFFFNNGNNs   *BD D4NrF   )rG   rH   rI   __doc__r]   re   rq   rw   ry   r   r   r   r    r(   r&   rV   rV   g   s         9 9 9 9+ + + +8 8 8 8*< < < <= = = =$
T 
T 
T 
TO O O O        r(   rV   c                  
   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'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 ))LoaderTestsz(
    Tests for L{trial.TestLoader}.
    r   r+   c                t    t          j                    | _        t          j                            |            d S r-   )r   r0   r1   r   SysPathManglingTestr/   r8   s    r&   r/   zLoaderTests.setUp   s/    '))$**400000r(   c                   ddl m} | j                            |j                  }|                     g dd |j        D                        g d}t          t          |t          d                              fd| j        _
        | j                            |j                  }|                     |d |j        D                        d S )	Nr   r_   )test_atest_btest_cc                    g | ]	}|j         
S r   _testMethodName.0r%   s     r&   
<listcomp>z.LoaderTests.test_sortCases.<locals>.<listcomp>   s    ;;;dT!;;;r(   )r   r   r      c                T                         |                                 d          S )N)getshortDescription)xsortDicts    r&   <lambda>z,LoaderTests.test_sortCases.<locals>.<lambda>   s!    x||A4F4F4H4H"'M'M r(   c                    g | ]	}|j         
S r   r   r   s     r&   r   z.LoaderTests.test_sortCases.<locals>.<listcomp>   s    #R#R#RTD$8#R#R#Rr(   )ra   r`   r1   	loadClassAlphabetTestrZ   _testsdictziprangesorter)r2   r`   suitenewOrderr   s       @r&   test_sortCaseszLoaderTests.test_sortCases   s    ------%%f&9::***;;el;;;	
 	
 	
 211HeAhh//00MMMM%%f&9::#R#RU\#R#R#RSSSSSr(   c                   | j                             d          }t          j                    }|                    |           |                     |j        d           |                     t          |j                  d           dS )z{
        Loading a test that fails and getting the result of it ends up with one
        test ran and one failure.
        z6twisted.trial.test.erroneous.TestRegularFail.test_failr   N)	r1   
loadByNamer   
TestResultrunrZ   testsRunlenfailures)r2   r   results      r&   test_loadFailurezLoaderTests.test_loadFailure   s~    
 &&D
 
 $&&		&!,,,V_--q11111r(   c                    ddl m} | j                            |j        j        |j        g d          }|                     d|                                           |                     d|j                   dS )z
        A decorated test method for which the decorator has failed to set the
        method's __name__ correctly is loaded and its name in the class scope
        discovered.
        r   r_   )r`   DecorationTesttest_badDecoratorrm   qualNamer   r   N)	ra   r`   r1   loadAnythingr   r   rZ   countTestCasesr   r2   r`   r   s      r&   test_loadBadDecoratorz!LoaderTests.test_loadBadDecorator  s     	.-----((!3(FFF ) 
 

 	E0022333,e.CDDDDDr(   c                    ddl m} | j                            |j        j        |j        g d          }|                     d|                                           |                     d|j                   dS )z
        A decorated test method for which the decorator has set the method's
        __name__ correctly is loaded and the only name by which it goes is used.
        r   r_   )r`   r   test_goodDecoratorr   r   r   N)	ra   r`   r1   r   r   r   rZ   r   r   r   s      r&   test_loadGoodDecoratorz"LoaderTests.test_loadGoodDecorator  s    
 	.-----((!4(GGG ) 
 

 	E0022333-u/DEEEEEr(   c                    ddl m} | j                            |j        j        |j        g d          }|                     d|                                           |                     d|j                   dS )z
        Load a decorated method which has been copied to a new name inside the
        class.  Thus its __name__ and its key in the class's __dict__ no
        longer match.
        r   r_   )r`   r   test_renamedDecoratorr   r   r   N)	ra   r`   r1   r   r   r   rZ   r   r   r   s      r&   test_loadRenamedDecoratorz%LoaderTests.test_loadRenamedDecorator%  s     	.-----((!7(JJJ ) 
 

 	E00223330%2GHHHHHr(   c                    ddl m} | j                            |j                  }|                     d|                                           |                     ddgd |j        D                        d S )Nr   r_      test_bartest_fooc                    g | ]	}|j         
S r   r   r   s     r&   r   z.LoaderTests.test_loadClass.<locals>.<listcomp>;  s    &U&U&Ut';&U&U&Ur(   )ra   r`   r1   r   FooTestrZ   r   r   r   s      r&   test_loadClasszLoaderTests.test_loadClass5  s    ------%%fn55E0022333$&U&U&U&U&U	
 	
 	
 	
 	
r(   c                V   ddl m} |                     t          | j        j        |           |                     t          | j        j        |j        j                   |                     t          | j        j        d           |                     t          | j        j        d           d S Nr   r_   string)foobar)ra   r`   r5   	TypeErrorr1   r   r   r   r2   r`   s     r&   test_loadNonClasszLoaderTests.test_loadNonClass>  s    ------)T[%:FCCC)T[%:FN<STTT)T[%:HEEE)T[%:NKKKKKr(   c                h    ddl m} |                     t          | j        j        |j                   d S Nr   r_   )ra   r`   r5   r@   r1   r   NotATestr   s     r&   test_loadNonTestCasez LoaderTests.test_loadNonTestCaseF  s9    ------*dk&;V_MMMMMr(   c                    ddl m} | j                            |          }|                     d|                                           d S )Nr   r_   
   )ra   r`   r1   
loadModulerZ   r   r   s      r&   test_loadModulezLoaderTests.test_loadModuleK  sQ    ------&&v..U113344444r(   c                `   ddl m} |                     t          | j        j        |j                   |                     t          | j        j        |j        j                   |                     t          | j        j        d           |                     t          | j        j        d           d S r   )ra   r`   r5   r   r1   r   r   r   r   s     r&   test_loadNonModulezLoaderTests.test_loadNonModuleQ  s    ------)T[%;V^LLL)T[%;V^=TUUU)T[%;XFFF)T[%;^LLLLLr(   c                    dd l }| j                            |          }|                     d|                                           d S Nr      rg   r1   loadPackagerZ   r   r2   rg   r   s      r&   test_loadPackagezLoaderTests.test_loadPackageY  sK    ''44E002233333r(   c                `   ddl m} |                     t          | j        j        |j                   |                     t          | j        j        |j        j                   |                     t          | j        j        d           |                     t          | j        j        d           d S r   )ra   r`   r5   r   r1   r   r   r   r   s     r&   test_loadNonPackagezLoaderTests.test_loadNonPackage_  s    ------)T[%<fnMMM)T[%<fn>UVVV)T[%<hGGG)T[%<nMMMMMr(   c                ^    ddl m} |                     t          | j        j        |           d S r   )ra   r`   r5   r   r1   r   r   s     r&   test_loadModuleAsPackagez$LoaderTests.test_loadModuleAsPackageg  s9    ------ 	)T[%<fEEEEEr(   c                    dd l }| j                            |d          }|                     d|                                           d S Nr   Trecurse   r   r   s      r&   test_loadPackageRecursivez%LoaderTests.test_loadPackageRecursivem  sP    ''T'BBU113344444r(   c                    ddl m} | j                            |          }|                     |j        |j        d         j        d         j        j                   d S r   )	ra   r`   r1   r   rZ   rG   r   r3   rH   r   s      r&   test_loadAnythingOnModulez%LoaderTests.test_loadAnythingOnModules  sf    ------((00OU\!_3A6@K	
 	
 	
 	
 	
r(   c                    ddl m} | j                            |j                  }|                     d|                                           d S )Nr   r_   r   )ra   r`   r1   r   r   rZ   r   r   s      r&   test_loadAnythingOnClassz$LoaderTests.test_loadAnythingOnClass{  sS    ------((88E002233333r(   c                    dd l }| j                            |          }|                     t	          || j        j                             |                     d|                                           d S r   rg   r1   r   r   
isinstancesuiteFactoryrZ   r   r   s      r&   test_loadAnythingOnPackagez&LoaderTests.test_loadAnythingOnPackage  sl    ((55
5$+*BCCDDDE002233333r(   c                    dd l }| j                            |d          }|                     t	          || j        j                             |                     d|                                           d S r   r   r   s      r&   #test_loadAnythingOnPackageRecursivez/LoaderTests.test_loadAnythingOnPackageRecursive  sq    ((d(CC
5$+*BCCDDDU113344444r(   c                R    |                      t          | j        j        d           d S )Nrg   )r5   r   r1   r   r8   s    r&   test_loadAnythingOnStringz%LoaderTests.test_loadAnythingOnString  s'     	)T[%=}MMMMMr(   c                   dd l }| j                            |d          }t          j                    }|                    |           |                     d|                                           |                     dt          |j	                             d |j	        D             }|
                                 |                     |ddg           d S )	Nr   Tr   Fr   c                <    g | ]\  }}|                                 S r   )r#   )r   r%   errors      r&   r   z1LoaderTests.test_importErrors.<locals>.<listcomp>  s$    ===e$''))===r(   zpackage.test_bad_modulezpackage.test_import_module)packager1   r   r   Reporterr   rZ   wasSuccessfulr   errorssort)r2   r	  r   r   r  s        r&   test_importErrorszLoaderTests.test_importErrors  s    '''>>"$$		& 4 4 6 6777C..///==v}===.0LM	
 	
 	
 	
 	
r(   c                    G d dt           j                  }| j                            |          }t	          j                    }|                    |           |                     |                                           dS )z
        L{TestLoader.loadClass} returns a suite with each test method
        represented by a different instances of the L{TestCase} they are
        defined on.
        c                      e Zd ZddZddZdS )>LoaderTests.test_differentInstances.<locals>.DistinctInstancesr   r+   c                    d| _         d S )Ntest1Run)firstr8   s    r&   test_1zELoaderTests.test_differentInstances.<locals>.DistinctInstances.test_1  s    '


r(   c                L    |                      t          | d                     d S )Nr  )assertFalsehasattrr8   s    r&   test_2zELoaderTests.test_differentInstances.<locals>.DistinctInstances.test_2  s&      w!7!788888r(   NrF   )rG   rH   rI   r  r  r   r(   r&   DistinctInstancesr    s<        ( ( ( (9 9 9 9 9 9r(   r  N)	pyunitTestCaser1   r   r   r
  r   r   r  )r2   r  r   r   s       r&   test_differentInstancesz#LoaderTests.test_differentInstances  s    	9 	9 	9 	9 	9 	9 	9 	9 %%&788"$$		&,,../////r(   c                    ddl m} | j                            |          }|                     d|                                           |                     dt          |dd                     dS )zp
        Check that C{test_suite} is used when present and other L{TestCase}s are
        not included.
        r   )mockcustomsuiteMyCustomSuiterN   N)ra   r  r1   r   rZ   r   getattr)r2   r  r   s      r&   test_loadModuleWith_test_suitez*LoaderTests.test_loadModuleWith_test_suite  su    
 	766666&&77E0022333'%*F*FGGGGGr(   c                    ddl m} | j                            |          }|                     d|                                           |                     dt          |dd                     dS )zo
        Check that C{testSuite} is used when present and other L{TestCase}s are
        not included.
        r   mockcustomsuite2r   rN   N)ra   r%  r1   r   rZ   r   r!  )r2   r%  r   s      r&   test_loadModuleWith_testSuitez)LoaderTests.test_loadModuleWith_testSuite  sv    
 	877777&&'788E0022333'%*F*FGGGGGr(   c                    ddl m} | j                            |          }|                     dt          |dd                     dS )z
        Check that if C{testSuite} and C{test_suite} are both present in a
        module then C{testSuite} gets priority.
        r   )mockcustomsuite3	testSuiterN   N)ra   r(  r1   r   rZ   r!  )r2   r(  r   s      r&   test_loadModuleWithBothCustomz)LoaderTests.test_loadModuleWithBothCustom  sT    
 	877777&&'788geVT&B&BCCCCCr(   c                    dd}ddl m} ||j        c|_        }	 |                     t          | j        j        |           ||_        dS # ||_        w xY w)zz
        Make sure that any C{AttributeError}s raised by C{testSuite} are not
        swallowed by L{TestLoader}.
        r   r+   c                      t          d          )Nzshould be reraised)r6   r   r(   r&   r)  zBLoaderTests.test_customLoadRaisesAttributeError.<locals>.testSuite  s     !5666r(   r   r$  NrF   )ra   r%  r)  r5   r6   r1   r   )r2   r)  r%  originals       r&   #test_customLoadRaisesAttributeErrorz/LoaderTests.test_customLoadRaisesAttributeError  s    	7 	7 	7 	7 	87777709;K;U,"H	2ndk.DFVWWW)1&&&&1111s   &A
 
	Atest1r   test2c                    t          |          }t          |          }|                                 |                                 |                     ||           d S r-   )r'   r  rZ   )r2   r/  r0  names1names2s        r&   assertSuitesEqualzLoaderTests.assertSuitesEqual  sT    
 5!!5!!(((((r(   c                    d}| j                             ||gd          }| j                             |d          }|                     ||           dS )z@
        Check that loadByNames ignores duplicate names
        twisted.trial.test.test_logTN)r1   loadByNamesr   r4  )r2   rK   suite1suite2s       r&   test_loadByNamesDuplicatez%LoaderTests.test_loadByNamesDuplicate  sX     /((&&)94@@''55vv.....r(   c                    g d}| j                             |          }t          j        t	          | j         j        |                    }|                     t          |          t          |                     dS )zX
        L{TestLoader.loadByNames} preserves the order of tests provided to it.
        )$inheritancepackage.test_x.A.test_fooztwisted.trial.test.samplerg   r6  z!twisted.trial.test.sample.FooTestpackage.test_moduleN)r1   r7  r   	TestSuitemapr   rZ   r'   r2   ru   r8  r9  s       r&   test_loadByNamesPreservesOrderz*LoaderTests.test_loadByNamesPreservesOrder  su    
 
 
 ((11!#dk&<g"F"FGG6**If,=,=>>>>>r(   c                    ddg}| j                             |          }t          j        t	          | j         j        |                    }|                     ||           dS )zM
        Check that loadByNames loads all the names that it is given
        rg   r=  Nr1   r7  r   r>  r?  r   r4  r@  s       r&   test_loadDifferentNamesz#LoaderTests.test_loadDifferentNames  s_     !"78((11!#dk&<g"F"FGGvv.....r(   c                    ddg}| j                             |          }t          j        t	          | j         j        |                    }|                     ||           dS )zu
        Check that test methods names which are inherited from are all
        loaded rather than just one.
        r<  z$inheritancepackage.test_x.B.test_fooNrC  )r2   methodsr8  r9  s       r&   test_loadInheritedMethodsz%LoaderTests.test_loadInheritedMethods  sc     32
 ((11!#dk&<g"F"FGGvv.....r(   NrF   )r/  r   r0  r   r   r+   )#rG   rH   rI   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.  r4  r:  rA  rD  rG  r   r(   r&   r   r      s        1 1 1 1T T T T2 2 2 2E E E E F F F FI I I I 
 
 
 
L L L LN N N N
5 5 5 5M M M M4 4 4 4N N N NF F F F5 5 5 5
 
 
 
4 4 4 44 4 4 45 5 5 5N N N N

 
 
 
0 0 0 0&	H 	H 	H 	H	H 	H 	H 	HD D D D2 2 2 2$	) 	) 	) 	)/ / / /? ? ? ? / / / // / / / / /r(   r   c                      e Zd ZddZdS )ZipLoadingTestsr   r+   c                    ddl m} t                              |             || j        | j        dz              | xj        dz  c_        |                     | j        | j        gz              d S )Nr   )zipitz.zip) twisted.python.test.test_zippathrK  r   r/   rm   ri   rj   )r2   rK  s     r&   r/   zZipLoadingTests.setUp#  sx    ::::::$dk4;/000v4<4;-788888r(   NrF   )rG   rH   rI   r/   r   r(   r&   rI  rI  "  s(        9 9 9 9 9 9r(   rI  c                  D    e Zd ZddZddZej        fdd	Zdd
ZddZ	dS )PackageOrderingTestsr   r+   c                   t          j                    | _        |                                 | _        t
          j                            | j        d          }t          j        |           t          t
          j                            |d          d          
                                 t          j                            | |           |                     | j        | j        gz              d S )Nuberpackager   wb)r   r0   r1   mktemptopDirrk   rA   rl   makedirsopencloser   r   r/   ri   rj   )r2   rm   s     r&   r/   zPackageOrderingTests.setUp-  s    '))kkmmdk=99
FRW\\&-00$77==???$**48884<4;-788888r(   r   BCallable[[PythonModule | PythonAttribute], SupportsRichComparison]5Generator[PythonModule | PythonAttribute, None, None]c              #    K   t          d          }g }|                                D ]J}|j                            d          d                             d          r|                    |           Kt          ||          }|D ]}|                    d          }||V  g }|                                D ]=}	t          j
        |	                                          r|                    |	           >t          ||          }
|
D ]|}g }|                                D ]J}|j                            d          d                             d          r|                    |           Kt          ||          }|E d{V  }dS )a  
        Right now, halfway by accident, trial sorts like this:

            1. all modules are grouped together in one list and sorted.

            2. within each module, the classes are grouped together in one list
               and sorted.

            3. finally within each class, each test method is grouped together
               in a list and sorted.

        This attempts to return a sorted list of testable thingies following
        those rules, so that we can compare the behavior of loadPackage.

        The things that show as 'cases' are errors from modules which failed to
        import, and test methods.  Let's gather all those together.
        rP  .r   test_)keyNr%   )r   walkModulesrN   split
startswithr"   sortedloaditerAttributesr   
isTestCase)r2   r   pkgtestModulesr   sortedModulesmodinforK   testClassesattribsortedClassesclsinfotestMethodsattrsortedMethodss                  r&   _trialSortAlgorithmz(PackageOrderingTests._trialSortAlgorithm6  s     ( &&//++ 	/ 	/J$$S))"-88AA /"":...{777$ 	- 	-G\\$''F~ %4466 3 3F(77 3#**6222 &{ ? ? ?, - -G"$K ' 6 6 8 8 5 59??3//3>>vFF 5'..t444$*;F$C$C$CM,,,,,,,,,-	- 	-r(   4Callable[[runner._Loadable], SupportsRichComparison]c           
     P   ddl }|| j        _        | j                            |d          }t	          j        |t                    }t          t          |                    }t          | 	                    |                    }t          t          ||                    D ]S\  }\  }}|                     |j        |                                d||j        |                                fz             T|                     t          |          t          |                     dS )zG
        Verify that packages are loaded in the correct order.
        r   NTr   z#%d: %s != %s)rP  r1   r   r   r   decorater   listr   ro  	enumerater   rZ   rN   r#   r   )	r2   r   rP  r   resultingTestsmanifestnumbermanifestTest
actualTests	            r&   loadSortedPackagesz'PackageOrderingTests.loadSortedPackagesc  s    	#''T'BB !%33mE22330088992;.))3
 3
 	 	.F.\: !6<+<jmmoo"NN   
 	XN(;(;<<<<<r(   c                .    |                                   d S r-   rz  r8   s    r&   test_sortPackagesDefaultOrderz2PackageOrderingTests.test_sortPackagesDefaultOrder|  s    !!!!!r(   c                8    dd}|                      |           d S )Nsrunner._Loadabler   r[   c                    t          j        |           }t          |                    d                                                    }|S )Nr   )r   rN   r   r   	hexdigest)r  nds      r&   sillySorterzEPackageOrderingTests.test_sortPackagesSillyOrder.<locals>.sillySorter  s;    
 AAAHHV$$%%//11AHr(   )r  r  r   r[   r|  )r2   r  s     r&   test_sortPackagesSillyOrderz0PackageOrderingTests.test_sortPackagesSillyOrder  s2    	 	 	 	 	,,,,,r(   NrF   )r   rW  r   rX  )r   rp  r   r+   )
rG   rH   rI   r/   ro  r   rN   rz  r}  r  r   r(   r&   rN  rN  ,  s        9 9 9 9+- +- +- +-\ NT[= = = = =2" " " "
- 
- 
- 
- 
- 
-r(   rN  )r   r   r   r    )rK   r   r   rL   )5r   
__future__r   rk   rt   r   r  hashlibr   operatorr   typesr   typingr   r   r	   hamcrestr
   r   r   hamcrest.core.matcherr   twisted.pythonr   r   twisted.python.modulesr   r   r   twisted.python.reflectr   twisted.trialr   r   twisted.trial._asyncrunnerr   twisted.trial.itrialr   ra   r   matchersr   	_typeshedr   r'   r   r*   rT   rV   r   rI  rN  r   r(   r&   <module>r     s    # " " " " " 				 



                       5 5 5 5 5 5 5 5 5 5 : : : : : : : : : : ) ) ) ) ) ) ) ) ) ) ) ) ) ) K K K K K K K K K K 1 1 1 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 * * * * * * ' ' ' ' ' '       1000000   !
 !
 !
 !
 !
X1 !
 !
 !
H5 5 5 50x x x x x, x x xv}/ }/ }/ }/ }/(. }/ }/ }/@
9 9 9 9 9k 9 9 9]- ]- ]- ]- ]-87 ]- ]- ]- ]- ]-r(   