ó
…¾^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	 d d d „  ƒ  YZ
 d „  Z e
 Z d „  Z e j d	 d
 ƒ d „  ƒ Z e j d „  ƒ Z d S(   sA    support for providing temporary directories to test functions.  i    (   t   absolute_importt   divisiont   print_functionN(   t   MonkeyPatcht   TempdirFactoryc           B` sA   e  Z d  Z d „  Z d d „ Z e d „ Z 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.
    c         C` s"   | |  _  | j j d ƒ |  _ d  S(   Nt   tmpdir(   t   configt   tracet   get(   t   selfR   (    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/tmpdir.pyt   __init__   s    	i   c         C` s   |  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.
        t   dir(   t   getbasetempt   ensure(   R	   t   stringR   (    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/tmpdir.pyt
   ensuretemp   s    c      	   C` sb   |  j  ƒ  } | s$ | j | ƒ } n* t j j j d | d d d | d d ƒ } |  j d | ƒ | 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   prefixt   keepi    t   rootdirt   lock_timeoutt   mktempN(   R   t   mkdirt   pyt   patht   localt   make_numbered_dirt   NoneR   (   R	   t   basenamet   numberedt   basetempt   p(    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/tmpdir.pyR      s    c         C` sÿ   y |  j  SWní t k
 rú |  j j j } | rh t j j | ƒ } | j ƒ  r[ | j	 ƒ  n  | j
 ƒ  nk t j j j ƒ  } t ƒ  } | rŸ | j d | ƒ } n | } | j d d ƒ t j j j d d d | ƒ } | j ƒ  |  _  } |  j d | ƒ | SXd S(	   s"    return base temporary directory. s   pytest-of-%sR   i   R   s   pytest-R   s   new basetempN(   t	   _basetempt   AttributeErrorR   t   optionR   R   R   R   t   checkt   removeR   t   get_temproott   get_usert   joinR   R   t   realpathR   (   R	   R   t   temproott   userR   t   t(    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/tmpdir.pyR   -   s(    		c         C` s   |  j  d ƒ d  S(   Nt   finish(   R   (   R	   (    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/tmpdir.pyR+   H   s    (	   t   __name__t
   __module__t   __doc__R
   R   t   TrueR   R   R+   (    (    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/tmpdir.pyR      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   (   R0   (    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/tmpdir.pyR%   L   s
    c         C` sj   t  ƒ  } t |  ƒ } |  j j | j | j g ƒ | 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   _tmpdirhandlert   raisingR   N(
   R   R   t   _cleanupt   extendt   undoR+   t   setattrt   Falset   pytestR   (   R   t   mpR*   (    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/tmpdir.pyt   pytest_configure[   s
    	t   scopet   sessionc         C` s
   |  j  j S(   s;   Return a TempdirFactory instance for the test session.
    (   R   R4   (   t   request(    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/tmpdir.pyt   tmpdir_factoryi   s    c         C` s_   |  j  j } t j d d | ƒ } d } t | ƒ | k rF | |  } n  | j | d 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 `py.path.local`_
    path object.
    s   [\W]t   _i   R   (   t   nodet   namet   ret   subt   lenR   R/   (   R@   RA   RD   t   MAXVALt   x(    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/tmpdir.pyR   p   s    (    (   R.   t
   __future__R    R   R   RE   R;   R   t   _pytest.monkeypatchR   R   R%   t   TempdirHandlerR=   t   fixtureRA   R   (    (    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/tmpdir.pyt   <module>   s   A		