ó
è¾bc           @   s  d  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 e Z e j d e j ƒ Z d „  Z d	 „  Z d
 „  Z d e f d „  ƒ  YZ e ƒ  Z e d „ Z e d „ Z d e e j d „ Z d e e j d „ Z d S(   s   Loading unittests.iÿÿÿÿN(   t
   cmp_to_key(   t   fnmatchi   (   t   caset   suites   [_a-z]\w*\.py$c         C   s/   d |  t  j ƒ  f } t d |  t | ƒ | ƒ S(   Ns#   Failed to import test module: %s
%st   ModuleImportFailure(   t	   tracebackt
   format_exct   _make_failed_testt   ImportError(   t   namet
   suiteClasst   message(    (    s%   /usr/lib/python2.7/unittest/loader.pyt   _make_failed_import_test   s    c         C   s   t  d |  | | ƒ S(   Nt   LoadTestsFailure(   R   (   R	   t	   exceptionR
   (    (    s%   /usr/lib/python2.7/unittest/loader.pyt   _make_failed_load_tests   s    c            sG   ‡  f d †  } i | | 6} t  |  t j f | ƒ } | | | ƒ f ƒ S(   Nc            s
   ˆ  ‚ d  S(   N(    (   t   self(   R   (    s%   /usr/lib/python2.7/unittest/loader.pyt   testFailure   s    (   t   typeR   t   TestCase(   t	   classnamet
   methodnameR   R
   R   t   attrst	   TestClass(    (   R   s%   /usr/lib/python2.7/unittest/loader.pyR      s    t
   TestLoaderc           B   s›   e  Z d  Z d Z e Z e j Z d Z
 d „  Z e d „ Z d d „ Z d d „ Z d „  Z d d d „ Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z RS(   s   
    This class is responsible for loading tests according to various criteria
    and returning them wrapped in a TestSuite
    t   testc         C   sn   t  | t j ƒ r! t d ƒ ‚ n  |  j | ƒ } | rR t | d ƒ rR d g } n  |  j t | | ƒ ƒ } | S(   s;   Return a suite of all test cases contained in testCaseClasssY   Test cases should not be derived from TestSuite. Maybe you meant to derive from TestCase?t   runTest(   t
   issubclassR   t	   TestSuitet	   TypeErrort   getTestCaseNamest   hasattrR
   t   map(   R   t   testCaseClasst   testCaseNamest   loaded_suite(    (    s%   /usr/lib/python2.7/unittest/loader.pyt   loadTestsFromTestCase0   s    c         C   sÝ   g  } x] t  | ƒ D]O } t | | ƒ } t | t ƒ r t | t j ƒ r | j |  j | ƒ ƒ q q Wt | d d ƒ } |  j
 | ƒ } | rÙ | d k	 rÙ y | |  | d ƒ SWqÙ t k
 rÕ } t | j | |  j
 ƒ SXn  | S(   s>   Return a suite of all test cases contained in the given modulet
   load_testsN(   t   dirt   getattrt
   isinstanceR   R   R   R   t   appendR$   t   NoneR
   t	   ExceptionR   t   __name__(   R   t   modulet   use_load_testst   testsR	   t   objR%   t   e(    (    s%   /usr/lib/python2.7/unittest/loader.pyt   loadTestsFromModule;   s    !c   
      C   sã  | j  d ƒ } | d k r} | } xK | ro y t d j | ƒ ƒ } PWq% t k
 rk | d =| sl ‚  ql q% Xq% W| d } n  | } x$ | D] } | t | | ƒ } } qŠ Wt | t j ƒ rÉ |  j	 | ƒ St | t
 ƒ r÷ t | t j ƒ r÷ |  j | ƒ St | t j ƒ rPt | t
 ƒ rPt | t j ƒ rP| d } | | ƒ } |  j | g ƒ St | t j ƒ rf| St | d ƒ rÏ| ƒ  }	 t |	 t j ƒ r”|	 St |	 t j ƒ r¶|  j |	 g ƒ St d | |	 f ƒ ‚ n t d | ƒ ‚ d S(   sS  Return a suite of all test cases given a string specifier.

        The name may resolve either to a module, a test case class, a
        test method within a test case class, or a callable object which
        returns a TestCase or TestSuite instance.

        The method optionally resolves the names relative to a given module.
        t   .iÿÿÿÿi   t   __call__s"   calling %s returned %s, not a tests$   don't know how to make test from: %sN(   t   splitR*   t
   __import__t   joinR   R'   R(   t   typest
   ModuleTypeR2   R   R   R   R   R$   t   UnboundMethodTypeR
   R   R   R   R   (
   R   R	   R-   t   partst
   parts_copyR0   t   partt   parentt   instR   (    (    s%   /usr/lib/python2.7/unittest/loader.pyt   loadTestsFromNameM   sH    		!
	c         C   s2   g  | D] } |  j  | | ƒ ^ q } |  j | ƒ S(   s   Return a suite of all test cases found using the given sequence
        of string specifiers. See 'loadTestsFromName()'.
        (   R@   R
   (   R   t   namesR-   R	   t   suites(    (    s%   /usr/lib/python2.7/unittest/loader.pyt   loadTestsFromNames~   s    %c         C   sP   | |  j  d „ } t | t | ƒ ƒ } |  j rL | j d t |  j ƒ ƒ n  | S(   sL   Return a sorted sequence of method names found within testCaseClass
        c         S   s%   |  j  | ƒ o$ t t | |  ƒ d ƒ S(   NR4   (   t
   startswithR   R'   (   t   attrnameR!   t   prefix(    (    s%   /usr/lib/python2.7/unittest/loader.pyt   isTestMethodˆ   s    t   key(   t   testMethodPrefixt   filterR&   t   sortTestMethodsUsingt   sortt	   _CmpToKey(   R   R!   RG   t   testFnNames(    (    s%   /usr/lib/python2.7/unittest/loader.pyR   …   s    	s   test*.pyc   	      C   sÄ  t  } | d k r- |  j d k	 r- |  j } n | d k rH t } | } n  t j j | ƒ } | t j k r t j j d | ƒ n  | |  _ t  } t j j	 t j j | ƒ ƒ rò t j j | ƒ } | | k r†t j j
 t j j | d ƒ ƒ } q†n” y t | ƒ Wn t k
 rt } nm Xt j | } | j d ƒ d } t j j t j j | j ƒ ƒ } | r†|  j | ƒ |  _ t j j | ƒ n  | rŸt d | ƒ ‚ n  t |  j | | ƒ ƒ } |  j | ƒ S(   s+  Find and return all test modules from the specified start
        directory, recursing into subdirectories to find them. Only test files
        that match the pattern will be loaded. (Using shell style pattern
        matching.)

        All test modules must be importable from the top level of the project.
        If the start directory is not the top level directory then the top
        level directory must be specified separately.

        If a test package name (directory with '__init__.py') matches the
        pattern then the package will be checked for a 'load_tests' function. If
        this exists then it will be called with loader, tests, pattern.

        If load_tests exists then discovery does  *not* recurse into the package,
        load_tests is responsible for loading all tests in the package.

        The pattern is deliberately not stored as a loader attribute so that
        packages can continue discovery themselves. top_level_dir is stored so
        load_tests does not need to pass this argument in to loader.discover().
        i    s   __init__.pyR3   s%   Start directory is not importable: %rN(   t   FalseR*   t   _top_level_dirt   Truet   ost   patht   abspatht   syst   insertt   isdirt   isfileR7   R6   R   t   modulesR5   t   dirnamet   __file__t    _get_directory_containing_modulet   removet   listt   _find_testsR
   (	   R   t	   start_dirt   patternt   top_level_dirt   set_implicit_topt   is_not_importablet
   the_modulet   top_partR/   (    (    s%   /usr/lib/python2.7/unittest/loader.pyt   discover‘   s:    		(
!c         C   ss   t  j | } t j j | j ƒ } t j j | ƒ j ƒ  j d ƒ r_ t j j	 t j j	 | ƒ ƒ St j j	 | ƒ Sd  S(   Ns   __init__.py(
   RU   RY   RR   RS   RT   R[   t   basenamet   lowerRD   RZ   (   R   t   module_nameR-   t	   full_path(    (    s%   /usr/lib/python2.7/unittest/loader.pyR\   Ñ   s
    !c         C   s‘   t  j j t  j j | ƒ ƒ d } t  j j | |  j ƒ } t  j j | ƒ sY t d ƒ ‚ | j d ƒ su t d ƒ ‚ | j	 t  j j
 d ƒ } | S(   Ni    s   Path must be within the projects   ..R3   (   RR   RS   t   splitextt   normpatht   relpathRP   t   isabst   AssertionErrorRD   t   replacet   sep(   R   RS   t   _relpathR	   (    (    s%   /usr/lib/python2.7/unittest/loader.pyt   _get_name_from_pathÝ   s    "c         C   s   t  | ƒ t j | S(   N(   R6   RU   RY   (   R   R	   (    (    s%   /usr/lib/python2.7/unittest/loader.pyt   _get_module_from_nameç   s    
c         C   s   t  | | ƒ S(   N(   R   (   R   RS   Rk   Ra   (    (    s%   /usr/lib/python2.7/unittest/loader.pyt   _match_pathë   s    c         c   s¹  t  j | ƒ } x£| D]›} t  j j | | ƒ } t  j j | ƒ r‹t j | ƒ sX q n  |  j | | | ƒ ss q n  |  j | ƒ } y |  j	 | ƒ } Wn t
 | |  j ƒ Vq±Xt  j j t | d | ƒ ƒ } t  j j | ƒ d }	 t  j j | ƒ d }
 |	 j ƒ  |
 j ƒ  k rzt  j j |	 ƒ } t  j j t  j j | ƒ ƒ d } t  j j | ƒ } d } t | | | | f ƒ ‚ n  |  j | ƒ Vq t  j j | ƒ r t  j j t  j j | d ƒ ƒ sÄq n  d } d } t | | ƒ r'|  j | ƒ } |  j	 | ƒ } t | d d ƒ } |  j | d t ƒ} n  | d k rl| d k	 rG| Vn  xd |  j | | ƒ D] } | VqZWq±y | |  | | ƒ VWq±t k
 r­} t | j | |  j ƒ Vq±Xq q Wd S(   s/   Used by discovery. Yields test suites it loads.R[   i    sW   %r module incorrectly imported from %r. Expected %r. Is this module globally installed?s   __init__.pyR%   R.   N(   RR   t   listdirRS   R7   RX   t   VALID_MODULE_NAMEt   matchRv   Rt   Ru   R   R
   RT   R'   Rl   Ri   RZ   Rh   R   R2   RW   R*   R   RO   R_   R+   R   R,   (   R   R`   Ra   t   pathsRS   Rk   R	   R-   t   mod_filet   realpatht   fullpath_noextt
   module_dirt   mod_namet   expected_dirt   msgR%   R/   t   packageR   R1   (    (    s%   /usr/lib/python2.7/unittest/loader.pyR_   ï   sV    "!N(   R,   t
   __module__t   __doc__RI   t   cmpRK   R   R   R
   R*   RP   R$   RQ   R2   R@   RC   R   Rg   R\   Rt   Ru   Rv   R_   (    (    (    s%   /usr/lib/python2.7/unittest/loader.pyR   &   s    		1	@		
		c         C   s1   t  ƒ  } | | _ |  | _ | r- | | _ n  | S(   N(   R   RK   RI   R
   (   RF   t	   sortUsingR
   t   loader(    (    s%   /usr/lib/python2.7/unittest/loader.pyt   _makeLoader+  s    			c         C   s   t  | | ƒ j |  ƒ S(   N(   Rˆ   R   (   R!   RF   R†   (    (    s%   /usr/lib/python2.7/unittest/loader.pyR   3  s    R   c         C   s   t  | | | ƒ j |  ƒ S(   N(   Rˆ   R$   (   R!   RF   R†   R
   (    (    s%   /usr/lib/python2.7/unittest/loader.pyt	   makeSuite6  s    c         C   s   t  | | | ƒ j |  ƒ S(   N(   Rˆ   R2   (   R-   RF   R†   R
   (    (    s%   /usr/lib/python2.7/unittest/loader.pyt   findTestCases:  s    (   R„   RR   t   reRU   R   R8   t	   functoolsR    RM   R   t    R   R   RQ   t
   __unittestt   compilet
   IGNORECASERx   R   R   R   t   objectR   t   defaultTestLoaderR*   Rˆ   R…   R   R   R‰   RŠ   (    (    (    s%   /usr/lib/python2.7/unittest/loader.pyt   <module>   s,   			ÿ 	