
Mc           @   s  d  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 d d l m Z d	   Z d
 e	 j f d     YZ d e	 j f d     YZ d e	 j f d     YZ d e f d     YZ d e	 j f d     YZ d S(   s"   
Tests for loading tests by name.
iN(   t   util(   t   md5(   t   packages(   t   runnert   reportert   unittest(   t	   ITestCase(   t	   getModulec         C   s7   g  } x* t  j |   D] } | j | j    q W| S(   sI   
    Return the id of each test within the given test suite or case.
    (   R   t   _iterateTestst   appendt   id(   t   testst   namest   test(    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt	   testNames   s    t
   FinderTestc           B   sY   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   c         C   s#   t  j j |   t j   |  _ d  S(   N(   R   t   PackageTestt   setUpR   t
   TestLoadert   loader(   t   self(    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyR   "   s    c         C   s   t  j j |   d  S(   N(   R   R   t   tearDown(   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyR   &   s    c         C   s2   |  j  j d  } d d  l } |  j | |  d  S(   Nt   twistedi(   R   t
   findByNameR   t   failUnlessEqual(   R   t   sample1t   sample2(    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_findPackage)   s    c         C   s2   |  j  j d  } d d  l } |  j | |  d  S(   Ns   twisted.trial.test.samplei(   R   R   t   sampleR   (   R   R   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_findModule.   s    c         C   sD   t  j t d  } |  j j |  } d d  l } |  j | |  d  S(   Ns	   sample.pyi(   R    t   sibpatht   __file__R   R   R   R   (   R   t   pathR   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_findFile3   s    c         C   s5   |  j  j d  } d d  l } |  j | j |  d  S(   Ns!   twisted.trial.test.sample.FooTesti(   R   R   R   R   t   FooTest(   R   R   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_findObject9   s    c         C   s   |  j  t |  j j d  d  S(   Ns   twisted.trial.test.nonexistent(   t   failUnlessRaisest   AttributeErrorR   R   (   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_findNonModule>   s    		c         C   s   |  j  t |  j j d  d  S(   Nt	   nonextant(   R$   t
   ValueErrorR   R   (   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_findNonPackageC   s    		c         C   s/   t  j t d  } |  j t |  j j |  d  S(   Ns   nonexistent.py(   R    R   R   R$   R(   R   R   (   R   R    (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_findNonFileH   s    (   t   __name__t
   __module__R   R   R   R   R!   R#   R&   R)   R*   (    (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyR   !   s   								t   FileTestc           B   s_   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(
   s/   
    Tests for L{runner.filenameToModule}.
    c         C   s   |  j  t t j d  d  S(   Nt   doesntexist(   R$   R(   R   t   filenameToModule(   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_notFileR   s    	c         C   s;   t  j t j t d   } d d  l } |  j | |  d  S(   Ns	   sample.pyi(   R   R/   R    R   R   R   R   (   R   R   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_moduleInPathV   s    c         C   s   |  j  t j j d d  |  j |  j  t j t	 j
 j |  j d d   } |  j |  j  d d l m } |  j t	 j
 j | j  d t	 j
 j | j  d  d S(   s  
        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.
        t   test_samplet   goodpackages   test_sample.pyi(   R2   i    N(   t
   addCleanupt   syst   modulest   popt   Nonet   mangleSysPatht   oldPathR   R/   t   osR    t   joint   parentt   newPathR3   R2   R   t   splitextR   (   R   R   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_moduleNotInPath\   s    c         C   sA   t  j t j j |  j d   } d d  l } |  j | |  d  S(   NR3   i(   R   R/   R;   R    R<   R=   R3   R   (   R   t   package1R3   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_packageInPaths   s    c         C   s   |  j  t j j d  |  j |  j  t j t j	 j
 |  j d   } |  j |  j  d d l } |  j t j	 j | j  d t j	 j | j  d  d S(   s   
        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.
        t   __init__R3   iNi    (   R4   R5   R6   R7   R9   R:   R   R/   R;   R    R<   R=   R>   R3   R   R?   R   (   R   RA   R3   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_packageNotInPathz   s    c         C   s&   |  j  t t j t j t d   d  S(   Nt	   directory(   R$   R(   R   R/   R    R   R   (   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_directoryNotPackage   s    c         C   s&   |  j  t t j t j t d   d  S(   Ns   notpython.py(   R$   R(   R   R/   R    R   R   (   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_filenameNotPython   s    c         C   s|   t  j j |  j d  } t | d  } | j t j  | j   z& t	 j
 |  } |  j | | j  Wd  t  j |  Xd  S(   Ns   goodpackage.pyt   w(   R;   R    R<   R=   t   opent   writeR   t
   testModulet   closeR   R/   R   R   t   remove(   R   t   filenamet   fdt   module(    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_filenameMatchesPackage   s    
c         C   s   t  j t d  } t j |  t t j j | d  d  } | j   z^ t	 j
 |  } |  j | j j d   t	 j
 | t j j  } |  j | j j d   Wd t j |  Xd S(   sw   
        Test loader against a filesystem directory. It should handle
        'path' and 'path/' the same way.
        t   goodDirectorys   __init__.pyRH   N(   R    R   R   R;   t   mkdirt   fileR    R<   RL   R   R/   t   assert_R+   t   endswitht   sept   shutilt   rmtree(   R   R    t   fRP   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_directory   s    
(   R+   R,   t   __doc__R0   R1   R@   RB   RD   RF   RG   RQ   R[   (    (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyR-   N   s   								t
   LoaderTestc           B   s7  e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d    Z" d!   Z# RS("   s(   
    Tests for L{trial.TestLoader}.
    c         C   s#   t  j   |  _ t j j |   d  S(   N(   R   R   R   R   t   SysPathManglingTestR   (   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyR      s    c            s   d d  l  } |  j j | j  } |  j d d d g g  | j D] } | j ^ q=  d d d g } t t | t	 d        f d   |  j _
 |  j j | j  } |  j | g  | j D] } | j ^ q  d  S(   Nit   test_at   test_bt   test_ci   c            s     j  |  j   d  S(   Ni(   t   gett   shortDescription(   t   x(   t   sortDict(    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   <lambda>   s    (   R   R   t	   loadClasst   AlphabetTestR   t   _testst   _testMethodNamet   dictt   zipt   ranget   sorter(   R   R   t   suiteR   t   newOrder(    (   Re   sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_sortCases   s     	c         C   sQ   d d  l  } |  j j | j j  } |  j d | j    |  j d | j  d  S(   Nii   t   test_foo(   R   R   t
   loadMethodR"   Rr   R   t   countTestCasesRj   (   R   R   Ro   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadMethod   s    c         C   sm   d d  l  } |  j j | j j  } t j   } | j |  |  j | j	 d  |  j t
 | j  d  d  S(   Nii   (   t	   erroneousR   Rs   t   TestRegularFailt	   test_failR   t
   TestResultt   runR   t   testsRunt   lent   failures(   R   Rv   Ro   t   result(    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadFailingMethod   s    c         C   sw   d d  l  } |  j t |  j j |  |  j t |  j j | j  |  j t |  j j d  |  j t |  j j d  d  S(   Nit   stringt   foot   bar(   R   R   (   R   R$   t	   TypeErrorR   Rs   R"   (   R   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadNonMethod   s    		c         C   sQ   d d l  } |  j j | j j  } |  j d | j    |  j d | j  d S(   s   
        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.
        iNi   t   test_badDecorator(   R   R   Rs   t   DecorationTestR   t   assertEqualsRt   Rj   (   R   R   Ro   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadBadDecorator   s    c         C   sQ   d d l  } |  j j | j j  } |  j d | j    |  j d | j  d S(   s   
        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.
        iNi   t   test_goodDecorator(   R   R   Rs   R   R   R   Rt   Rj   (   R   R   Ro   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadGoodDecorator   s
    	c         C   sQ   d d l  } |  j j | j j  } |  j d | j    |  j d | j  d S(   s   
        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.
        iNi   t   test_renamedDecorator(   R   R   Rs   R   R   R   Rt   Rj   (   R   R   Ro   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadRenamedDecorator  s
    	c         C   sj   d d  l  } |  j j | j  } |  j d | j    |  j d d g g  | j D] } | j ^ qP  d  S(   Nii   t   test_barRr   (   R   R   Rg   R"   R   Rt   Ri   Rj   (   R   R   Ro   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadClass  s
    c         C   sz   d d  l  } |  j t |  j j |  |  j t |  j j | j j  |  j t |  j j d  |  j t |  j j d  d  S(   NiR   R   R   (   s   foos   bar(   R   R$   R   R   Rg   R"   Rr   (   R   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadNonClass  s    		c         C   s,   d d  l  } |  j t |  j j | j  d  S(   Ni(   R   R$   R(   R   Rg   t   NotATest(   R   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadNonTestCase   s    c         C   s8   d d  l  } |  j j |  } |  j d | j    d  S(   Nii
   (   R   R   t
   loadModulet   assertEqualRt   (   R   R   Ro   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadModule&  s    c         C   s}   d d  l  } |  j t |  j j | j  |  j t |  j j | j j  |  j t |  j j d  |  j t |  j j d  d  S(   NiR   R   R   (   s   foos   bar(   R   R$   R   R   R   R"   Rr   (   R   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadNonModule,  s    			c         C   s8   d d  l  } |  j j |  } |  j d | j    d  S(   Nii   (   R3   R   t   loadPackageR   Rt   (   R   R3   Ro   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadPackage7  s    c         C   s}   d d  l  } |  j t |  j j | j  |  j t |  j j | j j  |  j t |  j j d  |  j t |  j j d  d  S(   NiR   R   R   (   s   foos   bar(   R   R$   R   R   R   R"   Rr   (   R   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadNonPackage=  s    			c         C   s)   d d  l  } |  j t |  j j |  d  S(   Ni(   R   R$   R   R   R   (   R   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadModuleAsPackageH  s    c         C   s>   d d  l  } |  j j | d t } |  j d | j    d  S(   Nit   recursei   (   R3   R   R   t   TrueR   Rt   (   R   R3   Ro   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadPackageRecursiveN  s    c         C   sI   d d  l  } |  j j |  } |  j | j | j d j d j j  d  S(   Nii    (   R   R   t   loadAnythingR   R+   Ri   t	   __class__R,   (   R   R   Ro   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadAnythingOnModuleT  s    c         C   s;   d d  l  } |  j j | j  } |  j d | j    d  S(   Nii   (   R   R   R   R"   R   Rt   (   R   R   Ro   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadAnythingOnClass[  s    c         C   s>   d d  l  } |  j j | j j  } |  j d | j    d  S(   Nii   (   R   R   R   R"   Rr   R   Rt   (   R   R   Ro   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadAnythingOnMethoda  s    c         C   sT   d d  l  } |  j j |  } |  j t | |  j j   |  j d | j    d  S(   Nii   (   R3   R   R   t
   failUnlesst
   isinstancet   suiteFactoryR   Rt   (   R   R3   Ro   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadAnythingOnPackageg  s    c         C   sZ   d d  l  } |  j j | d t } |  j t | |  j j   |  j d | j    d  S(   NiR   i   (	   R3   R   R   R   R   R   R   R   Rt   (   R   R3   Ro   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt#   test_loadAnythingOnPackageRecursiven  s    c         C   s   |  j  t |  j j d  d  S(   NR3   (   R$   R   R   R   (   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadAnythingOnStringu  s    	c         C   s   d d  l  } |  j j | d t } t j   } | j |  |  j t | j	    |  j d t
 | j   g  | j D] \ } } | j   ^ qv } | j   |  j | d d g  d  S(   NiR   i   s   package.test_bad_modules   package.test_import_module(   t   packageR   R   R   R   t   ReporterRz   R   t   Falset   wasSuccessfulR|   t   errorsR
   t   sort(   R   R   Ro   R~   R   t   errorR   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_importErrors|  s    (
c         C   s[   d t  j f d     Y} |  j j |  } t j   } | j |  |  j | j    d S(   s   
        L{TestLoader.loadClass} returns a suite with each test method
        represented by a different instances of the L{TestCase} they are
        defined on.
        t   DistinctInstancesc           B   s   e  Z d    Z d   Z RS(   c         S   s   d |  _  d  S(   Nt   test1Run(   t   first(   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_1  s    c         S   s   |  j  t |  d   d  S(   NR   (   t   assertFalset   hasattr(   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_2  s    (   R+   R,   R   R   (    (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyR     s   	N(	   R   t   TestCaseR   Rg   R   R   Rz   t
   assertTrueR   (   R   R   Ro   R~   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_differentInstances  s
    c         C   sX   d d l  m } |  j j |  } |  j d | j    |  j d t | d d   d S(   sp   
        Check that C{test_suite} is used when present and other L{TestCase}s are
        not included.
        i(   t   mockcustomsuitei    t   MyCustomSuitet   nameN(   t   twisted.trial.testR   R   R   R   Rt   t   getattrR8   (   R   R   Ro   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadModuleWith_test_suite  s    c         C   sX   d d l  m } |  j j |  } |  j d | j    |  j d t | d d   d S(   so   
        Check that C{testSuite} is used when present and other L{TestCase}s are
        not included.
        i(   t   mockcustomsuite2i    R   R   N(   R   R   R   R   R   Rt   R   R8   (   R   R   Ro   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadModuleWith_testSuite  s    c         C   sB   d d l  m } |  j j |  } |  j d t | d d   d S(   s   
        Check that if C{testSuite} and C{test_suite} are both present in a
        module then C{testSuite} gets priority.
        i(   t   mockcustomsuite3t	   testSuiteR   N(   R   R   R   R   R   R   R8   (   R   R   Ro   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadModuleWithBothCustom  s    c         C   sZ   d   } d d l  m } | | j | _ } z |  j t |  j j |  Wd | | _ Xd S(   sz   
        Make sure that any C{AttributeError}s raised by C{testSuite} are not
        swallowed by L{TestLoader}.
        c           S   s   t  d   d  S(   Ns   should be reraised(   R%   (    (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyR     s    i(   R   N(   R   R   R   t   assertRaisesR%   R   R   (   R   R   R   t   original(    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt#   test_customLoadRaisesAttributeError  s    	c         C   s@   t  |  } t  |  } | j   | j   |  j | |  d  S(   N(   R   R   R   (   R   t   test1t   test2t   names1t   names2(    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   assertSuitesEqual  s
    

c         C   sJ   d } |  j  j | | g t  } |  j  j | t  } |  j | |  d S(   s@   
        Check that loadByNames ignores duplicate names
        s$   twisted.trial.test.test_test_visitorN(   R   t   loadByNamesR   t
   loadByNameR   (   R   RP   t   suite1t   suite2(    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadByNamesDuplicate  s    c         C   sP   d d g } |  j  j |  } t j t |  j  j |   } |  j | |  d S(   sM   
        Check that loadByNames loads all the names that it is given
        R3   s   package.test_moduleN(   R   R   R   t	   TestSuitet   mapR   R   (   R   R6   R   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadDifferentNames  s    c         C   sP   d d g } |  j  j |  } t j t |  j  j |   } |  j | |  d S(   su   
        Check that test methods names which are inherited from are all
        loaded rather than just one.
        s$   inheritancepackage.test_x.A.test_foos$   inheritancepackage.test_x.B.test_fooN(   R   R   R   R   R   R   R   (   R   t   methodsR   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_loadInheritedMethods  s
    	($   R+   R,   R\   R   Rq   Ru   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   R   (    (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyR]      sD   				
	
					
																		
			
		t   ZipLoadingTestc           B   s   e  Z d    Z RS(   c         C   sa   d d l  m } t j |   | |  j |  j d  |  j d 7_ |  j |  j |  j g  d  S(   Ni(   t   zipits   .zip(   t   twisted.test.test_pathsR   R]   R   R=   R9   R:   (   R   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyR     s
    (   R+   R,   R   (    (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyR     s   t   PackageOrderingTestc           B   sS   e  Z e j d k  r d Z n  d   Z d   Z e j d  Z	 d   Z
 d   Z RS(	   i   i   s  Python 2.3 import semantics make this behavior incorrect on that version of Python as well as difficult to test.  The second import of a package which raised an exception the first time it was imported will succeed on Python 2.3, whereas it will fail on later versions of Python.  Trial does not account for this, so this test fails with inconsistencies between the expected and the received loader errors.c         C   s   t  j   |  _ |  j   |  _ t j j |  j d  } t j |  t	 t j j | d  d  j
   t j j |  |  |  j |  j |  j g  d  S(   Nt   uberpackages   __init__.pyt   wb(   R   R   R   t   mktempt   topDirR;   R    R<   t   makedirsRT   RL   R   R^   R   R9   R:   (   R   R=   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyR     s    "c         c   s{  t  d  } g  } xC | j   D]5 } | j j d  d j d  r | j |  q q Wt | d | } x
| D]} | j d  } | d k r | Vqq g  } x9 | j	   D]+ }	 t
 j |	 j    r | j |	  q q Wt | d | }
 x |
 D]z } g  } xC | j	   D]5 } | j j d  d j d  r| j |  qqWt | d | } x | D] } | Vq`Wq Wqq Wd S(   s  
        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.
        R   t   .it   test_t   keyR   N(   R   t   walkModulesR   t   splitt
   startswithR	   t   sortedt   loadR8   t   iterAttributesR   t
   isTestCase(   R   Rn   t   pkgt   testModulesRK   t   sortedModulest   modinfoRP   t   testClassest   attribt   sortedClassest   clsinfot   testMethodst   attrt   sortedMethodst   methinfo(    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   _trialSortAlgorithm  s.    c   	      C   s   d d l  } | |  j _ |  j j | d t } t j | t  } t t j	 |   } t |  j
 |   } x[ t t | |   D]D \ } \ } } |  j | j | j   d | | j | j   f  q W|  j t |  t |   d S(   sG   
        Verify that packages are loaded in the correct order.
        iNR   s   #%d: %s != %s(   R   R   Rn   R   R   R   t   decorateR   t   listR   R   t	   enumerateRl   R   R   R
   R|   (	   R   Rn   R   Ro   t   resultingTestst   manifestt   numbert   manifestTestt
   actualTest(    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   loadSortedPackagesA  s    "c         C   s   |  j    d  S(   N(   R   (   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_sortPackagesDefaultOrderV  s    c         C   s   d   } |  j  |  d  S(   Nc         S   s%   t  j |   } t |  j   } | S(   N(   R   R   R   t	   hexdigest(   t   st   nt   d(    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   sillySorter[  s    (   R   (   R   R  (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   test_sortPackagesSillyOrderZ  s    	(   i   i   (   R+   R,   R5   t   version_infot   skipR   R   R   R   R   R   R  (    (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyR      s   				-	(   R\   R;   RX   R5   t   twisted.pythonR    t   twisted.python.hashlibR   R   R   t   twisted.trialR   R   R   t   twisted.trial.itrialR   t   twisted.python.modulesR   R   R   R   R^   R-   R]   R   R   (    (    (    sB   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_loader.pyt   <module>   s    	-i @
