σ
η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 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 d l m Z d d l m Z e	 j d e f d     Y Z e	 j d e f d     Y Z d   Z d   Z e j d d  d    Z e j d d  d    Z d   Z e j d    Z e j d    Z  d S(   sA    support for providing temporary directories to test functions.  i    (   t   absolute_import(   t   division(   t   print_functionNi   (   t   ensure_reset_dir(   t   LOCK_TIMEOUT(   t   make_numbered_dir(   t   make_numbered_dir_with_cleanup(   t   Path(   t   MonkeyPatcht   TempPathFactoryc           B` sq   e  Z d  Z e j d e j j d     Z e j   Z e j d d  Z
 e d    Z e d  Z d   Z RS(   s   Factory for temporary directories under the common base temp directory.

    The base directory can be configured using the ``--basetemp`` option.t	   converterc         C` s   t  t j j t j |     S(   N(   R   t   ost   patht   abspatht   sixt	   text_type(   t   p(    (    s-   lib/python2.7/site-packages/_pytest/tmpdir.pyt   <lambda>$   t    t   defaultc         C` s%   |  d | j  j d | j j d   S(   s7   
        :param config: a pytest configuration
        t   given_basetempt   tracet   tmpdir(   t   optiont   basetempR   t   get(   t   clst   config(    (    s-   lib/python2.7/site-packages/_pytest/tmpdir.pyt   from_config*   s    c         C` sW   | s( |  j    j |  } | j   n+ t d |  j    d |  } |  j d |  | S(   s2   makes a temporary directory managed by the factoryt   roott   prefixt   mktemp(   t   getbasetempt   joinpatht   mkdirR   t   _trace(   t   selft   basenamet   numberedR   (    (    s-   lib/python2.7/site-packages/_pytest/tmpdir.pyR   3   s    c      	   C` s  |  j  d k	 r |  j  S|  j d k	 rG |  j } t |  | j   } n t j j d  } t | pk t	 j
    j   } t   p d } | j d j |   } | j d t  t d d d | d d	 d
 t  } | d k	 sη t |   | |  _  } |  j d |  | S(   s"    return base temporary directory. t   PYTEST_DEBUG_TEMPROOTt   unknowns   pytest-of-{}t   exist_okR   s   pytest-R   t   keepi   t   lock_timeouts   new basetempN(   t	   _basetempt   Nonet   _given_basetempR   t   resolveR   t   environR   R   t   tempfilet
   gettempdirt   get_userR!   t   formatR"   t   TrueR   R   t   AssertionErrorR#   (   R$   R   t   from_envt   temproott   usert   rootdirt   t(    (    s-   lib/python2.7/site-packages/_pytest/tmpdir.pyR    =   s"    	
N(   t   __name__t
   __module__t   __doc__t   attrt   ibt
   converterst   optionalR.   R#   R-   R,   t   classmethodR   R5   R   R    (    (    (    s-   lib/python2.7/site-packages/_pytest/tmpdir.pyR	      s   			
t   TempdirFactoryc           B` s;   e  Z d  Z e j   Z d d  Z e d  Z d   Z	 RS(   ss   
    backward comptibility wrapper that implements
    :class:``py.path.local`` for :class:``TempPathFactory``
    i   c         C` s<   d d l  m } t j | d d |  j   j | d | S(   s*   (deprecated) return temporary directory path with
            the given string as the trailing part.  It is usually
            better to use the 'tmpdir' function argument which
            provides an empty unique-per-test-invocation directory
            and is guaranteed to be empty.
        i   (   t   PYTEST_ENSURETEMPt
   stackleveli   t   dir(   t
   deprecatedRE   t   warningst   warnR    t   ensure(   R$   t   stringRG   RE   (    (    s-   lib/python2.7/site-packages/_pytest/tmpdir.pyt
   ensuretemp`   s    c         C` s%   t  j j |  j j | |  j    S(   sΖ   Create a subdirectory of the base temporary directory and return it.
        If ``numbered``, ensure the directory is unique by adding a number
        prefix greater than any existing one.
        (   t   pyR   t   localt   _tmppath_factoryR   R/   (   R$   R%   R&   (    (    s-   lib/python2.7/site-packages/_pytest/tmpdir.pyR   m   s    c         C` s   t  j j |  j j   j    S(   s<   backward compat wrapper for ``_tmppath_factory.getbasetemp``(   RN   R   RO   RP   R    R/   (   R$   (    (    s-   lib/python2.7/site-packages/_pytest/tmpdir.pyR    t   s    (
   R<   R=   R>   R?   R@   RP   RM   R5   R   R    (    (    (    s-   lib/python2.7/site-packages/_pytest/tmpdir.pyRD   W   s
   c          C` s9   d d l  }  y |  j   SWn t t f k
 r4 d SXd S(   sq   Return the current user name, or None if getuser() does not work
    in the current environment (see #1010).
    i    N(   t   getpasst   getusert   ImportErrort   KeyErrorR-   (   RQ   (    (    s-   lib/python2.7/site-packages/_pytest/tmpdir.pyR3   y   s
    c         C` s   t    } t j |   } t |  } |  j j | j  | j |  d | d t | j |  d | d t | j t	 d | j
 d t d S(   s  Create a TempdirFactory and attach it to the config object.

    This is to comply with existing plugins which expect the handler to be
    available at pytest_configure time, but ideally should be moved entirely
    to the tmpdir_factory session fixture.
    t   _tmp_path_factoryt   raisingt   _tmpdirhandlerRM   N(   R   R	   R   RD   t   _cleanupt   appendt   undot   setattrt   Falset   pytestRM   (   R   t   mpt   tmppath_handlerR;   (    (    s-   lib/python2.7/site-packages/_pytest/tmpdir.pyt   pytest_configure   s    	t   scopet   sessionc         C` s
   |  j  j S(   sS   Return a :class:`_pytest.tmpdir.TempdirFactory` instance for the test session.
    (   R   RW   (   t   request(    (    s-   lib/python2.7/site-packages/_pytest/tmpdir.pyt   tmpdir_factory   s    c         C` s
   |  j  j S(   sT   Return a :class:`_pytest.tmpdir.TempPathFactory` instance for the test session.
    (   R   RU   (   Rc   (    (    s-   lib/python2.7/site-packages/_pytest/tmpdir.pyt   tmp_path_factory   s    c         C` sD   |  j  j } t j d d |  } d } | |  } | j | d t S(   Ns   [\W]t   _i   R&   (   t   nodet   namet   ret   subR   R5   (   Rc   t   factoryRh   t   MAXVAL(    (    s-   lib/python2.7/site-packages/_pytest/tmpdir.pyt   _mk_tmp£   s
    
c         C` s   t  j j |   S(   s+  Return a temporary directory path object
    which is unique to each test function invocation,
    created as a sub directory of the base temporary
    directory.  The returned object is a `py.path.local`_
    path object.

    .. _`py.path.local`: https://py.readthedocs.io/en/latest/path.html
    (   RN   R   RO   (   t   tmp_path(    (    s-   lib/python2.7/site-packages/_pytest/tmpdir.pyR   «   s    
c         C` s   t  |  |  S(   s#  Return a temporary directory path object
    which is unique to each test function invocation,
    created as a sub directory of the base temporary
    directory.  The returned object is a :class:`pathlib.Path`
    object.

    .. note::

        in python < 3.6 this is a pathlib2.Path
    (   Rm   (   Rc   Re   (    (    s-   lib/python2.7/site-packages/_pytest/tmpdir.pyRn   Έ   s    (!   R>   t
   __future__R    R   R   R   Ri   R1   RI   R?   RN   R   R]   t   pathlibR   R   R   R   R   t   _pytest.monkeypatchR   t   st   objectR	   RD   R3   R`   t   fixtureRd   Re   Rm   R   Rn   (    (    (    s-   lib/python2.7/site-packages/_pytest/tmpdir.pyt   <module>   s8   	=	!			