
i\c           @` s  d  Z  d d l m Z d d l m 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	 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 d d l m Z d d l m Z d d l m Z d   Z d   Z d   Z d   Z d   Z e d d  Z d   Z d   Z d   Z d   Z  d   Z! d   Z" e d  Z# d   Z$ d   Z% e	 j& d e'  d e( f d      Y Z) d!   Z* d"   Z+ d# e( f d$     YZ, d%   Z- d S(&   s4    basic collect and runtest protocol implementations i    (   t   absolute_import(   t   division(   t   print_functionN(   t   timei   (   t   CollectErrorRepr(   t   CollectReport(   t
   TestReport(   t   ExceptionInfo(   t   Exit(   t   Skipped(   t   TEST_OUTCOMEc         C` sJ   |  j  d d d d } | j d d d d t d	 d  d
 d d d f d  S(   Ns   terminal reportingt	   reportingt   aftert   generals   --durationst   actiont   storet   typet   defaultt   metavart   Nt   helps2   show N slowest setup/test durations (N=0 for all).(   t   getgroupt	   addoptiont   intt   None(   t   parsert   group(    (    s-   lib/python2.7/site-packages/_pytest/runner.pyt   pytest_addoption   s    c         C` sV  |  j  j j } |  j  j d  } | d  k r1 d  S|  } g  } xG | j j   D]6 } x- | D]% } t | d  rZ | j |  qZ qZ WqM W| s d  S| j	 d d    | j
   | s | j d d  n | j d d |  | |  } xj | D]b } | d k  r+| j d	 k  r+| j d
  | j d  Pn  | j d | j | j | j f  q Wd  S(   Nt   verboset   durationt   keyc         S` s   |  j  S(   N(   R   (   t   x(    (    s-   lib/python2.7/site-packages/_pytest/runner.pyt   <lambda>4   t    t   =s   slowest test durationss   slowest %s test durationsi   g{Gzt?R!   s:   (0.00 durations hidden.  Use -vv to show these durations.)s   %02.2fs %-8s %s(   t   configt   optiont	   durationst   getvalueR   t   statst   valuest   hasattrt   appendt   sortt   reverset	   write_sepR   t
   write_linet   whent   nodeid(   t   terminalreporterR%   R   t   trt   dlistt   replistt   rep(    (    s-   lib/python2.7/site-packages/_pytest/runner.pyt   pytest_terminal_summary'   s0    

c         C` s   t    |  _ d  S(   N(   t
   SetupStatet   _setupstate(   t   session(    (    s-   lib/python2.7/site-packages/_pytest/runner.pyt   pytest_sessionstartD   s    c         C` s   |  j  j   d  S(   N(   R8   t   teardown_all(   R9   (    (    s-   lib/python2.7/site-packages/_pytest/runner.pyt   pytest_sessionfinishH   s    c         C` sR   |  j  j d |  j d |  j  t |  d | |  j  j d |  j d |  j  t S(   NR0   t   locationt   nextitem(   t   ihookt   pytest_runtest_logstartR0   R=   t   runtestprotocolt   pytest_runtest_logfinisht   True(   t   itemR>   (    (    s-   lib/python2.7/site-packages/_pytest/runner.pyt   pytest_runtest_protocolL   s    c         C` s   t  |  d  } | r, |  j r, |  j   n  t |  d |  } | g } | j r |  j j d t  rr t |   n  |  j j d t  s | j	 t |  d |   q n  | j	 t |  d | d |  | r t |  _ d  |  _ n  | S(   Nt   _requestt   setupt	   setupshowt	   setuponlyt   callt   teardownR>   (   R)   RF   t   _initrequestt   call_and_reportt   passedR#   t	   getoptiont   Falset   show_test_itemR*   R   t   funcargs(   RD   t   logR>   t
   hasrequestR5   t   reports(    (    s-   lib/python2.7/site-packages/_pytest/runner.pyRA   S   s    			c         C` sz   |  j  j   } | j   | j d  | j |  j  t |  j j j    } | rv | j d j	 d j
 |    n  d S(   sA   Show test function, parameters and the fixtures of the test item.t    i   s    (fixtures used: {})s   , Ns           (   R#   t   get_terminal_writert   linet   writet   _nodeidt   sortedt   _fixtureinfot   name2fixturedefst   keyst   formatt   join(   RD   t   twt   used_fixtures(    (    s-   lib/python2.7/site-packages/_pytest/runner.pyRQ   g   s    
c         C` s$   t  |  d  |  j j j |   d  S(   NRG   (   t   _update_current_test_varR9   R8   t   prepare(   RD   (    (    s-   lib/python2.7/site-packages/_pytest/runner.pyt   pytest_runtest_setupr   s    c         C` s   t  |  d  d \ t _ t _ t _ y |  j   WnV t k
 r t j   \ } } } | j	 } | t _ | t _ | t _ ~ ~ ~   n Xd  S(   NRJ   (   NNN(
   Rc   R   t   syst	   last_typet
   last_valuet   last_tracebackt   runtestt	   Exceptiont   exc_infot   tb_next(   RD   R   t   valuet   tb(    (    s-   lib/python2.7/site-packages/_pytest/runner.pyt   pytest_runtest_callw   s    					c         C` s4   t  |  d  |  j j j |  |  t  |  d   d  S(   NRK   (   Rc   R9   R8   t   teardown_exactR   (   RD   R>   (    (    s-   lib/python2.7/site-packages/_pytest/runner.pyt   pytest_runtest_teardown   s    c         C` sW   d } | rC d j  |  j |  } | j d d  } | t j | <n t j j |  d S(   s   
    Update PYTEST_CURRENT_TEST to reflect the current item and stage.

    If ``when`` is None, delete PYTEST_CURRENT_TEST from the environment.
    t   PYTEST_CURRENT_TESTs   {} ({})s    s   (null)N(   R_   R0   t   replacet   ost   environt   pop(   RD   R/   t   var_nameRn   (    (    s-   lib/python2.7/site-packages/_pytest/runner.pyRc      s    c         C` s4   |  j  d
 k r0 |  j r d S|  j r) d Sd Sn  d  S(   NRG   RK   t   errort   Et   ERRORt   skippedt   st   SKIPPEDR!   (   RG   RK   (   Ry   Rz   R{   (   R|   R}   R~   (   R!   R!   R!   (   R/   t   failedR|   (   t   report(    (    s-   lib/python2.7/site-packages/_pytest/runner.pyt   pytest_report_teststatus   s    		c         K` s~   t  |  | |  } |  j } | j d |  d |  } | rL | j d |  n  t | |  rz | j d |  d | d |  n  | S(   NRD   RJ   R   t   node(   t   call_runtest_hookR?   t   pytest_runtest_makereportt   pytest_runtest_logreportt   check_interactive_exceptiont   pytest_exception_interact(   RD   R/   RS   t   kwdsRJ   t   hookR   (    (    s-   lib/python2.7/site-packages/_pytest/runner.pyRM      s    	c         C` s>   |  j  o= t | d  p< |  j  j t  p< |  j  j t j  S(   Nt   wasxfail(   t   excinfoR)   t   errisinstanceR	   t   bdbt   BdbQuit(   RJ   R   (    (    s-   lib/python2.7/site-packages/_pytest/runner.pyR      s    	c         ` sr   d | } t   j |    t f }  j j d t  sJ | t f 7} n  t j     f d   d | d | S(   Nt   pytest_runtest_t   usepdbc           ` s     d    S(   NRD   (    (    (   R?   RD   R   (    s-   lib/python2.7/site-packages/_pytest/runner.pyR       R!   R/   t   reraise(	   t   getattrR?   R   R#   RO   RP   t   KeyboardInterruptt   CallInfot	   from_call(   RD   R/   R   t   hooknameR   (    (   R?   RD   R   s-   lib/python2.7/site-packages/_pytest/runner.pyR      s    
	t   reprR   c           B` st   e  Z d  Z e j   Z e j   Z e j   Z e j   Z e j   Z	 e
 d    Z e d d   Z d   Z RS(   s.    Result/Exception info a function invocation. c         C` s.   |  j  d  k	 r' t d j |     n  |  j S(   Ns   {!r} has no valid result(   R   R   t   AttributeErrorR_   t   _result(   t   self(    (    s-   lib/python2.7/site-packages/_pytest/runner.pyt   result   s    c         C` s   t    } d  } y |   } Wn: t j   } | d  k	 rO | j |  rO   n  d  } n Xt    } |  d | d | d | d | d |  S(   Nt   startt   stopR/   R   R   (   R   R   R   t   from_currentR   (   t   clst   funcR/   R   R   R   R   R   (    (    s-   lib/python2.7/site-packages/_pytest/runner.pyR      s    	
	c         C` sX   |  j  d  k	 r$ d } |  j  j } n t |  j  } d } d j d |  j d | d |  S(   Nt	   exceptionR   s*   <CallInfo when={when!r} {status}: {value}>R/   Rn   t   status(   R   R   Rn   R   R   R_   R/   (   R   R   Rn   (    (    s-   lib/python2.7/site-packages/_pytest/runner.pyt   __repr__   s    	N(   t   __name__t
   __module__t   __doc__t   attrt   ibR   R   R   R   R/   t   propertyR   t   classmethodR   R   R   (    (    (    s-   lib/python2.7/site-packages/_pytest/runner.pyR      s   c         C` s   t  j |  |  S(   N(   R   t   from_item_and_call(   RD   RJ   (    (    s-   lib/python2.7/site-packages/_pytest/runner.pyR      s    c   	      ` s  t  j   f d   d  } d  } | j s3 d } n d d l m } t f | j   } | j j |  r d }   j	 | j d  j
 } t | j  | j | j f } n< d }   j | j  } t | d	  s t |  } n  | } t   j | | t | d
 d    } | | _ | S(   Nc           ` s   t    j    S(   N(   t   listt   collect(    (   t	   collector(    s-   lib/python2.7/site-packages/_pytest/runner.pyR       R!   R   RN   i    (   t   noseR|   RX   R   t
   toterminalR   (   R   R   R   R   t   _pytestR   R	   t   get_skip_exceptionsR   t   _repr_failure_pyt	   reprcrasht   strt   patht   linenot   messaget   repr_failureR)   R   R   R0   R   RJ   (	   R   RJ   t   longreprt   outcomeR   t   skip_exceptionst   rt	   errorinfoR5   (    (   R   s-   lib/python2.7/site-packages/_pytest/runner.pyt   pytest_make_collect_report   s&    		!!	R7   c           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(
   sD    shared state for setting up/tearing down test items or collectors. c         C` s   g  |  _  i  |  _ d  S(   N(   t   stackt   _finalizers(   R   (    (    s-   lib/python2.7/site-packages/_pytest/runner.pyt   __init__  s    	c         C` sN   | r t  | t  s t  t |  s. t  |  j j | g   j |  d S(   s    attach a finalizer to the given colitem.
        if colitem is None, this will add a finalizer that
        is called at the end of teardown_all().
        N(   t
   isinstancet   tuplet   AssertionErrort   callableR   t
   setdefaultR*   (   R   t	   finalizert   colitem(    (    s-   lib/python2.7/site-packages/_pytest/runner.pyt   addfinalizer  s    c         C` s    |  j  j   } |  j |  d  S(   N(   R   Rw   t   _teardown_with_finalization(   R   R   (    (    s-   lib/python2.7/site-packages/_pytest/runner.pyt   _pop_and_teardown'  s    c         C` s   |  j  j | d   } d  } xP | rm | j   } y |   Wq t k
 ri | d  k rj t j   } qj q Xq W| r t j |   n  d  S(   N(   R   Rw   R   R
   Rf   Rl   t   sixR   (   R   R   t
   finalizerst   exct   fin(    (    s-   lib/python2.7/site-packages/_pytest/runner.pyt   _callfinalizers+  s    	c         C` sq   |  j  |  t | d  r) | j   n  xA |  j D]6 } | d  k s3 | |  j k s3 t | t  s3 t  q3 Wd  S(   NRK   (	   R   R)   RK   R   R   R   R   R   R   (   R   R   (    (    s-   lib/python2.7/site-packages/_pytest/runner.pyR   :  s
    c         C` sU   x |  j  r |  j   q Wx$ t |  j  D] } |  j |  q* W|  j sQ t  d  S(   N(   R   R   R   R   R   R   (   R   R   (    (    s-   lib/python2.7/site-packages/_pytest/runner.pyR;   C  s
    c         C` s)   | r | j    p g  } |  j |  d  S(   N(   t	   listchaint   _teardown_towards(   R   RD   R>   t   needed_collectors(    (    s-   lib/python2.7/site-packages/_pytest/runner.pyRq   J  s    c         C` s   d  } xj |  j rr |  j | t |  j   k r2 Pn  y |  j   Wq	 t k
 rn | d  k ro t j   } qo q	 Xq	 W| r t j |   n  d  S(   N(	   R   R   t   lenR   R
   Rf   Rl   R   R   (   R   R   R   (    (    s-   lib/python2.7/site-packages/_pytest/runner.pyR   N  s    c         C` s   | j    } |  j |  x3 |  j D]( } t | d  r# t j | j   q# q# Wx_ | t |  j  D]J } |  j j |  y | j	   Wqc t
 k
 r t j   | _   qc Xqc Wd S(   sn    setup objects along the collector chain to the test-method
            and teardown previously setup objects.t   _prepare_excN(   R   R   R   R)   R   R   R   R   R*   RG   R
   Rf   Rl   (   R   R   R   t   col(    (    s-   lib/python2.7/site-packages/_pytest/runner.pyRd   ]  s    (   R   R   R   R   R   R   R   R   R;   Rq   R   Rd   (    (    (    s-   lib/python2.7/site-packages/_pytest/runner.pyR7     s   		
							c         C` sx   |  j  } | j d |   | j d |   } | j j d d   } | rt t | |  rt | j d |  d | d |  n  | S(   NR   RJ   R   R   (   R?   t   pytest_collectstartR   t   __dict__Rw   R   R   R   (   R   R?   R5   RJ   (    (    s-   lib/python2.7/site-packages/_pytest/runner.pyt   collect_one_nodep  s    	(.   R   t
   __future__R    R   R   R   Ru   Rf   R   R   R   RU   R   R   R   t   _pytest._code.codeR   t   _pytest.outcomesR   R	   R
   R   R6   R:   R<   RE   RC   R   RA   RQ   Re   Rp   Rr   Rc   R   RM   R   R   R}   RP   t   objectR   R   R   R7   R   (    (    (    s-   lib/python2.7/site-packages/_pytest/runner.pyt   <module>   sJ   													-		Z