
i\c           @` sz  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 m 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 d d l m Z d Z d Z e	 j d e f d     Y Z d e f d     YZ d e f 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_import(   t   division(   t   print_functionN(   t   OrderedDicti   (   t   _PY2(   t   Path(   t   resolve_from_str(   t   rmtreeu'  # pytest cache directory #

This directory contains data from the pytest's cache plugin,
which provides the `--lf` and `--ff` options, as well as the `cache` fixture.

**Do not** commit this to version control.

See [the docs](https://docs.pytest.org/en/latest/cache.html) for more information.
s   Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by pytest.
# For information about cache directory tags, see:
#	http://www.bford.info/cachedir/spec.html
t   Cachec           B` s   e  Z e j d  e  Z e j d  e  Z e d    Z e	 d    Z
 d   Z d   Z d   Z d   Z d   Z d   Z RS(	   t   reprc         C` sT   |  j  |  } | j d  rG | j   rG t | d t | j   n  |  | |  S(   Nt
   cachecleart   force(   t   cache_dir_from_configt	   getoptiont   existsR   t   Truet   mkdir(   t   clst   configt   cachedir(    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt
   for_config2   s
    c         C` s   t  |  j d  |  j  S(   Nt	   cache_dir(   R   t   getinit   rootdir(   R   (    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyR   :   s    c         K` sX   d d l  m } d d l m } | | | r; | j |   n |  |  j j d d d  S(   Ni    (   t   _issue_warning_captured(   t   PytestCacheWarningt
   stackleveli   (   t   _pytest.warningsR   t   _pytest.warning_typesR   t   formatt   _configt   hook(   t   selft   fmtt   argsR   R   (    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt   warn>   s    c         C` sk   t  |  } t | j  d k r0 t d   n  |  j j d |  } | j d t d t  t j	 j
 |  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.
        i   s.   name is not allowed to contain path separatorst   dt   exist_okt   parents(   R   t   lent   partst
   ValueErrort	   _cachedirt   joinpathR   R   t   pyt   patht   local(   R    t   namet   res(    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt   makedirH   s    
c         C` s   |  j  j d t |   S(   Nt   v(   R*   R+   R   (   R    t   key(    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt   _getvaluepathY   s    c         C` sZ   |  j  |  } y) | j d   } t j |  SWd QXWn t t t f k
 rU | SXd 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   rN(   R4   t   opent   jsont   loadR)   t   IOErrort   OSError(   R    R3   t   defaultR-   t   f(    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt   get\   s    c         C` s  |  j  |  } yD | j j   r* t } n( |  j j   } | j j d t d t  Wn+ t t f k
 r |  j	 d d | d SX| s |  j
   n  y | j t r d n d  } Wn* t t f k
 r |  j	 d d | n* X| ! 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.
        R%   R&   s"   could not create cache path {path}R-   Nt   wbt   ws!   cache could not write path {path}t   indenti   t	   sort_keys(   R4   t   parentt   is_dirR   R*   R   R   R9   R:   R#   t   _ensure_supporting_filesR6   t   PY2R7   t   dump(   R    R3   t   valueR-   t   cache_dir_exists_alreadyR<   (    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt   setn   s"    		c         C` sh   |  j  d } | j t  |  j  j d  } d } | j | d d |  j  j d  } | j t  d S(   sO   Create supporting files in the cache dir that are not really part of the cache.s	   README.mds
   .gitignoreu$   # Created by pytest automatically.
*t   encodings   UTF-8s   CACHEDIR.TAGN(   R*   t
   write_textt   README_CONTENTR+   t   write_bytest   CACHEDIR_TAG_CONTENT(   R    t   readme_patht   gitignore_patht   msgt   cachedir_tag_path(    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyRD      s    (   t   __name__t
   __module__t   attrt   ibt   FalseR*   R   t   classmethodR   t   staticmethodR   R#   R1   R4   R=   RI   RD   (    (    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyR   -   s   	
				t   LFPluginc           B` sV   e  Z d  Z d   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         ` se     |  _  d } t   f d   | D  |  _   j j d i   |  _ d  |  _ d  |  _ d |  _	 d  S(   Nt   lft   failedfirstc         3` s   |  ] }   j  |  Vq d  S(   N(   R   (   t   .0R3   (   R   (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pys	   <genexpr>   s    s   cache/lastfailedi    (   R[   R\   (
   R   t   anyt   activet   cacheR=   t
   lastfailedt   Nonet   _previously_failed_countt   _report_statust   _skipped_files(   R    R   t   active_keys(    (   R   s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt   __init__   s    			c         ` sh   y |  j  SWnV t k
 rc t |  j j      f d   |  j D } d   | D } | |  _  | SXd S(   sS   Returns a set with all Paths()s of the previously failed nodeids (cached).
        c         ` s'   h  |  ] }   | j  d   d  q S(   s   ::i    (   t   split(   R]   t   nodeid(   t   rootpath(    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pys	   <setcomp>   s   	 c         S` s"   h  |  ] } | j    r |  q S(    (   R   (   R]   t   x(    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pys	   <setcomp>   s   	 N(   t   _last_failed_pathst   AttributeErrorR   R   R   Ra   (   R    t   result(    (   Rj   s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt   last_failed_paths   s    	c         C` st   |  j  rp |  j j d  rp | j   rp |  j   } | rp t |  |  j   k } | ri |  j d 7_ n  | Sn  d S(   s|   
        Ignore this file path if we are in --lf mode and it is not in the list of
        previously failed files.
        R[   i   N(   R_   R   R   t   isfileRo   R   Re   (   R    R-   Ro   t   skip_it(    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt   pytest_ignore_collect   s    'c         C` s0   |  j  r, |  j j d  d k r, d |  j Sd  S(   Nt   verbosei    s   run-last-failure: %s(   R_   R   R   Rd   (   R    (    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt   pytest_report_collectionfinish   s    !c         C` sZ   | j  d k r | j s! | j r: |  j j | j d   n | j rV t |  j | j <n  d  S(   Nt   call(	   t   whent   passedt   skippedRa   t   popRi   Rb   t   failedR   (   R    t   report(    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt   pytest_runtest_logreport   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(   NRw   Rx   c         s` s   |  ] } | j  t f Vq d  S(   N(   Ri   R   (   R]   t   item(    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pys	   <genexpr>   s    (   Rw   Rx   (   t   outcomeRi   Ra   Ry   t   updateRn   R   (   R    R{   Rw   (    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt   pytest_collectreport   s    #c   
      C` s  |  j  s d  S|  j r~g  } g  } x= | D]5 } | j |  j k rQ | j |  q) | j |  q) Wt |  |  _ | s d t |  j  f |  _ n |  j j d  r | | (| j	 j
 d |  n | | | (|  j d k r d n d } |  j j d  r d n d	 } d
 j d |  j d | d |  |  _ |  j d k r|  j d k rNd n d }	 |  j d j d |  j d |	  7_ qn\ d |  _ |  j j d  d k r|  j d 7_ | j	 j
 d |  g  | (n |  j d 7_ d  S(   Ns'   %d known failures not in selected testsR[   t   itemsi   t   failuret   failuresR\   s    firstt    s%   rerun previous {count} {noun}{suffix}t   countt   suffixt   nouni    t   filet   filess    (skipped {files} {files_noun})t
   files_nouns   no previously failed tests, t   last_failed_no_failurest   nones   deselecting all items.s   not deselecting items.(   R_   Ra   Ri   t   appendR'   Rc   Rd   R   R   R   t   pytest_deselectedR   Re   (
   R    t   sessionR   R   t   previously_failedt   previously_passedR}   R   R   R   (    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt   pytest_collection_modifyitems   s>    				
c         C` sl   |  j  } | j d  s' t | d  r+ d  S| j j d i   } | |  j k rh | j j d |  j  n  d  S(   Nt	   cacheshowt
   slaveinputs   cache/lastfailed(   R   R   t   hasattrR`   R=   Ra   RI   (   R    R   R   t   saved_lastfailed(    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt   pytest_sessionfinish   s    	(   RS   RT   t   __doc__Rg   Ro   Rr   Rt   R|   R   R   R   (    (    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyRZ      s   									/t   NFPluginc           B` s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s9    Plugin which implements the --nf (run new-first) option c         C` s4   | |  _  | j j |  _ | j j d g   |  _ d  S(   Ns   cache/nodeids(   R   t   optiont   newfirstR_   R`   R=   t   cached_nodeids(   R    R   (    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyRg     s    	c         C` s   |  j  r t   } t   } x= | D]5 } | j |  j k rJ | | | j <q" | | | j <q" W|  j t j |   |  j t j |   | (n  g  | D]! } t | t j	  r | j ^ q |  _ d  S(   N(
   R_   R   Ri   R   t   _get_increasing_ordert   sixt
   itervaluest
   isinstancet   pytestt   Item(   R    R   R   R   t	   new_itemst   other_itemsR}   Rk   (    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyR     s    			c         C` s   t  | d d   d t S(   NR3   c         S` s   |  j  j   S(   N(   t   fspatht   mtime(   R}   (    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt   <lambda>!  R   t   reverse(   t   sortedR   (   R    R   (    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyR      s    c         C` sE   |  j  } | j d  s' t | d  r+ d  S| j j d |  j  d  S(   NR   R   s   cache/nodeids(   R   R   R   R`   RI   R   (   R    R   R   (    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyR   #  s    	(   RS   RT   R   Rg   R   R   R   (    (    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyR   	  s
   			c         C` s8  |  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 d | j d d d d d d d d d | j d d d d d d d d } d t j k r t j j t j d |  } n  |  j d d | d d | j d  d! d d" d 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   --nfs   --new-firstR   sO   run tests from new files first, then the rest of the tests sorted by file mtimes   --cache-showR   t   nargst   ?R   s_   show cache contents, don't perform collection or tests. Optional argument: glob (default: '*').s   --cache-clearR
   s/   remove all cache contents at start of test run.s   .pytest_cachet   TOX_ENV_DIRR   R;   s   cache directory path.s   --lfnfs   --last-failed-no-failurest   storeR   t   choicest   allR   s7   which tests to run with no previously (known) failures.(   R   R   (   t   getgroupt	   addoptiont   ost   environR-   t   joint   addini(   t   parsert   groupt   cache_dir_default(    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt   pytest_addoption+  sT    c         C` s-   |  j  j r) d d l m } | |  t  Sd  S(   Ni    (   t   wrap_session(   R   R   t   _pytest.mainR   (   R   R   (    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt   pytest_cmdline_maine  s    t   tryfirstc         C` sH   t  j |   |  _ |  j j t |   d  |  j j t |   d  d  S(   Nt   lfplugint   nfplugin(   R   R   R`   t   pluginmanagert   registerRZ   R   (   R   (    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt   pytest_configurel  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(    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyR`   s  s    c         C` st   |  j  j d k s' |  j d  d k rp |  j j } y | j |  j  } Wn t k
 rb | } n Xd j |  Sd S(   s6   Display cachedir with --cache-show and if non-default.i    R   s   .pytest_caches   cachedir: {}N(	   R   Rs   R   R`   R*   t   relative_toR   R)   R   (   R   R   t   displaypath(    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt   pytest_report_header  s    '
c         C` s  d d l  m } t j j   } | j d t |  j j   |  j j j	   s_ | j d  d S|  j
 j d } | d  k r d } n  t   } |  j j } | d } | j d d |  x t d	   | j |  D  D] } | j |  }	 |  j j |	 |  }
 |
 | k r!| j d
 |	  q | j d |	  x+ | |
  j   D] } | j d |  qEWq W| d } | j	   rt | j |   } | j d d |  xQ | D]F } | j   r| j |  }	 | j d j |	 | j   j   qqWn  d S(   Ni    (   t   pformats
   cachedir: s   cache is emptyt   *R2   t   -s   cache values for %rc         s` s!   |  ] } | j    r | Vq d  S(   N(   t   is_file(   R]   Rk   (    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pys	   <genexpr>  s    s/   %s contains unreadable content, will be ignoreds   %s contains:s     R$   s   cache directories for %rs   {} is a file of length {:d}(   t   pprintR   R,   t   iot   TerminalWritert   linet   strR`   R*   RC   R   R   Rb   t   objectt   sepR   t   rglobR   R=   t
   splitlinesR   R   t   statt   st_size(   R   R   R   t   twt   globt   dummyt   basedirt   vdirt   valpathR3   t   valR   t   ddirt   contentst   p(    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyR     s<    		
&
,($   R   t
   __future__R    R   R   R7   R   t   collectionsR   RU   R,   R   R   t   compatR   RE   t   pathlibR   R   R   RL   RN   t   sR   R   RZ   R   R   R   t   hookimplR   R   t   fixtureR`   R   R   (    (    (    s4   lib/python2.7/site-packages/_pytest/cacheprovider.pyt   <module>   s4   	jq"	:		