ó
®9lUc           @   sÒ  d  Z  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 m Z d d l m Z 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 d d l m Z m Z m Z m Z m  Z  m! Z! m" Z" m# Z# m$ Z$ m% Z% d d l& m' Z' m( Z( m) Z) d d l
 m* Z* m+ Z+ e j, e- ƒ Z. e j/ j0 Z1 e j/ j2 Z3 e j/ j4 Z5 e j/ j6 Z7 e j/ j8 Z9 d d g Z: d e j; f d „  ƒ  YZ; e; Z< d S(   sß   
Test Loader
-----------

nose's test loader implements the same basic functionality as its
superclass, unittest.TestLoader, but extends it by more liberal
interpretations of what may be a test and how a test may be named.
iÿÿÿÿ(   t
   generatorsN(   t
   isfunction(   t   unbound_methodt   ismethod(   t   FunctionTestCaset   MethodTestCase(   t   Failure(   t   Config(   t   Importert   add_patht   remove_path(   t   defaultSelectort   TestAddress(
   t   func_linenot
   getpackaget   isclasst   isgeneratort	   ispackaget   regex_last_keyt   resolve_namet   transplant_funct   transplant_classt   test_address(   t   ContextSuiteFactoryt   ContextListt	   LazySuite(   t	   sort_listt
   cmp_to_keyt
   TestLoadert   defaultTestLoaderc           B   sæ   e  Z d  Z d Z d Z d Z d Z d Z d d d d d „ Z	 d „  Z
 d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d e d	 „ Z d e d
 „ Z d d „ Z d „  Z d „  Z d d „ Z d d „ Z d „  Z d „  Z RS(   sA  Test loader that extends unittest.TestLoader to:

    * Load tests from test-like functions and classes that are not
      unittest.TestCase subclasses
    * Find and load test modules in a directory
    * Support tests that are generators
    * Support easy extensions of or changes to that behavior through plugins
    c         C   s  | d k r t ƒ  } n  | d k r6 t d | ƒ } n  | d k rN | j } n  | d k ri t | ƒ } n t | ƒ r„ | | ƒ } n  | |  _ | |  _ t t	 | ƒ ƒ |  _ | |  _
 | j rÍ t | | ƒ n  t d | ƒ |  _ t g  ƒ |  _ t j j |  ƒ d S(   s  Initialize a test loader.

        Parameters (all optional):

        * config: provide a `nose.config.Config`_ or other config class
          instance; if not provided a `nose.config.Config`_ with
          default values is used.
        * importer: provide an importer instance that implements
          `importFromPath`. If not provided, a
          `nose.importer.Importer`_ is used.
        * workingDir: the directory to which file and module names are
          relative. If not provided, assumed to be the current working
          directory.
        * selector: a selector class or instance. If a class is
          provided, it will be instantiated with one argument, the
          current config. If not provided, a `nose.selector.Selector`_
          is used.
        t   configN(   t   NoneR   R   t
   workingDirR   R   R   t   importert   op_normpatht
   op_abspatht   selectort   addPathsR	   R   t
   suiteClasst   sett   _visitedPathst   unittestR   t   __init__(   t   selfR   R!   R    R$   (    (    s*   lib/python2.7/site-packages/nose/loader.pyR*   ;   s&    				c         C   sŽ   |  j  j r t j j |  | ƒ S| |  j d „ } t | t | ƒ ƒ } | rh t | d ƒ rh d g } n  |  j	 rŠ t
 | t |  j	 ƒ ƒ n  | S(   s_   Override to select with selector, unless
        config.getTestCaseNamesCompat is True
        c         S   sM   t  | |  d  ƒ } t | ƒ r0 t | | ƒ } n t | ƒ s@ t S| j | ƒ S(   N(   t   getattrR   R   R   R   t   Falset
   wantMethod(   t   attrt   clst   selt   item(    (    s*   lib/python2.7/site-packages/nose/loader.pyt   wantedl   s    t   runTest(   R   t   getTestCaseNamesCompatR)   R   t   getTestCaseNamesR$   t   filtert   dirt   hasattrt   sortTestMethodsUsingR   R   (   R+   t   testCaseClassR3   t   cases(    (    s*   lib/python2.7/site-packages/nose/loader.pyR6   e   s    	c         C   s   | d  k r t S| |  j k S(   N(   R   R-   R(   (   R+   t   path(    (    s*   lib/python2.7/site-packages/nose/loader.pyt   _haveVisited}   s    c         C   s#   | d  k	 r |  j j | ƒ n  d  S(   N(   R   R(   t   add(   R+   R=   (    (    s*   lib/python2.7/site-packages/nose/loader.pyt   _addVisitedPath…   s    c         #   s™  t  j d | ƒ ˆ j j } | j | ƒ ˆ j j rJ t | ˆ j ƒ } n  t j | ƒ } t	 | t
 ˆ j j ƒ ƒ xa| D]Y} | j d ƒ r” qy n  t t | | ƒ ƒ ‰  t ˆ  ƒ } t } | rÜ t } ˆ j j ˆ  ƒ } n< t ˆ  ƒ } | r| j d ƒ rqy n  ˆ j j ˆ  ƒ } n  t ˆ  ƒ }	 | ry ˆ j ˆ  ƒ ry ˆ j ˆ  ƒ | r˜| j ƒ  | j d ƒ r}ˆ j ˆ  d t ƒVn ˆ j ˆ  ƒ V| j ƒ  qÒ|	 rµˆ j ˆ  d t ƒVqÒˆ j ‡  ‡ f d †  ƒ Vqy qy Wg  }
 x$ | j | ƒ D] } |
 j  | ƒ qìWy |
 rˆ j |
 ƒ Vn  Wn= t! t" f k
 r:‚  n$ ˆ j t# t$ j% ƒ  Œ  g ƒ Vn Xˆ j j rˆx | D] } t& | ƒ qqWn  | j' | ƒ d S(   sÚ   Load tests from the directory at path. This is a generator
        -- each suite of tests from a module or other file is yielded
        and is expected to be executed before the next file is
        examined.
        s   load from dir %st   .t   _s   .pyt
   discoveredc              s   ˆ j  ˆ  ƒ S(   N(   t   loadTestsFromDir(    (   t
   entry_pathR+   (    s*   lib/python2.7/site-packages/nose/loader.pyt   <lambda>Ã   s    N((   t   logt   debugR   t   pluginst   beforeDirectoryR%   R	   t   ost   listdirR   R   t	   testMatcht
   startswithR#   t   op_joint	   op_isfileR-   R$   t   wantFilet   op_isdirt   wantDirectoryR   R>   R@   t   beforeContextt   endswitht   loadTestsFromNamet   Truet   loadTestsFromFilet   afterContextR&   RD   t   appendt   KeyboardInterruptt
   SystemExitR   t   syst   exc_infoR
   t   afterDirectory(   R+   R=   RI   t   paths_addedt   entriest   entryt   is_fileR3   t   is_dirt
   is_packaget   testst   testt   p(    (   RE   R+   s*   lib/python2.7/site-packages/nose/loader.pyRD   ‰   sd    
!c      	   C   sè   t  j d | ƒ yq g  |  j j j | ƒ D] } | ^ q) } | r] t d | ƒ } |  j | ƒ St | d ƒ j	 ƒ  t
 d | ƒ ‚ Wn` t t f k
 r ‚  nG t j ƒ  } |  j t | d | d | d d | d d f ƒg ƒ SXd S(	   s¸   Load tests from a non-module file. Default is to raise a
        ValueError; plugins may implement `loadTestsFromFile` to
        provide a list of tests loaded from the file.
        s   Load from non-module file %st   rs!   Unable to load tests from file %si    i   i   t   addressN(   RG   RH   R   RI   RX   R7   R   R&   t   opent   closet
   ValueErrorR[   R\   R]   R^   R   (   R+   t   filenameRg   Rf   t   exc(    (    s*   lib/python2.7/site-packages/nose/loader.pyRX   Ö   s"    %c            s1   ˆ  | ‡  ‡ f d † } ˆ j  | d ˆ  d t ƒS(   sº   Lazy-load tests from a generator function. The generator function
        may yield either:

        * a callable, or
        * a function name resolvable within the same module
        c         3   s¸   yb x[ |  ƒ  D]P } ˆ j  | ƒ \ } } t | ƒ sF t | | ƒ } n  t | d | d |  ƒVq WWnO t k
 rx ‚  n< t j ƒ  } t | d | d | d d t ˆ  ƒ ƒVn Xd  S(   Nt   argt
   descriptori    i   i   Rj   (	   t   parseGeneratedTestt   callableR,   R   R[   R]   R^   R   R   (   t   gt   mRg   t	   test_funcRp   Ro   (   t	   generatorR+   (    s*   lib/python2.7/site-packages/nose/loader.pyt   generateù   s    t   contextt	   can_split(   R&   R-   (   R+   Rw   t   moduleRx   (    (   Rw   R+   s*   lib/python2.7/site-packages/nose/loader.pyt   loadTestsFromGeneratorò   s    c            sm   t  ˆ  d ƒ r ˆ  j } n  | ƒ  } ˆ  j } t | | ƒ ‰  ˆ  | ‡  ‡ f d † } ˆ j | d ˆ  d t ƒS(   sý   Lazy-load tests from a generator method.

        This is more complicated than loading from a generator function,
        since a generator method may yield:

        * a function
        * a bound or unbound method, or
        * a method name
        t   im_classc         3   s  y² x« |  ƒ  D]  } ˆ j  | ƒ \ } } t | ƒ sO t | t | | ƒ ƒ } n  t | ƒ ru t | d | d |  ƒVq t | ƒ r› t |  d | d | ƒVq t t d | ƒ Vq WWnO t k
 rÈ ‚  n< t	 j
 ƒ  } t | d | d | d d t ˆ  ƒ ƒVn Xd  S(	   NRp   Rq   Rg   s   %s is not a callable or methodi    i   i   Rj   (   Rr   Rs   R   R,   R   R   R   t	   TypeErrorR[   R]   R^   R   (   Rt   t   cRg   Rv   Rp   Ro   (   Rw   R+   (    s*   lib/python2.7/site-packages/nose/loader.pyRx     s$    Ry   Rz   (   R9   R}   t   __name__R,   R&   R-   (   R+   Rw   R0   t   instt   methodRx   (    (   Rw   R+   s*   lib/python2.7/site-packages/nose/loader.pyt   loadTestsFromGeneratorMethod  s    		c            sG  t  j d ˆ  ƒ g  } g  } g  } | s; ˆ j j ˆ  ƒ rx… t ˆ  ƒ D]w } t ˆ  | d ƒ } t | ƒ r‘ ˆ j j | ƒ r¿ | j	 | ƒ q¿ qH t
 | ƒ rH ˆ j j | ƒ rH | j	 | ƒ qH qH Wt | d „  ƒ t | t ƒ t ‡  ‡ f d †  | | ƒ } n  t ˆ  d g  ƒ }	 | r;t j j t j j | ƒ ƒ } n  xÀ |	 D]¸ }
 t  j d |
 ƒ t  j d | t j j |
 ƒ t j j t j j |
 ƒ ƒ ƒ ˆ j j sÌ| sÌt j j t j j |
 ƒ ƒ j | ƒ rBt j j |
 ƒ rú| j ˆ j |
 ƒ ƒ qúqBqBWx- ˆ j j j ˆ  | ƒ D] } | j	 | ƒ qWˆ j t | d ˆ  ƒƒ S(	   sã   Load all tests from module and return a suite containing
        them. If the module has been discovered and is not test-like,
        the suite will be empty by default, though plugins may add
        their own tests.
        s   Load from module %sc         S   s   |  j  S(   N(   R€   (   t   x(    (    s*   lib/python2.7/site-packages/nose/loader.pyRF   J  s    c            s   ˆ j  |  d ˆ  ƒS(   Nt   parent(   t   makeTest(   t   t(   R{   R+   (    s*   lib/python2.7/site-packages/nose/loader.pyRF   L  s    t   __path__s   Load tests from module path %s?s!   path: %s os.path.realpath(%s): %sRy   N(   RG   RH   R$   t
   wantModuleR8   R,   R   R   t	   wantClassRZ   R   t   wantFunctionR   R   t   mapRK   R=   t   normcaset   realpathR   t   traverseNamespaceRN   t   isdirt   extendRD   RI   t   loadTestsFromModuleR&   R   (   R+   R{   R=   RC   Rf   t   test_classest
   test_funcsR2   Rg   t   module_pathst   module_path(    (   R{   R+   s*   lib/python2.7/site-packages/nose/loader.pyR’   4  s@    !		 c            sh  t  j d | | ƒ ˆ j } ˆ j j j | | ƒ } | rD | | ƒ St | d ˆ j ƒ} | rD| j rt | j } n  ˆ j	 | | ƒ \ } } t
 | ƒ rê t | d d ƒ | j k rê t | t ƒ rê t | | j ƒ } t | | j ƒ } n  t  j d | | | ƒ t | t ƒ r| | g ƒ S| t ˆ j | | ƒ g d | ƒƒ Sn | j rby€ | j d k rqt | j ƒ } n[ ˆ j j j | j | j ƒ z ˆ j j | j | j ƒ } Wd ˆ j j j | j | j ƒ XWnZ t t f k
 ré‚  nA t j ƒ  }	 | t |	 d |	 d |	 d	 d
 | j ƒ  ƒg ƒ SX| j rFˆ j | j | ƒ Sˆ j | | j d | ƒSn| j r>| j ‰  | j rÚt  ˆ  ƒ }
 |
 d k rÄ| t t! d | j ˆ  f d
 | j ƒ  ƒg ƒ Sˆ j | j d |
 ƒSt" ˆ  ƒ rüt# ‡  ‡ f d †  ƒ St$ ˆ  ƒ rˆ j% ˆ  ƒ S| t t& d ˆ  d
 | j ƒ  ƒg ƒ Sn& | t t! d | d
 | j ƒ  ƒg ƒ Sd S(   sã   Load tests from the entity with the given name.

        The name may indicate a file, directory, module, or any object
        within a module. See `nose.util.split_test_name` for details on
        test name parsing.
        s   load from %s (%s)R    t
   __module__s   parent %s obj %s module %sRy   Ni    i   i   Rj   RC   s>   Can't find callable %s in file %s: file is not a python moduleR{   c              s   ˆ j  ˆ  ƒ S(   N(   RD   (    (   R=   R+   (    s*   lib/python2.7/site-packages/nose/loader.pyRF   Ç  s    s   No such file %ss   Unresolvable test name %s('   RG   RH   R&   R   RI   RV   R   R    t   callt   resolveR   R,   R   R€   t
   isinstanceR   R   R   R†   R{   Rn   R   t   beforeImportR!   t   importFromPatht   afterImportR[   R\   R]   R^   t   totupleR’   R   Rm   RR   R   RP   RX   t   OSError(   R+   t   nameR{   RC   t   suitet
   plug_testst   addrR…   t   objRo   t   package(    (   R=   R+   s*   lib/python2.7/site-packages/nose/loader.pyRV   i  s€    	

				
			c         C   sw   |  j  j j | | ƒ } | ra | \ } } | ra |  j |  j | ƒ t j j |  | | ƒ g ƒ Sn  t j j |  | | ƒ S(   sS   Load tests from all names, returning a suite containing all
        tests.
        (   R   RI   t   loadTestsFromNamesR&   R)   R   (   R+   t   namesR{   t   plug_resR¡   (    (    s*   lib/python2.7/site-packages/nose/loader.pyR¦   Õ  s    c         C   s”   g  } |  j  j } x$ | j | ƒ D] } | j | ƒ q" W| sU t t |  ƒ j | ƒ S| j g  t t |  ƒ j | ƒ D] } | ^ qt ƒ |  j | ƒ S(   s6   Load tests from a unittest.TestCase subclass.
        (   R   RI   t   loadTestsFromTestCaseRZ   t   superR   R‘   R&   (   R+   R;   R<   RI   t   case(    (    s*   lib/python2.7/site-packages/nose/loader.pyR©   ã  s    )c         C   s•   | |  j  d „ } g  t | t | ƒ ƒ D]! } |  j t | | ƒ | ƒ ^ q( } x* |  j j j | ƒ D] } | j | ƒ qe W|  j	 t
 | d | ƒƒ S(   s!  Load tests from a test class that is *not* a unittest.TestCase
        subclass.

        In this case, we can't depend on the class's `__init__` taking method
        name arguments, so we have to compose a MethodTestCase for each
        method in the class that looks testlike.
        c         S   sM   t  | |  d  ƒ } t | ƒ r0 t | | ƒ } n t | ƒ s@ t S| j | ƒ S(   N(   R,   R   R   R   R   R-   R.   (   R/   R0   R1   R2   (    (    s*   lib/python2.7/site-packages/nose/loader.pyR3   ü  s    Ry   (   R$   R7   R8   R†   R,   R   RI   t   loadTestsFromTestClassRZ   R&   R   (   R+   R0   R3   R«   R<   Rg   (    (    s*   lib/python2.7/site-packages/nose/loader.pyR¬   ô  s    :c         C   s™   y |  j  | | ƒ SWn~ t t f k
 r0 ‚  ne t j ƒ  } y t | ƒ } Wn  t k
 re ‚  n d  } n Xt | d | d | d d | ƒSXd  S(   Ni    i   i   Rj   (   t	   _makeTestR[   R\   R]   R^   R   R   R   (   R+   R¤   R…   Ro   R£   (    (    s*   lib/python2.7/site-packages/nose/loader.pyR†   	  s    
c         C   sl  g  } y t  | ƒ } Wn  t k
 r, ‚  n d } n Xx- |  j j j | | ƒ D] } | j | ƒ qR Wy | r |  j | ƒ SWnK t t f k
 rœ ‚  n2 t	 j
 ƒ  } t | d | d | d d | ƒSXt | ƒ r| rt | t j ƒ rt | | ƒ } n  t | t j ƒ r| St | ƒ rƒ| rT| j | j k rTt | | j ƒ } n  t | t j ƒ rs|  j | ƒ S|  j | ƒ Snå t | ƒ rï| d k r§| j } n  t | t j ƒ rÆ| | j ƒ St | ƒ râ|  j | | ƒ St | ƒ Sny t | ƒ rQ| r(| j | j k r(t | | j ƒ } n  t | ƒ rD|  j  | | ƒ St! | ƒ Sn t t" d | d | ƒSd S(   sV   Given a test object and its parent, return a test case
        or test suite.
        i    i   i   Rj   s   Can't make a test from %sN(#   R   R[   R   R   RI   R†   RZ   R&   R\   R]   R^   R   R   Rš   t   typest
   ModuleTypeR   R)   t   TestCaseR   R—   R€   R   t
   issubclassR©   R¬   R   t	   __class__R   Rƒ   R   R   R|   R   R~   (   R+   R¤   R…   R¢   R£   Rg   Ro   (    (    s*   lib/python2.7/site-packages/nose/loader.pyR­     sX    
#%
c         C   sk   | } | j  d ƒ } x' | D] } | t | | d ƒ } } q W| d k ra t t d | ƒ } n  | | f S(   s#   Resolve name within module
        RA   s   No such test %sN(   t   splitR,   R   R   Rm   (   R+   R    R{   R¤   t   partst   partR…   (    (    s*   lib/python2.7/site-packages/nose/loader.pyR™   S  s    c         C   s‚   t  | t ƒ s" | t ƒ  } } nV t | ƒ d k rK | d t ƒ  } } n- t | ƒ d k sc t ‚ | d | d } } | | f S(   sŽ   Given the yield value of a test generator, return a func and args.

        This is used in the two loadTestsFromGenerator* methods.

        i   i    (   Rš   t   tuplet   lent   AssertionError(   R+   Rg   Rv   Rp   (    (    s*   lib/python2.7/site-packages/nose/loader.pyRr   _  s    N(   R€   R—   t   __doc__R   R   R!   R    R$   R&   R*   R6   R>   R@   RD   RX   R|   Rƒ   R-   R’   RV   R¦   R©   R¬   R†   R­   R™   Rr   (    (    (    s*   lib/python2.7/site-packages/nose/loader.pyR   ,   s0   	)				M			,5l		;	(=   R¹   t
   __future__R    t   loggingRK   R]   R)   R®   t   inspectR   t   nose.pyversionR   R   t	   nose.caseR   R   t   nose.failureR   t   nose.configR   t   nose.importerR   R	   R
   t   nose.selectorR   R   t	   nose.utilR   R   R   R   R   R   R   R   R   R   t
   nose.suiteR   R   R   R   R   t	   getLoggerR€   RG   R=   t   normpathR"   t   abspathR#   t   joinRO   R   RR   t   isfileRP   t   __all__R   R   (    (    (    s*   lib/python2.7/site-packages/nose/loader.pyt   <module>   s6   Fÿ ÿ D