σ
Ύ^Yc           @` sΪ   d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l Z d d l m	 Z
 m Z d e f d     YZ d d d     YZ d	   Z d
   Z e j d e  d    Z e j d    Z d   Z d   Z d S(   s   
merged implementation of the cache provider

the name cache was not chosen to ensure pluggy automatically
ignores the external pytest-cache
i    (   t   absolute_importt   divisiont   print_functionN(   t   sept   altsept   Cachec           B` s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C` s   | |  _  | j j d  |  _ | j j j d  |  _ | j d  r |  j d  |  j j   rq |  j j	   n  |  j j
   n  d  S(   Ns   .cachet   cachet
   cacheclears   clearing cachedir(   t   configt   rootdirt   joint	   _cachedirt   tracet   roott   gett   getvaluet   checkt   removet   mkdir(   t   selfR   (    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyt   __init__   s    	c         C` sF   t  | k s$ t d k	 r3 t | k r3 t d   n  |  j j d |  S(   sΐ   return a directory path object with the given name.  If the
        directory does not yet exist, it will be created.  You can use it
        to manage files likes e. g. store/retrieve database
        dumps across test sessions.

        :param name: must be a string not containing a ``/`` separator.
             Make sure the name contains your plugin or application
             identifiers to prevent clashes with other cache users.
        s.   name is not allowed to contain path separatorst   dN(   t   _sept   _altsept   Nonet
   ValueErrorR   t
   ensure_dir(   R   t   name(    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyt   makedir   s    
$c         C` s   |  j  j d | j d   S(   Nt   vt   /(   R   R
   t   split(   R   t   key(    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyt   _getvaluepath'   s    c         C` ss   |  j  |  } | j   ro y) | j d   } t j |  SWd QXWqo t k
 rk |  j d | f  qo Xn  | S(   s   return cached value for the given key.  If no value
        was yet cached or the value cannot be read, the specified
        default is returned.

        :param key: must be a ``/`` separated value. Usually the first
             name is the name of your plugin or your application.
        :param default: must be provided in case of a cache-miss or
             invalid cache values.

        t   rNs   cache-invalid at %s(   R!   R   t   opent   jsont   loadR   R   (   R   R    t   defaultt   patht   f(    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyR   *   s    c         C` sϋ   |  j  |  } y | j   j   WnD t j j t j j f k
 ri |  j j d d d d | f  d SXy | j	 d  } Wn7 t j j
 k
 rΆ |  j j d d d d | f  nA X| 8 |  j d | | f  t j | | d	 d
 d t Wd QXd S(   sP   save value for the given key.

        :param key: must be a ``/`` separated value. Usually the first
             name is the name of your plugin or your application.
        :param value: must be of any combination of basic
               python types, including nested types
               like e. g. lists of dictionaries.
        t   codet   I9t   messages   could not create cache path %sNt   ws   cache could not write path %ss   cache-write %s: %rt   indenti   t	   sort_keys(   R!   t   dirpathR   t   pyt   errort   EEXISTt   EACCESR   t   warnR#   t   ENOTDIRR   R$   t   dumpt   True(   R   R    t   valueR'   R(   (    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyt   set>   s    	(   t   __name__t
   __module__R   R   R!   R   R9   (    (    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyR      s
   	
			t   LFPluginc           B` sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s<    Plugin which implements the --lf (run last-failing) option c         ` s_     |  _  d } t   f d   | D  |  _ |  j rR   j j d i   |  _ n	 i  |  _ d  S(   Nt   lft   failedfirstc         3` s   |  ] }   j  |  Vq d  S(   N(   R   (   t   .0R    (   R   (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pys	   <genexpr>_   s    s   cache/lastfailed(   s   lfR>   (   R   t   anyt   activeR   R   t
   lastfailed(   R   R   t   active_keys(    (   R   s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyR   \   s    		c         C` sX   |  j  rT |  j s d } n1 d t |  j  |  j j d  rB d n d f } d | Sd  S(   Ns   run all (no recorded failures)s   rerun last %d failures%sR>   s    firstt    s   run-last-failure: %s(   RA   RB   t   lenR   R   (   R   t   mode(    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyt   pytest_report_headere   s    			"c         C` sc   | j  r+ d | j k r+ t |  j | j <n4 | j  s_ | j d k r_ |  j j | j d   q_ n  d  S(   Nt   xfailt   call(   t   failedt   keywordsR7   RB   t   nodeidt   whent   popR   (   R   t   report(    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyt   pytest_runtest_logreporto   s
    	c         C` sq   | j  d k } | r] | j |  j k rm |  j j | j  |  j j d   | j D  qm n t |  j | j <d  S(   Nt   passedt   skippedc         s` s   |  ] } | j  t f Vq d  S(   N(   RL   R7   (   R?   t   item(    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pys	   <genexpr>|   s   (   s   passedRR   (   t   outcomeRL   RB   RN   t   updatet   resultR7   (   R   RO   RQ   (    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyt   pytest_collectreportv   s    	c         C` s―   |  j  r« |  j r« g  } g  } x= | D]5 } | j |  j k rM | j |  q% | j |  q% W| rn | rn q« |  j j d  r | | (| j j d |  q« | | | (n  d  S(   NR=   t   items(   RA   RB   RL   t   appendR   R   t   hookt   pytest_deselected(   R   t   sessionR   RX   t   previously_failedt   previously_passedRS   (    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyt   pytest_collection_modifyitems   s    c         C` s{   |  j  } | j d  s' t | d  r+ d  S| j j d d   d  k	 } | j rU | s^ |  j rw | j j d |  j  n  d  S(   Nt	   cacheshowt
   slaveinputs   cache/lastfailed(	   R   R   t   hasattrR   R   R   t   testscollectedRB   R9   (   R   R\   R   t   prev_failed(    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyt   pytest_sessionfinish   s    	(	   R:   R;   t   __doc__R   RG   RP   RW   R_   Re   (    (    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyR<   Z   s   			
			c      	   C` s   |  j  d  } | j d d d d d d d d	 | j d
 d d d d d d d | j d d d d d d d | j d d d d d d d d  S(   Nt   generals   --lfs   --last-failedt   actiont
   store_truet   destR=   t   helpsH   rerun only the tests that failed at the last run (or all if none failed)s   --ffs   --failed-firstR>   sx   run all tests but run the last failures first.  This may re-order tests and thus lead to repeated fixture setup/teardowns   --cache-showR`   s6   show cache contents, don't perform collection or testss   --cache-clearR   s/   remove all cache contents at start of test run.(   t   getgroupt	   addoption(   t   parsert   group(    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyt   pytest_addoption   s    c         C` s-   |  j  j r) d d l m } | |  t  Sd  S(   Ni    (   t   wrap_session(   t   optionR`   t   _pytest.mainRq   (   R   Rq   (    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyt   pytest_cmdline_main°   s    t   tryfirstc         C` s,   t  |   |  _ |  j j t |   d  d  S(   Nt   lfplugin(   R   R   t   pluginmanagert   registerR<   (   R   (    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyt   pytest_configure·   s    c         C` s
   |  j  j S(   sg  
    Return a cache object that can persist state between testing sessions.

    cache.get(key, default)
    cache.set(key, value)

    Keys must be a ``/`` separated value, where the first part is usually the
    name of your plugin or application to avoid clashes with other cache users.

    Values can be any object handled by the json stdlib module.
    (   R   R   (   t   request(    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyR   ½   s    c         C` s6   |  j  j r2 t j j   j |  j j  } d | Sd  S(   Ns   cachedir: %s(   Rr   t   verboseR0   R'   t   localt   bestrelpathR   R   (   R   t   relpath(    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyRG   Ν   s    c         C` s  d d l  m  } t j j   } | j d t |  j j   |  j j j   s_ | j d  d St	   } |  j j } | j
 d  } | j d d  xΡ t | j d     D]· } | j |  j | j d	  } |  j j | |  }	 |	 | k r| j d
 |  q¬ | j d |  t j j   }
 | |	 d |
 x+ |
 j   j   D] } | j d |  qHWq¬ W| j
 d  } | j   r| j   r| j d d  xa t | j
 d  j    D]A } | j   rΊ| j |  } | j d | | j   f  qΊqΊWn  d S(   Ni    (   t   pprints
   cachedir: s   cache is emptyR   t   -s   cache valuesc         S` s
   |  j    S(   N(   t   isfile(   t   x(    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyt   <lambda>ή   s    R   s/   %s contains unreadable content, will be ignoreds   %s contains:t   streams     R   s   cache directoriess   %s is a file of length %d(   R   R0   t   iot   TerminalWritert   linet   strR   R   R   t   objectR
   R   t   sortedt   visitt   reltot   replaceR   t   TextIOR   t
   splitlinest   isdirt   listdirR   t   size(   R   R\   R   t   twt   dummyt   basedirt   vdirt   valpathR    t   valR   R   t   ddirt   p(    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyR`   Σ   s<    		"	(    (   Rf   t
   __future__R    R   R   R0   t   pytestR$   t   os.pathR   R   R   R   R   R   R<   Rp   Rt   t   hookimplR7   Ry   t   fixtureR   RG   R`   (    (    (    s5   /tmp/pip-build-hU8Cw8/pytest/_pytest/cacheprovider.pyt   <module>   s   LC			