ó
%‘Uc           @   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 Z d d l Z d d l m Z d d l	 m
 Z
 m Z m Z d d l m Z y d d l m Z Wn! e k
 rÍ d d l m Z n Xe Z d „  Z e j d e j ƒ Z d	 e
 j f d
 „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z d „  Z d e j f d „  ƒ  YZ e ƒ  Z  e! d „ Z" e j# d „ Z$ d e j# e j% d „ Z& d e j# e j% d „ Z' d S(   s   Loading unittests.iÿÿÿÿN(   t   fnmatch(   t   caset   suitet   util(   t
   raise_from(   t   relpathc            s    d t  f ‡  f d †  ƒ  Y} | S(   s,   Convert a cmp= function into a key= functiont   Kc              s    e  Z d  „  Z ‡  f d †  Z RS(   c         S   s   | |  _  d  S(   N(   t   obj(   t   selfR   (    (    s/   lib/python2.7/site-packages/unittest2/loader.pyt   __init__   s    c            s   ˆ  |  j  | j  ƒ d k S(   Niÿÿÿÿ(   R   (   R   t   other(   t   mycmp(    s/   lib/python2.7/site-packages/unittest2/loader.pyt   __lt__   s    (   t   __name__t
   __module__R	   R   (    (   R   (    s/   lib/python2.7/site-packages/unittest2/loader.pyR      s   	(   t   object(   R   R   (    (   R   s/   lib/python2.7/site-packages/unittest2/loader.pyt	   _CmpToKey   s    s   [_a-z]\w*\.py$t   _FailedTestc           B   s    e  Z d Z d  „  Z d „  Z RS(   c         C   s#   | |  _  t t |  ƒ j | ƒ d  S(   N(   t
   _exceptiont   superR   R	   (   R   t   method_namet	   exception(    (    s/   lib/python2.7/site-packages/unittest2/loader.pyR	   +   s    	c            s8   | ˆ  j  k r% t t ˆ  ƒ j | ƒ S‡  f d †  } | S(   Nc              s   ˆ  j  ‚ d  S(   N(   R   (    (   R   (    s/   lib/python2.7/site-packages/unittest2/loader.pyt   testFailure2   s    (   t   _testMethodNameR   R   t   __getattr__(   R   t   nameR   (    (   R   s/   lib/python2.7/site-packages/unittest2/loader.pyR   /   s    N(   R   R   t   NoneR   R	   R   (    (    (    s/   lib/python2.7/site-packages/unittest2/loader.pyR   (   s   	c         C   s/   d |  t  j ƒ  f } t |  t | ƒ | | ƒ S(   Ns#   Failed to import test module: %s
%s(   t	   tracebackt
   format_exct   _make_failed_testt   ImportError(   R   t
   suiteClasst   message(    (    s/   lib/python2.7/site-packages/unittest2/loader.pyt   _make_failed_import_test7   s    c         C   s&   d t  j ƒ  f } t |  | | | ƒ S(   Ns   Failed to call load_tests:
%s(   R   R   R   (   R   R   R   R    (    (    s/   lib/python2.7/site-packages/unittest2/loader.pyt   _make_failed_load_tests<   s    c         C   s"   t  |  | ƒ } | | f ƒ | f S(   N(   R   (   t
   methodnameR   R   R    t   test(    (    s/   lib/python2.7/site-packages/unittest2/loader.pyR   A   s    c         C   sV   t  j t | ƒ ƒ d „  ƒ } i | |  6} t d t  j f | ƒ } | | |  ƒ f ƒ S(   Nc         S   s   d  S(   N(    (   R   (    (    s/   lib/python2.7/site-packages/unittest2/loader.pyt   testSkippedG   s    t   ModuleSkipped(   R   t   skipt   strt   typet   TestCase(   R#   R   R   R%   t   attrst	   TestClass(    (    s/   lib/python2.7/site-packages/unittest2/loader.pyt   _make_skipped_testF   s    c         C   s1   |  j  ƒ  j d ƒ r |  d  St j j |  ƒ d S(   Ns	   $py.classi÷ÿÿÿi    (   t   lowert   endswitht   ost   patht   splitext(   R1   (    (    s/   lib/python2.7/site-packages/unittest2/loader.pyt   _jython_aware_splitextN   s    t
   TestLoaderc           B   s¿   e  Z d  Z d Z e e j ƒ Z e j	 Z
 d Z d „  Z d „  Z d d d „ Z d d „ Z d d „ Z d „  Z d d d	 „ Z d
 „  Z d „  Z d „  Z d „  Z e d „ Z e d „ Z RS(   s   
    This class is responsible for loading tests according to various criteria
    and returning them wrapped in a TestSuite
    R$   c         C   s,   t  t |  ƒ j ƒ  g  |  _ t ƒ  |  _ d  S(   N(   R   R4   R	   t   errorst   sett   _loading_packages(   R   (    (    s/   lib/python2.7/site-packages/unittest2/loader.pyR	   _   s    	c         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 tests 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/   lib/python2.7/site-packages/unittest2/loader.pyt   loadTestsFromTestCasef   s    c         O   s”  | d k	 r t j d t ƒ n  t | ƒ d k rY t | ƒ d } t d j | ƒ ƒ ‚ n  t | ƒ d k r“ t | ƒ d } t d j | ƒ ƒ ‚ n  g  } x] t | ƒ D]O } t	 | | ƒ }	 t
 |	 t ƒ r¦ t |	 t j ƒ r¦ | j |  j |	 ƒ ƒ q¦ q¦ Wt	 | d d ƒ }
 |  j | ƒ } |
 d k	 ry |
 |  | | ƒ SWqt k
 rŒt j ƒ  d } t | j | |  j ƒ \ } } |  j j | ƒ | SXn  | S(   s?   Return a suite of all tests cases contained in the given modules(   use_load_tests is deprecated and ignoredi    i   sD   loadTestsFromModule() takes 1 positional argument but {0} were givens>   loadTestsFromModule() got an unexpected keyword argument '{0}'t
   load_testsN(   R   t   warningst   warnt   DeprecationWarningt   lenR;   t   formatt   sortedt   dirt   getattrt
   isinstanceR)   R9   t   unittestR*   t   appendRB   R   t	   Exceptiont   syst   exc_infoR"   R   R5   (   R   t   modulet   use_load_testst   patternt   argst   kwst	   complaintt   testsR   R   RC   t   et
   error_caset   error_message(    (    s/   lib/python2.7/site-packages/unittest2/loader.pyt   loadTestsFromModulet   s4    	
!c         C   s4  | j  d ƒ } d
 \ } } | d	 k rº | } x| | r¬ y  d j | ƒ } t | ƒ } PWq1 t k
 r¨ | j ƒ  } t | |  j ƒ \ } } | s© |  j j	 | ƒ | Sq1 Xq1 W| d } n  | }	 xµ | D]­ }
 y |	 t
 |	 |
 ƒ } }	 WqÇ t k
 rs} t
 |	 d d	 ƒ d	 k	 r1| d	 k	 r1|  j j	 | ƒ | St |
 | |  j d t j ƒ  f ƒ \ } } |  j j	 | ƒ | SqÇ XqÇ Wt |	 t j ƒ r—|  j |	 ƒ St |	 t ƒ rÅt |	 t j ƒ rÅ|  j |	 ƒ St t d ƒ r-t |	 t j ƒ r-t | t ƒ r-t | t j ƒ r-| d } | | ƒ } |  j | g ƒ St |	 t j ƒ r¤t | t ƒ r¤t | t j ƒ r¤| d } | | ƒ } t t
 | | ƒ t j ƒ sº|  j | g ƒ Sn t |	 t j ƒ rº|	 St |	 ƒ r |	 ƒ  } t | t j ƒ rå| St | t j ƒ r|  j | g ƒ St d |	 | f ƒ ‚ n t d |	 ƒ ‚ d	 S(   sT  Return a suite of all tests 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   t   __path__s   Failed to access attribute:
%st   UnboundMethodTypeiÿÿÿÿs"   calling %s returned %s, not a tests$   don't know how to make test from: %sN(   NN(   t   splitR   t   joint
   __import__R   t   popR!   R   R5   RN   RK   t   AttributeErrorR   R   R   RL   t   typest
   ModuleTypeR\   R)   R9   RM   R*   RB   R=   R_   R   t   FunctionTypeR:   t   callableR;   (   R   R   RR   t   partsRZ   R[   t
   parts_copyt   module_namet   next_attributeR   t   partt   parentRY   t   instR$   (    (    s/   lib/python2.7/site-packages/unittest2/loader.pyt   loadTestsFromNameœ   sz    		!

	c         C   s2   g  | D] } |  j  | | ƒ ^ q } |  j | ƒ S(   s‚   Return a suite of all tests cases found using the given sequence
        of string specifiers. See 'loadTestsFromName()'.
        (   Rp   R   (   R   t   namesRR   R   t   suites(    (    s/   lib/python2.7/site-packages/unittest2/loader.pyt   loadTestsFromNamesñ   s    %c         C   sV   | |  j  d „ } t t | t | ƒ ƒ ƒ } |  j rR | 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(   Nt   __call__(   t
   startswithR=   RK   (   t   attrnameR?   t   prefix(    (    s/   lib/python2.7/site-packages/unittest2/loader.pyt   isTestMethodû   s    t   key(   t   testMethodPrefixt   listt   filterRJ   t   sortTestMethodsUsingt   sortR   (   R   R?   Rx   t   testFnNames(    (    s/   lib/python2.7/site-packages/unittest2/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  } g  } 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 } n´Xt j | } | j d ƒ d }	 y% t j j t j j | j ƒ ƒ } Wn't k
 r”y | j }
 Wn t k
 r¡d }
 n X|
 rM|
 j d k rM|
 j d k	 r‘t } x{ | j D]m } | rù| j | ƒ rùqÖn  | j | j j d t j j ƒ ƒ d |  _ | j |  j | | d t ƒƒ qÖWq‘q•| j t j k rut t d ƒ d ƒ q•t t d j  | ƒ ƒ d ƒ n X| rÙ| sÆ|  j! |	 ƒ |  _ t j j" | ƒ qÙt j j" | ƒ n  | ròt d | ƒ ‚ n  | st# |  j | | ƒ ƒ } n  |  j$ | ƒ S(	   s%  Find and return all test modules from the specified start
        directory, recursing into subdirectories to find them and return all
        tests found within 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) unless
        the package has already had load_tests called from the same discovery
        invocation, in which case the package module object is not scanned for
        tests - this ensures that when a package uses discover to further
        discover child tests that infinite recursion does not happen.

        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().

        Paths are sorted before being imported to ensure reproducible execution
        order even on filesystems with non-alphabetical ordering like ext3/4.
        i    s   __init__.pyR]   t	   namespaces2   Can not use builtin modules as dotted module namess%   don't know how to discover from {0!r}s%   Start directory is not importable: %rN(%   t   FalseR   t   _top_level_dirt   TrueR0   R1   t   abspathRP   t   insertt   isdirt   isfileRa   Rb   R   t   modulesR`   t   dirnamet   __file__Rd   t   __spec__t   loadert   submodule_search_locationsR^   Ru   R   t   replacet   sept   extendt   _find_testst   builtin_module_namesR   R;   RH   t    _get_directory_containing_modulet   removeR{   R   (   R   t	   start_dirRT   t   top_level_dirt   set_implicit_topt   is_not_importablet   is_namespaceRX   t
   the_modulet   top_partt   specR1   (    (    s/   lib/python2.7/site-packages/unittest2/loader.pyt   discover  sv    		(
	

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(
   RP   Rˆ   R0   R1   R„   RŠ   t   basenameR.   Ru   R‰   (   R   Rk   RR   t	   full_path(    (    s/   lib/python2.7/site-packages/unittest2/loader.pyR“   r  s
    !c         C   s”   | |  j  k r d St t j j | ƒ ƒ } t | |  j  ƒ } t j j | ƒ s\ t d ƒ ‚ | j d ƒ sx t d ƒ ‚ | j	 t j j
 d ƒ } | S(   NR]   s   Path must be within the projects   ..(   R‚   R3   R0   R1   t   normpathR   t   isabst   AssertionErrorRu   RŽ   R   (   R   R1   t   _relpathR   (    (    s/   lib/python2.7/site-packages/unittest2/loader.pyt   _get_name_from_path~  s    c         C   s   t  | ƒ t j | S(   N(   Rb   RP   Rˆ   (   R   R   (    (    s/   lib/python2.7/site-packages/unittest2/loader.pyt   _get_module_from_nameŠ  s    
c         C   s   t  | | ƒ S(   N(   R    (   R   R1   RŸ   RT   (    (    s/   lib/python2.7/site-packages/unittest2/loader.pyt   _match_pathŽ  s    c         c   s?  |  j  | ƒ } | d k rf | |  j k rf |  j | | | ƒ \ } } | d k	 rY | Vn  | sf d Sn  t t j | ƒ ƒ } x½ | D]µ } t j j | | ƒ }	 |  j |	 | | ƒ \ } } | d k	 rÌ | Vn  | r‚ |  j  |	 ƒ } |  j j	 | ƒ z/ |  j
 |	 | | ƒ }
 x |
 D] } | VqWWd |  j j | ƒ Xq‚ q‚ Wd S(   s/   Used by discovery. Yields test suites it loads.R]   N(   R¤   R7   t   _find_test_pathR   RI   R0   t   listdirR1   Ra   t   addR‘   t   discard(   R   R•   RT   R€   R   RX   t   should_recurset   pathsR1   RŸ   t
   path_testsR$   (    (    s/   lib/python2.7/site-packages/unittest2/loader.pyR‘   ’  s.    c         C   s  t  j j | ƒ } t  j j | ƒ rÂt j | ƒ s= d t f S|  j | | | ƒ s\ d t f S|  j	 | ƒ } y |  j
 | ƒ } Wna t j k
 r¬ } t | | |  j ƒ t f St | |  j ƒ \ } }	 |  j j |	 ƒ | t f SXt  j j t | d | ƒ ƒ }
 t t  j j |
 ƒ ƒ } t t  j j | ƒ ƒ } | j ƒ  | j ƒ  k r¦t  j j | ƒ } t t  j j | ƒ ƒ } t  j j | ƒ } d } t | | | | f ƒ ‚ n  |  j | d | ƒt f SnIt  j j | ƒ r| rt  j j t  j j | d ƒ ƒ rd t f Sd } d } |  j	 | ƒ } y |  j
 | ƒ } Wna t j k
 rc} t | | |  j ƒ t f St | |  j ƒ \ } }	 |  j j |	 ƒ | t f SXt | d d ƒ } |  j j | ƒ z9 |  j | d | ƒ} | d k	 ré| t f S| t f SWd |  j j | ƒ Xn  d S(   sÉ   Used by discovery.

        Loads tests from a single file, or a directories' __init__.py when
        passed the directory.

        Returns a tuple (None_or_tests_from_file, should_recurse).
        RŠ   sW   %r module incorrectly imported from %r. Expected %r. Is this module globally installed?RT   s   __init__.pyRC   N(    R0   R1   Rž   R‡   t   VALID_MODULE_NAMEt   matchR   R   R¦   R¤   R¥   R   t   SkipTestR-   R   R!   R5   RN   R„   RK   R3   t   realpathR.   R‰   R   R\   R†   Ra   R7   R©   Rƒ   Rª   (   R   RŸ   RT   R€   Rž   R   RR   RY   RZ   R[   t   mod_fileR±   t   fullpath_noextt
   module_dirt   mod_namet   expected_dirt   msgRC   RX   t   package(    (    s/   lib/python2.7/site-packages/unittest2/loader.pyR§   ¶  sj    

	"

N(   R   R   t   __doc__Rz   t   staticmethodR   t   three_way_cmpR}   R   R:   R   R   R‚   R	   RB   R\   Rp   Rs   R<   R   R“   R¤   R¥   R¦   R   R‘   R§   (    (    (    s/   lib/python2.7/site-packages/unittest2/loader.pyR4   U   s$   			(U	n				$c         C   s1   t  ƒ  } | | _ |  | _ | r- | | _ n  | S(   N(   R4   R}   Rz   R   (   Rw   t	   sortUsingR   RŒ   (    (    s/   lib/python2.7/site-packages/unittest2/loader.pyt   _makeLoader  s    			c         C   s   t  | | ƒ j |  ƒ S(   N(   R½   R<   (   R?   Rw   R¼   (    (    s/   lib/python2.7/site-packages/unittest2/loader.pyR<     s    R$   c         C   s   t  | | | ƒ j |  ƒ S(   N(   R½   RB   (   R?   Rw   R¼   R   (    (    s/   lib/python2.7/site-packages/unittest2/loader.pyt	   makeSuite  s    c         C   s   t  | | | ƒ j |  ƒ S(   N(   R½   R\   (   RR   Rw   R¼   R   (    (    s/   lib/python2.7/site-packages/unittest2/loader.pyt   findTestCases  s    ((   R¹   R0   t   reRP   R   Re   RM   RD   R    t	   unittest2R   R   R   t   unittest2.compatibilityR   t   os.pathR   R   Rƒ   t
   __unittestR   t   compilet
   IGNORECASER®   R*   R   R!   R"   R   R-   R3   R4   t   defaultTestLoaderR   R½   R»   R<   R:   R¾   R¿   (    (    (    s/   lib/python2.7/site-packages/unittest2/loader.pyt   <module>   s@   						ÿ ¬			