ó
d¦Uc           @   sÈ  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 e j d k ró e j d	  d	 d
 f k  rÚ d d l Z e j d ƒ d d l m Z n d e f d „  ƒ  YZ n  e j e ƒ Z e ƒ  Z d „  Z d e f d „  ƒ  YZ d e j f d „  ƒ  YZ d e f d „  ƒ  YZ  d e f d „  ƒ  YZ! d e f d „  ƒ  YZ" d e j f d „  ƒ  YZ# d f  d „  ƒ  YZ$ d f  d „  ƒ  YZ% d S(    sâ   
Test Suites
-----------

Provides a LazySuite, which is a suite whose test list is a generator
function, and ContextSuite,which can run fixtures (setup/teardown
functions or methods) for the context that contains its tests.

iÿÿÿÿ(   t
   generatorsN(   t   Test(   t   Config(   t   ResultProxyFactory(   t   isclasst   resolve_namet   try_runt   clii   i   t
   IronPython(   t   StringExceptionR	   c           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s)   lib/python2.7/site-packages/nose/suite.pyR	      s   c         C   s   d |  j  |  j f S(   Ns   %s.%s(   R   R
   (   t   cls(    (    s)   lib/python2.7/site-packages/nose/suite.pyt	   _strclass$   s    t   MixedContextErrorc           B   s   e  Z d  Z RS(   sQ   Error raised when a context suite sees tests from more than
    one context.
    (   R
   R   t   __doc__(    (    (    s)   lib/python2.7/site-packages/nose/suite.pyR   '   s   t	   LazySuitec           B   s}   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z e Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z e e e d d
 ƒ Z RS(   s:   A suite that may use a generator as its list of tests
    c         C   s$   t  t |  ƒ j ƒ  |  j | ƒ d S(   sF   Initialize the suite. tests may be an iterable or a generator
        N(   t   superR   t   __init__t
   _set_tests(   t   selft   tests(    (    s)   lib/python2.7/site-packages/nose/suite.pyR   1   s    c         C   s   t  |  j ƒ S(   N(   t   itert   _tests(   R   (    (    s)   lib/python2.7/site-packages/nose/suite.pyt   __iter__7   s    c         C   s   d t  |  j ƒ t |  ƒ f S(   Ns   <%s tests=generator (%s)>(   R   t	   __class__t   id(   R   (    (    s)   lib/python2.7/site-packages/nose/suite.pyt   __repr__:   s    c         C   s   t  j |  ƒ S(   N(   t   objectt   __hash__(   R   (    (    s)   lib/python2.7/site-packages/nose/suite.pyR   >   s    c         C   s   |  j  j | ƒ d  S(   N(   t	   _precachet   append(   R   t   test(    (    s)   lib/python2.7/site-packages/nose/suite.pyt   addTestC   s    c         C   s/   x( |  j  D] } | j r Pn  | | ƒ q
 W| S(   N(   R   t
   shouldStop(   R   t   resultR    (    (    s)   lib/python2.7/site-packages/nose/suite.pyt   runG   s
    	c         C   s   t  j d t |  ƒ ƒ |  j r# t S|  j d  k r6 t Sy3 |  j j ƒ  } | d  k	 rh |  j j	 | ƒ t SWn t
 k
 r| n Xt S(   Ns   tests in %s?(   t   logt   debugR   R   t   Truet   test_generatort   Nonet   Falset   nextR   t   StopIteration(   R   R    (    (    s)   lib/python2.7/site-packages/nose/suite.pyt   __nonzero__N   s    	c         c   s\   t  j d |  j ƒ x |  j D] } | Vq W|  j d  k r? d  Sx |  j D] } | VqI Wd  S(   Ns   precache is %s(   R%   R&   R   R(   R)   (   R   R    (    (    s)   lib/python2.7/site-packages/nose/suite.pyt
   _get_tests]   s    	c         C   sy   g  |  _  t | t j ƒ } t | ƒ r= | r= | ƒ  |  _ n8 | r_ |  j | g ƒ d  |  _ n |  j | ƒ d  |  _ d  S(   N(   R   t
   isinstancet   unittestt	   TestSuitet   callableR(   t   addTestsR)   (   R   R   t   is_suite(    (    s)   lib/python2.7/site-packages/nose/suite.pyR   f   s    	sb   Access the tests in this suite. Access is through a generator, so iteration may not be repeatable.(    N(   R
   R   R   R   R   R   R   t   __str__R!   R$   R-   R.   R   t   propertyR)   R   (    (    (    s)   lib/python2.7/site-packages/nose/suite.pyR   .   s   									t   ContextSuitec           B   s  e  Z d  Z e j j Z e Z e Z d. Z	 d/ Z
 d0 Z d1 Z d2 Z d3 Z d4 d5 d5 d5 d5 e d „ Z d „  Z e Z d „  Z d  „  Z d! „  Z d" „  Z d# „  Z d$ „  Z d5 d% „ Z d& „  Z d' „  Z d( „  Z d) „  Z d* „  Z d+ „  Z  d, „  Z! e" e! e# j$ d5 d- ƒ Z% RS(6   s4  A suite with context.

    A ContextSuite executes fixtures (setup and teardown functions or
    methods) for the context containing its tests.

    The context may be explicitly passed. If it is not, a context (or
    nested set of contexts) will be constructed by examining the tests
    in the suite.
    t   setup_classt	   setup_allt
   setupClasst   setupAllt
   setUpClasst   setUpAllt   teardown_classt   teardown_allt   teardownClasst   teardownAllt   tearDownClasst   tearDownAllt   setup_modulet   setupModulet   setUpModulet   setupt   setUpt   teardown_modulet   teardownModulet   tearDownModulet   teardownt   tearDownt   setup_packaget   setupPackaget   setUpPackaget   teardown_packaget   teardownPackaget   tearDownPackagec         C   s   t  j d | | t |  ƒ ƒ | |  _ | |  _ | d  k rF t ƒ  } n  | |  _ | |  _ t	 |  _
 | |  _ d  |  _ t t |  ƒ j | ƒ d  S(   Ns   Context suite for %s (%s) (%s)(   R%   R&   R   t   contextt   factoryR)   R   t   configt   resultProxyR*   t   has_runt	   can_splitt   error_contextR   R7   R   (   R   R   RT   RU   RV   RW   RY   (    (    s)   lib/python2.7/site-packages/nose/suite.pyR   ’   s    							c         C   s)   d t  |  j ƒ t |  j d |  j ƒ f S(   Ns   <%s context=%s>R
   (   R   R   t   getattrRT   (   R   (    (    s)   lib/python2.7/site-packages/nose/suite.pyR       s    c         C   s.   |  j  r  d t |  ƒ |  j  f St |  ƒ Sd  S(   Ns   %s:%s(   RZ   t   repr(   R   (    (    s)   lib/python2.7/site-packages/nose/suite.pyR   ¦   s    	c         C   s   t  j |  ƒ S(   N(   R   R   (   R   (    (    s)   lib/python2.7/site-packages/nose/suite.pyR   ¬   s    c         O   s   |  j  | | Ž  S(   N(   R$   (   R   t   argt   kw(    (    s)   lib/python2.7/site-packages/nose/suite.pyt   __call__°   s    c         C   s
   t  j ƒ  S(   s.   Hook for replacing error tuple output
        (   t   syst   exc_info(   R   (    (    s)   lib/python2.7/site-packages/nose/suite.pyRa   ³   s    c         C   sY   |  j  ƒ  } t j d k rU t | d t ƒ rU t | d ƒ | d | d f } qU n  | S(   s:   Bottleneck to fix up IronPython string exceptions
        R   i    i   i   (   Ra   R`   t   platformR/   R	   t   str(   R   t   e(    (    s)   lib/python2.7/site-packages/nose/suite.pyt	   _exc_info¸   s
    'c         C   s3  t  j d t |  ƒ |  |  j ƒ |  j rD |  j | |  ƒ | } } n | | } } y |  j ƒ  Wn: t k
 ru ‚  n' d |  _ | j |  |  j	 ƒ  ƒ d SXz< x5 |  j D]* } | j
 rÉ t  j d ƒ Pn  | | ƒ q© WWd t |  _ y |  j ƒ  Wn9 t k
 r‚  n& d |  _ | j |  |  j	 ƒ  ƒ n XXd S(   s5   Run tests in suite inside of suite fixtures.
        s#   suite %s (%s) run called, tests: %sRG   Nt   stoppingRL   (   R%   R&   R   R   RW   RH   t   KeyboardInterruptRZ   t   addErrorRe   R"   R'   RX   RM   (   R   R#   t   origR    (    (    s)   lib/python2.7/site-packages/nose/suite.pyR$   Å   s4    					c         C   s‡   |  j  } | d  k r t S|  j | d | ƒr2 t S|  j } | rƒ | j  j |  g  ƒ } x* | D] } |  j | d | ƒr] t Sq] Wn  t S(   Nt   ctx_callback(   RT   R)   R*   t   implementsAnyFixtureR'   RU   t   get(   R   Rj   RT   RU   t	   ancestorst   ancestor(    (    s)   lib/python2.7/site-packages/nose/suite.pyt   hasFixturesë   s    		c         C   s¢   t  | ƒ r |  j |  j } n6 |  j |  j } t | d ƒ rU | |  j |  j 7} n  t } x' | D] } t | | ƒ rb t	 } Pqb qb W| d  k r• | S| | | ƒ S(   Nt   __path__(   R   t
   classSetupt   classTeardownt   moduleSetupt   moduleTeardownt   hasattrt   packageSetupt   packageTeardownR*   R'   R)   (   R   RT   Rj   t   namest   fixtt   m(    (    s)   lib/python2.7/site-packages/nose/suite.pyRk   û   s    c         C   sA  t  j d t |  ƒ |  j ƒ |  s< t  j d t |  ƒ ƒ d  S|  j r_ t  j d t |  ƒ ƒ d  S|  j } | d  k rx d  S|  j } | r| j j |  g  ƒ } xX | r÷ | j	 ƒ  } t  j d | ƒ | | j k r× q  n  t  j d | ƒ |  j
 | ƒ q  W| | j k r'|  j
 | ƒ q'n |  j
 | ƒ t |  _ t  j d ƒ d  S(   Ns    suite %s setUp called, tests: %ss   suite %s has no testss   suite %s already set ups   ancestor %s may need setups   ancestor %s does need setups   completed suite setup(   R%   R&   R   R   t	   was_setupRT   R)   RU   Rl   t   popt   setupContextR'   (   R   RT   RU   Rm   Rn   (    (    s)   lib/python2.7/site-packages/nose/suite.pyRH     s2    					c         C   s©   |  j  j j | ƒ t j d |  | ƒ |  j rX | |  j j k rE d  S|  |  j j | <n  t | ƒ rp |  j } n( |  j	 } t
 | d ƒ r˜ |  j | } n  t | | ƒ d  S(   Ns   %s setup context %sRp   (   RV   t   pluginst   startContextR%   R&   RU   R{   R   Rq   Rs   Ru   Rv   R   (   R   RT   Rx   (    (    s)   lib/python2.7/site-packages/nose/suite.pyR}   ,  s    		c         C   s   |  j  d  k r d Sd |  j  S(   Ns
   test suites   test suite for %s(   RT   R)   (   R   (    (    s)   lib/python2.7/site-packages/nose/suite.pyt   shortDescription=  s    c         C   sV  t  j d ƒ |  j s  |  j rA t  j d |  j |  j f ƒ d  St |  _ |  j } | d  k rp t  j d ƒ d  S|  j } | rE| j j |  g  ƒ | g } x´ | D]œ } t  j d | ƒ | | j k rÝ t  j d | ƒ q¢ n  | | j k rt  j d | ƒ q¢ n  | j | } t  j d | | ƒ | |  k r¢ |  j	 | ƒ q¢ q¢ Wn |  j	 | ƒ d  S(   Ns   context teardowns6   No reason to teardown (was_setup? %s was_torndown? %s)s   No context to tear downs   ancestor %s may need teardowns   ancestor %s was not setups   ancestor %s already torn downs   %s setup ancestor %s(
   R%   R&   R{   t   was_torndownR'   RT   R)   RU   Rl   t   teardownContext(   R   RT   RU   Rm   Rn   RG   (    (    s)   lib/python2.7/site-packages/nose/suite.pyRM   B  s6    			c         C   s©   t  j d |  | ƒ |  j rE | |  j j k r2 d  S|  |  j j | <n  t | ƒ r] |  j } n( |  j } t | d ƒ r… |  j | } n  t	 | | ƒ |  j
 j j | ƒ d  S(   Ns   %s teardown context %sRp   (   R%   R&   RU   R   R   Rr   Rt   Ru   Rw   R   RV   R~   t   stopContext(   R   RT   Rx   (    (    s)   lib/python2.7/site-packages/nose/suite.pyR‚   c  s    		c         c   sa   xZ |  j  ƒ  D]L } t | t ƒ s4 t | t j ƒ r< | Vq t | d |  j d |  j ƒVq Wd  S(   NRV   RW   (   R.   R/   R   R0   R1   RV   RW   (   R   R    (    (    s)   lib/python2.7/site-packages/nose/suite.pyt   _get_wrapped_testss  s    !		sO   Access the tests in this suite. Tests are returned inside of a context wrapper.(   R8   R9   R:   R;   R<   R=   (   R>   R?   R@   RA   RB   RC   (   RD   RE   RF   RG   RH   (   RI   RJ   RK   RL   RM   (   RN   RO   RP   (   RQ   RR   RS   (    N(&   R
   R   R   R0   t   TestCaset   failureExceptionR*   R{   R   Rq   Rr   Rs   Rt   Rv   Rw   R)   R'   R   R   R5   R   R   R_   Ra   Re   R$   Ro   Rk   RH   R}   R€   RM   R‚   R„   R6   R   R   R   (    (    (    s)   lib/python2.7/site-packages/nose/suite.pyR7   y   sF   	     								&		 			!			t   ContextSuiteFactoryc           B   s\   e  Z d  Z e Z d d e d „ Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z RS(	   sC  Factory for ContextSuites. Called with a collection of tests,
    the factory decides on a hierarchy of contexts by introspecting
    the collection or the tests themselves to find the objects
    containing the test objects. It always returns one suite, but that
    suite may consist of a hierarchy of nested suites.
    c         C   sˆ   | d  k r t ƒ  } n  | |  _ | d  k	 r9 | |  _ n  | t k rW t d | ƒ } n  | |  _ i  |  _ i  |  _ i  |  _	 i  |  _
 d  S(   NRV   (   R)   R   RV   t
   suiteClasst   _defR   RW   t   suitesRT   R{   R   (   R   RV   Rˆ   RW   (    (    s)   lib/python2.7/site-packages/nose/suite.pyR   ‰  s    					c         K   s²   t  j d | ƒ | j d t | d d ƒ ƒ } t  j d | | ƒ | d k rŸ |  j | ƒ } y |  j | ƒ } WqŸ t k
 r› |  j |  j	 | ƒ d |  SXn  |  j | | |  S(   sÄ  Return ``ContextSuite`` for tests. ``tests`` may either
        be a callable (in which case the resulting ContextSuite will
        have no parent context and be evaluated lazily) or an
        iterable. In that case the tests will wrapped in
        nose.case.Test, be examined and the context of each found and a
        suite of suites returned, organized into a stack with the
        outermost suites belonging to the outermost contexts.
        s   Create suite for %sRT   s   tests %s context %sN(
   R%   R&   R|   R[   R)   t	   wrapTestst   findContextR   t	   makeSuitet   mixedSuites(   R   R   R^   RT   (    (    s)   lib/python2.7/site-packages/nose/suite.pyR_   ™  s    	 c         c   s÷   t  j d | ƒ | d k r  d St | d ƒ r; | j } n t | d ƒ rY | j j } n  t | d ƒ r} | j j d ƒ } n8 t | d ƒ r¥ | j	 j d ƒ d  } n t
 d	 | ƒ ‚ x; | rò t  j d
 | | ƒ t d j | ƒ ƒ V| j ƒ  q¸ Wd S(   sØ   Return the ancestry of the context (that is, all of the
        packages and modules containing the context), in order of
        descent with the outermost ancestor last.
        This method is a generator.
        s   get ancestry %sNt   im_classt   __self__R   t   .R
   iÿÿÿÿs   %s has no ancestors?s    %s ancestors %s(   R%   R&   R)   Ru   R   R   R   R   t   splitR
   t	   TypeErrorR   t   joinR|   (   R   RT   Rm   (    (    s)   lib/python2.7/site-packages/nose/suite.pyt   ancestry­  s     	c         C   s›   t  | ƒ s t | t j ƒ r" d  Sd  } xl | D]d } t | d d  ƒ } | d  k rY q/ n  | d  k rn | } q/ | | k r/ t d | | f ƒ ‚ q/ q/ W| S(   NRT   s5   Tests with different contexts in same suite! %s != %s(   R2   R/   R0   R1   R)   R[   R   (   R   R   RT   R    t   ctx(    (    s)   lib/python2.7/site-packages/nose/suite.pyRŒ   È  s    	c         K   sú   |  j  | d | d |  j d |  d |  j | } | d  k	 rö |  j j | g  ƒ j | ƒ |  j j | g  ƒ j | ƒ t j	 d | t
 | d d  ƒ ƒ x` |  j | ƒ D]L } |  j j | g  ƒ j | ƒ |  j | j | ƒ t j	 d | | j ƒ q£ Wn  | S(   NRT   RV   RU   RW   s   suite %s has context %sR
   s   suite %s has ancestor %s(   Rˆ   RV   RW   R)   RŠ   t
   setdefaultR   RT   R%   R&   R[   R•   R
   (   R   R   RT   R^   t   suiteRn   (    (    s)   lib/python2.7/site-packages/nose/suite.pyR   Ù  s    c         C   sŒ  | s
 g  S| j  d ƒ } | s& | g S| } | } t | d d ƒ } | d k	 r| g g  |  j | ƒ D] } | ^ qg } x| D]ù } | g }	 g  }
 x· | D]¯ } t } t | d d ƒ } | d k rÚ |
 j | ƒ q n  | | k rù |	 j | ƒ q n  x: |  j | ƒ D]) } | | k r	|	 j | ƒ t } Pq	q	W| s |
 j | ƒ q q W|	 rk|  j |	 | ƒ } n  |  j |
 ƒ } q Wn  | g | S(   sc  The complex case where there are tests that don't all share
        the same context. Groups tests into suites with common ancestors,
        according to the following (essentially tail-recursive) procedure:

        Starting with the context of the first test, if it is not
        None, look for tests in the remaining tests that share that
        ancestor. If any are found, group into a suite with that
        ancestor as the context, and replace the current suite with
        that suite. Continue this process for each ancestor of the
        first test, until all ancestors have been processed. At this
        point if any tests remain, recurse with those tests as the
        input, returning a list of the common suite (which may be the
        suite or test we started with, if no common tests were found)
        plus the results of recursion.
        i    RT   N(	   R|   R[   R)   R•   R*   R   R'   R   RŽ   (   R   R   t   headR˜   t   tailRT   t   aRm   Rn   t   commont   remainR    t   found_commont   test_ctxt   test_ancestor(    (    s)   lib/python2.7/site-packages/nose/suite.pyRŽ   è  sB    )	c         C   sñ   t  j d | ƒ t | ƒ s. t | t j ƒ r? t  j d ƒ | Sg  } x¥ | D] } t  j d | ƒ t | t ƒ sƒ t | t j ƒ r“ | j | ƒ qL t | t ƒ rÄ | j |  j	 | d | j
 ƒƒ qL | j t | d |  j d |  j ƒƒ qL W| S(   Ns   wrap %ss   I won't wraps   wrapping %sRT   RV   RW   (   R%   R&   R2   R/   R0   R1   R   R   t   ContextListR   RT   RV   RW   (   R   R   t   wrappedR    (    (    s)   lib/python2.7/site-packages/nose/suite.pyR‹     s    !"#N(   R
   R   R   R7   Rˆ   R)   R‰   R   R_   R•   RŒ   R   RŽ   R‹   (    (    (    s)   lib/python2.7/site-packages/nose/suite.pyR‡     s   					2R¡   c           B   s#   e  Z d  Z d d „ Z d „  Z RS(   sÄ   Not quite a suite -- a group of tests in a context. This is used
    to hint the ContextSuiteFactory about what context the tests
    belong to, in cases where it may be ambiguous or missing.
    c         C   s   | |  _  | |  _ d  S(   N(   R   RT   (   R   R   RT   (    (    s)   lib/python2.7/site-packages/nose/suite.pyR   2  s    	c         C   s   t  |  j ƒ S(   N(   R   R   (   R   (    (    s)   lib/python2.7/site-packages/nose/suite.pyR   6  s    N(   R
   R   R   R)   R   R   (    (    (    s)   lib/python2.7/site-packages/nose/suite.pyR¡   -  s   t   FinalizingSuiteWrapperc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sÐ   Wraps suite and calls final function after suite has
    executed. Used to call final functions in cases (like running in
    the standard test runner) where test running is not under nose's
    control.
    c         C   s)   t  t |  ƒ j ƒ  | |  _ | |  _ d  S(   N(   R   R£   R   R˜   t   finalize(   R   R˜   R¤   (    (    s)   lib/python2.7/site-packages/nose/suite.pyR   @  s    	c         O   s   |  j  | | Ž  S(   N(   R$   (   R   R]   R^   (    (    s)   lib/python2.7/site-packages/nose/suite.pyR_   E  s    c         C   s   t  |  j ƒ S(   N(   R   R˜   (   R   (    (    s)   lib/python2.7/site-packages/nose/suite.pyR   I  s    c         O   s,   z |  j  | | Ž  SWd  |  j | | Ž  Xd  S(   N(   R˜   R¤   (   R   R]   R^   (    (    s)   lib/python2.7/site-packages/nose/suite.pyR$   L  s    (   R
   R   R   R   R_   R   R$   (    (    (    s)   lib/python2.7/site-packages/nose/suite.pyR£   :  s
   			t   TestDirc           B   s   e  Z d  „  Z RS(   c          O   s   t  d ƒ ‚ d  S(   Ns…   TestDir is not usable with nose 0.10. The class is present in nose.suite for backwards compatibility purposes but it may not be used.(   t   NotImplementedError(   R]   R^   (    (    s)   lib/python2.7/site-packages/nose/suite.pyR   U  s    (   R
   R   R   (    (    (    s)   lib/python2.7/site-packages/nose/suite.pyR¥   T  s   t
   TestModulec           B   s   e  Z d  „  Z RS(   c          O   s   t  d ƒ ‚ d  S(   Nsˆ   TestModule is not usable with nose 0.10. The class is present in nose.suite for backwards compatibility purposes but it may not be used.(   R¦   (   R]   R^   (    (    s)   lib/python2.7/site-packages/nose/suite.pyR   ]  s    (   R
   R   R   (    (    (    s)   lib/python2.7/site-packages/nose/suite.pyR§   \  s   (&   R   t
   __future__R    t   loggingR`   R0   t	   nose.caseR   t   nose.configR   t
   nose.proxyR   t	   nose.utilR   R   R   Rb   t   version_infot   clrt   AddReferencet   IronPython.Runtime.ExceptionsR	   t	   Exceptiont	   getLoggerR
   R%   R   R‰   R   R   R1   R   R7   R‡   R¡   R£   R¥   R§   (    (    (    s)   lib/python2.7/site-packages/nose/suite.pyt   <module>	   s4   		Kÿ 	¬