
^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 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 m Z d d l m Z d d l Z d d l Z d d l m Z m Z d d	 l m Z d
   Z d   Z d e f d     YZ  i d d 6d d 6d d 6d d 6d d 6d d 6d d 6Z! i  d  Z" e j# d d d d d d d g  d     Z$ e j# d!    Z% d" f  d#     YZ& d$   Z' d% f  d&     YZ( d' f  d(     YZ) e j# d)    Z* e j# d* d+  d,    Z+ e j# d-    Z, e	 j- d.  Z. d/ f  d0     YZ/ d1 f  d2     YZ0 d3   Z1 d4 f  d5     YZ2 d+ f  d6     YZ3 d S(7   sF    (disabled by default) support for testing pytest and pytest plugins. i    (   t   absolute_importt   divisiont   print_functionN(   t   fnmatch(   t   WeakKeyDictionary(   t   MultiCapturet
   SysCapture(   t   Source(   t   Sessiont   EXIT_OK(   t   AssertionRewritingHookc      
   C` sN   |  j  d d d d d d t d d |  j  d	 d d
 d d d d d d d  S(   Ns   --lsoft   actiont
   store_truet   destt   lsoft   defaultt   helps"   run FD checks if lsof is availables   --runpytestt	   inprocesst	   runpytestt   choicest
   subprocesssY   run pytest sub runs in tests using an 'inprocess' or 'subprocess' (python -m main) method(   R   s
   subprocess(   t	   addoptiont   False(   t   parser(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   pytest_addoption   s    c         C` s   y t  WnA t k
 rK t j j t j j d   a  t  j d d  a  n X|  j	 d  r t
   } | j   r |  j j |  q n  d  S(   Nt   ocs	   $py.classs   .pyR   (   t   _pytest_fullpatht	   NameErrort   ost   patht   abspatht   pytestt   __file__t   rstript   replacet   getvaluet   LsofFdLeakCheckert   matching_platformt   pluginmanagert   register(   t   configt   checker(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   pytest_configure%   s    	R$   c           B` sM   e  Z d    Z d   Z d   Z d   Z e j d e d e  d    Z	 RS(   c         C` s   |  j    } |  j |  } | S(   N(   t
   _exec_lsoft   _parse_lsof_output(   t   selft   outt
   open_files(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   get_open_files5   s    c         C` s    t  j   } t j j d |  S(   Ns   lsof -Ffn0 -p %d(   R   t   getpidt   pyt   processt   cmdexec(   R-   t   pid(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR+   :   s    c         C` s   d   } g  } xv | j  d  D]e } | |  r | j  d  } | d d } | d d } | j d  r | j | | f  q q q W| S(   Nc         S` s=   |  j  d  o< d |  k o< d |  k o< d |  k o< d |  k S(   Nt   ft   deletedt   memt   txtt   cwd(   t
   startswith(   t   line(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   isopen?   s    s   
t    i    i   t   /(   t   splitR;   t   append(   R-   R.   R=   R/   R<   t   fieldst   fdt   filename(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR,   >   s    	c         C` s@   y t  j j d  Wn! t  j j j t f k
 r7 t SXt Sd  S(   Ns   lsof -v(   R2   R3   R4   t   Errort   UnicodeDecodeErrorR   t   True(   R-   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR%   O   s
    t   hookwrappert   tryfirstc   	      c` s  |  j    } d  Vt t d  r- t j   n  |  j    } t g  | D] } | d ^ qC  t g  | D] } | d ^ qc  } g  | D] } | d | k r | ^ q } | rg  } | j d t |   | j g  | D] } t	 |  ^ q  | j d  | j g  | D] } t	 |  ^ q	 | j d  | j g  | D] } t	 |  ^ q< | j | d  | j d | j
  | j d  | j d d	 j |   n  d  S(
   Nt   pypy_version_infoi    s   ***** %s FD leakage detecteds   *** Before:s
   *** After:s   *** function %s:%s: %s s   See issue #2366t    s   
(   R0   t   hasattrt   syst   gct   collectt   setRA   t   lent   extendt   strt   locationt   warnt   join(	   R-   t   itemt   lines1t   lines2t   tt   new_fdst   leaked_filest   errorR6   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   pytest_runtest_protocolZ   s&    D)&&&(
   t   __name__t
   __module__R0   R+   R,   R%   R   t   hookimplRG   R^   (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR$   4   s
   				s   C:\Python27\python.exes	   python2.7s   C:\Python26\python.exes	   python2.6s   C:\Python31\python.exes	   python3.1s   C:\Python32\python.exes	   python3.2s   C:\Python33\python.exes	   python3.3s   C:\Python34\python.exes	   python3.4s   C:\Python35\python.exes	   python3.5c         C` s   y | |  SWn t  k
 r t j j j |   } | r d d  l } | j t |  d g d t d | j	 } | j
   \ } } |  d k r | s d | k r d  } n  d | k r d  } q q | j d k r d  } q n  | | |  <| SXd  S(   Ni    s	   --versiont   universal_newlinest   stderrt   jythons   2.5s   2.5.2(   t   KeyErrorR2   R   t   localt   sysfindR   t   PopenRS   RG   t   PIPEt   communicatet   Nonet
   returncode(   t   namet   cachet
   executableR   t   popenR.   t   err(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   getexecutable}   s$    	
t   paramst   pypyt   pypy3c         C` s   |  j  } t |  } | d  k r t j d k rp t j | d   } | rp t j j	 |  } | j
   rm | Sqp n  t j d | f  n  | S(   Nt   win32s   no suitable %s found(   t   paramRr   Rk   RM   t   platformt   winpymapt   getR2   R   Rf   t   checkR   t   skip(   t   requestRm   Ro   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt	   anypython   s    	
c         C` s
   t  |   S(   s    Return a helper which offers a gethookrecorder(hook)
    method which returns a HookRecorder instance which helps
    to make assertions about called hooks.
    (   t	   PytestArg(   R}   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   _pytest   s    R   c           B` s   e  Z d    Z d   Z RS(   c         C` s   | |  _  d  S(   N(   R}   (   R-   R}   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   __init__   s    c         C` s&   t  | j  } |  j j | j  | S(   N(   t   HookRecordert   _pmR}   t   addfinalizert   finish_recording(   R-   t   hookt   hookrecorder(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   gethookrecorder   s    (   R_   R`   R   R   (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR      s   	c         C` s'   g  |  D] } | d d k r | ^ q S(   s?   Only return names from iterator l without a leading underscore.i    t   _(    (   t   lt   x(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   get_public_names   s    t
   ParsedCallc           B` s   e  Z d    Z d   Z RS(   c         C` s   |  j  j |  | |  _ d  S(   N(   t   __dict__t   updatet   _name(   R-   Rm   t   kwargs(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR      s    c         C` s'   |  j  j   } | d =d |  j | f S(   NR   s   <ParsedCall %r(**%r)>(   R   t   copyR   (   R-   t   d(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   __repr__   s    (   R_   R`   R   R   (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR      s   	R   c           B` s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d d  Z	 d	 d d d
  Z d d  Z d   Z d   Z d   Z d d d d  Z d   Z RS(   s   Record all hooks called in a plugin manager.

    This wraps all the hook calls in the plugin manager, recording
    each call before propagating the normal calls.

    c         ` sC   |   _  g    _   f d   } d   } | j | |    _ d  S(   Nc         ` s     j  j t |  |   d  S(   N(   t   callsRA   R   (   t	   hook_namet
   hook_implsR   (   R-   (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   before   s    c         S` s   d  S(   N(    (   t   outcomeR   R   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   after   s    (   t   _pluginmanagerR   t   add_hookcall_monitoringt   _undo_wrapping(   R-   R&   R   R   (    (   R-   s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR      s
    			c         C` s   |  j    d  S(   N(   R   (   R-   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR      s    c         C` sG   t  | t  r | j   } n  g  |  j D] } | j | k r( | ^ q( S(   N(   t
   isinstanceRS   R@   R   R   (   R-   t   namest   call(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   getcalls   s    c   	      C` s  t  } d } t |  } t j d  j } x | r| j d  \ } } x t |  j |  D] \ } } | j | k r t	 d | |  t
 | | | j  r t	 d t |  d |  n t	 d t |  d |  q\ | | d 7} Pn  t	 d | d	 |  q\ Wt j d
 | | f  q- Wd  S(   Ni    i   t	   NAMEMATCHt   CHECKERMATCHs   ->t   NOCHECKERMATCHt   -t   NONAMEMATCHt   withs   could not find %r check %r(   RG   t   listRM   t	   _getframet   f_localst   popt	   enumerateR   R   t   printt   evalR   t   reprR   t   fail(	   R-   t   entriest   __tracebackhide__t   it
   backlocalsRm   R{   t   indR   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   assert_contains   s"    	 c         C` s   t  } x: t |  j  D]) \ } } | j | k r |  j | =| Sq Wd | f g } | j g  |  j D] } d t |  ^ qc  t j d j |   d  S(   Ns   could not find call %r, in:s     %ss   
(	   RG   R   R   R   RR   RS   R   R   RV   (   R-   Rm   R   R   R   t   linesR   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   popcall   s    
-c         C` s;   |  j  |  } t |  d k s3 t | | f   | d S(   Ni   i    (   R   RQ   t   AssertionError(   R-   Rm   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   getcall   s    $s-   pytest_runtest_logreport pytest_collectreportc         C` s#   g  |  j  |  D] } | j ^ q S(   N(   R   t   report(   R-   R   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt
   getreports  s    RK   c         C` s  g  } x |  j  d |  D] } y) | rG | j d k rG | j rG w n  Wn t k
 r[ n X| r t | d d	  | k r q n  | s | | j j d  k r | j |  q q W| s t	 d | f   n  t
 |  d k r t	 d | | f   n  | d S(
   s6    return a testreport whose dotted import path matches R   R   t   whens   ::s?   could not find test report matching %r: no test reports at all!i   s+   found 2 or more testreports matching %r: %si    N(   R   R   t   passedt   AttributeErrort   getattrRk   t   nodeidR@   RA   t
   ValueErrorRQ   (   R-   t	   inamepartR   R   R   t   rep(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   matchreport
  s$    
c         C` s)   g  |  j  |  D] } | j r | ^ q S(   N(   R   t   failed(   R-   R   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   getfailures!  s    c         C` s   |  j  d  S(   Nt   pytest_collectreport(   R   (   R-   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   getfailedcollections%  s    c         C` s   g  } g  } g  } x} |  j  d  D]l } | j r\ t | d d   d k r | j |  q q" | j ru | j |  q" | j r" | j |  q" q" W| | | f S(   Ns-   pytest_collectreport pytest_runtest_logreportR   R   (   R   R   R   Rk   RA   t   skippedR   (   R-   R   R   R   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   listoutcomes(  s    				c         C` s#   g  |  j    D] } t |  ^ q S(   N(   R   RQ   (   R-   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   countoutcomes7  s    i    c         C` sa   |  j    \ } } } | t |  k s- t  | t |  k sE t  | t |  k s] t  d  S(   N(   R   RQ   R   (   R-   R   R   R   t
   realpassedt   realskippedt
   realfailed(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   assertoutcome:  s    c         C` s   g  |  j  (d  S(   N(   R   (   R-   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   clear@  s    N(   R_   R`   t   __doc__R   R   R   R   R   R   R   Rk   R   R   R   R   R   R   R   (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR      s    					
				c         C` s   t    S(   N(   t   LineComp(   R}   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   linecompD  s    Rm   t   LineMatcherc         C` s   t  S(   N(   R   (   R}   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   LineMatcher_fixtureI  s    c         C` s   t  |  |  S(   N(   t   Testdir(   R}   t   tmpdir_factory(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   testdirN  s    s   (\d+) ([\w-]+)t	   RunResultc           B` s2   e  Z d  Z d   Z d   Z d d d d  Z RS(   s  The result of running a command.

    Attributes:

    :ret: The return value.
    :outlines: List of lines captured from stdout.
    :errlines: List of lines captures from stderr.
    :stdout: :py:class:`LineMatcher` of stdout, use ``stdout.str()`` to
       reconstruct stdout or the commonly used
       ``stdout.fnmatch_lines()`` method.
    :stderrr: :py:class:`LineMatcher` of stderr.
    :duration: Duration in seconds.

    c         C` sF   | |  _  | |  _ | |  _ t |  |  _ t |  |  _ | |  _ d  S(   N(   t   rett   outlinest   errlinesR   t   stdoutRc   t   duration(   R-   R   R   R   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR   c  s    			c         C` s   xl t  |  j  D][ } d | k r t j |  } | rk i  } x$ | D] \ } } t |  | | <qD W| Sq q Wt d   d S(   ss    Return a dictionary of outcomestring->num from parsing
        the terminal output that the test process produced.t   secondss    Pytest terminal report not foundN(   t   reversedR   t   rex_outcomet   findallt   intR   (   R-   R<   t   outcomesR   t   numt   cat(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   parseoutcomesk  s    i    c         C` sj   |  j    } | | j d d  k s* t  | | j d d  k sH t  | | j d d  k sf t  d S(   s    assert that the specified outcomes appear with the respective
        numbers (0 means it didn't occur) in the text output from a test run.R   i    R   R   N(   R   Rz   R   (   R-   R   R   R   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   assert_outcomesx  s    (   R_   R`   R   R   R   R   (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR   T  s   		R   c           B` s  e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d d  Z	 d	   Z
 d
   Z d   Z d   Z d   Z d   Z d/ d  Z d   Z d   Z d   Z e Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d d   Z" d!   Z# d0 e$ d"  Z% d#   Z& d$   Z' d%   Z( d&   Z) d'   Z* d(   Z+ d)   Z, d*   Z- d+   Z. d, d-  Z/ d, d.  Z0 RS(1   s  Temporary test directory with tools to test/run pytest itself.

    This is based on the ``tmpdir`` fixture but provides a number of
    methods which aid with testing pytest itself.  Unless
    :py:meth:`chdir` is used all methods will use :py:attr:`tmpdir` as
    current working directory.

    Attributes:

    :tmpdir: The :py:class:`py.path.local` instance of the temporary
       directory.

    :plugins: A list of plugins to use with :py:meth:`parseconfig` and
       :py:meth:`runpytest`.  Initially this is an empty list but
       plugins can be added to the list.  The type of items to add to
       the list depend on the method which uses them so refer to them
       for details.

    c         C` s3  | |  _  t   |  _ | j d  } | j j } xO t d  D]A } y | j | t |   } Wn t	 j
 j k
 r| q= n XPq= W| |  _ g  |  _ t t j  t t j  f |  _ t t j  |  _ |  j   |  j  j |  j  |  j  j j d  } | d k r|  j |  _ n | d k r/|  j |  _ n  d  S(   NR   id   s   --runpytestR   R   (   R}   R   t   _mod_collectionst
   ensuretempt   functionR_   t   ranget   mkdirRS   R2   R]   t   EEXISTt   tmpdirt   pluginsR   RM   R   t	   meta_patht   _savesyspathRP   t   modulest   _savemodulekeyst   chdirR   t   finalizeR(   t	   getoptiont   runpytest_inprocesst   _runpytest_methodt   runpytest_subprocess(   R-   R}   R   t   basetmpRm   R   R   t   method(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR     s*    			!
c         C` s   d |  j  f S(   Ns   <Testdir %r>(   R   (   R-   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR     s    c         C` sD   |  j  \ t j (t j (t |  d  r6 |  j j   n  |  j   d S(   s	  Clean up global state artifacts.

        Some methods modify the global interpreter state and this
        tries to clean this up.  It does not remove the temporary
        directory however so it can be looked at after the test run
        has finished.

        t   _olddirN(   R   RM   R   R   RL   R   R   t   delete_loaded_modules(   R-   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR     s    	c         C` sF   x? t  t j  j |  j  D]" } | j d  s t j | =q q Wd S(   s   Delete modules that have been loaded during a test.

        This allows the interpreter to catch module changes in case
        the module is re-imported.
        t   zopeN(   RP   RM   R   t
   differenceR   R;   (   R-   Rm   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR     s    "c         C` s@   t  | d  s t  t |  | _ } |  j j | j  | S(   s:   Create a new :py:class:`HookRecorder` for a PluginManager.t   reprec(   RL   R   R   R  R}   R   R   (   R-   R&   R  (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   make_hook_recorder  s    c         C` s.   |  j  j   } t |  d  s* | |  _ n  d S(   sb   Cd into the temporary directory.

        This is done automatically upon instantiation.

        R   N(   R   R   RL   R   (   R-   t   old(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR     s    s   utf-8c         C` sX  t  | j    } | rz t j j d  j t t j j |   t j j d  } |  j j j	 } | j
 d | | f  n  d  } x | D] \ }	 }
 |  j j |	  j d |  } | j   j   t |
  } d d  } d j g  | j D] } | |  ^ q  } t j j |  } | j   j |  } | j | d  | d  k r | } q q W| S(   Ns   
i    t   exts   utf-8c         S` s1   t  j j |   r- t  j j |  d | }  n  |  S(   Nt   encoding(   R2   t   builtint   _isbytest   _totext(   t   sR  (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt	   my_totext  s    t   wb(   R   t   itemsR2   R  R	  RV   t   mapR}   R   R_   t   insertRk   R   t   newt   dirpatht
   ensure_dirR   R   t   stript   encodet   write(   R-   R  t   argsR   R  R  t   sourcet   basenameR   Rm   t   valuet   pR  R<   t   source_unicodet   content(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt	   _makefile  s&    (+c         O` s   |  j  | | |  S(   s  Create a new file in the testdir.

        ext: The extension the file should use, including the dot.
           E.g. ".py".

        args: All args will be treated as strings and joined using
           newlines.  The result will be written as contents to the
           file.  The name of the file will be based on the test
           function requesting this fixture.
           E.g. "testdir.makefile('.txt', 'line1', 'line2')"

        kwargs: Each keyword is the name of a file, while the value of
           it will be written as contents of the file.
           E.g. "testdir.makefile('.ini', pytest='[pytest]
addopts=-rs
')"

        (   R  (   R-   R  R  R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   makefile  s    c         C` s   |  j  d |  S(   s2   Write a contest.py file with 'source' as contents.t   conftest(   t
   makepyfile(   R-   R  (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   makeconftest  s    c         C` s   |  j  d d | S(   s/   Write a tox.ini file with 'source' as contents.s   .init   tox(   R  (   R-   R  (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   makeini  s    c         C` s#   |  j  |  } t j j |  d S(   s7   Return the pytest section from the tox.ini config file.R   (   R#  R2   t	   iniconfigt	   IniConfig(   R-   R  R  (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt	   getinicfg  s    c         O` s   |  j  d | |  S(   s.   Shortcut for .makefile() with a .py extension.s   .py(   R  (   R-   R  R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR     s    c         O` s   |  j  d | |  S(   s/   Shortcut for .makefile() with a .txt extension.s   .txt(   R  (   R-   R  R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   maketxtfile  s    c         C` s?   | d k r |  j } n  t j j d t |   |  j   d S(   s~   Prepend a directory to sys.path, defaults to :py:attr:`tmpdir`.

        This is undone automatically after the test.
        i    N(   Rk   R   RM   R   R  RS   t"   _possibly_invalidate_import_caches(   R-   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   syspathinsert!  s    c         C` sD   y d d  l  } Wn t k
 r# n Xt | d  r@ | j   n  d  S(   Ni    t   invalidate_caches(   t	   importlibt   ImportErrorRL   R*  (   R-   R+  (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR(  .  s    c         C` s   |  j  j |  S(   s   Create a new (sub)directory.(   R   R   (   R-   Rm   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR   8  s    c         C` s    |  j  |  } | j d  | S(   s   Create a new python package.

        This creates a (sub)directory with an empty ``__init__.py``
        file so that is recognised as a python package.

        s   __init__.py(   R   t   ensure(   R-   Rm   R  (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   mkpydir<  s    c         C` s   t  |  } d t |  k s$ t  t j j |  } | j j d |  | j t |  g d t	 d } | j j
 d | d t  | S(   s&  Return the collection node of a file.

        :param config: :py:class:`_pytest.config.Config` instance, see
           :py:meth:`parseconfig` and :py:meth:`parseconfigure` to
           create the configuration.

        :param arg: A :py:class:`py.path.local` instance of the file.

        s   ::t   sessiont   genitemsi    t
   exitstatus(   R   RS   R   R2   R   Rf   R   t   pytest_sessionstartt   perform_collectR   t   pytest_sessionfinishR	   (   R-   R(   t   argR/  R  t   res(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   getnodeH  s    
"c         C` sy   |  j  |  } t |  } | j j |  } | j j d |  | j | g d t d } | j j d | d t	  | S(   s  Return the collection node of a file.

        This is like :py:meth:`getnode` but uses
        :py:meth:`parseconfigure` to create the (configured) pytest
        Config instance.

        :param path: A :py:class:`py.path.local` instance of the file.

        R/  R0  i    R1  (
   t   parseconfigureR   t   fspatht   bestrelpathR   R2  R3  R   R4  R	   (   R-   R   R(   R/  R   R6  (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   getpathnodeZ  s    
c         C` s>   | d j  } g  } x$ | D] } | j | j |   q W| S(   s   Generate all test items from a collection node.

        This recurses into the collection node and returns a list of
        all the test items contained within.

        i    (   R/  RR   R0  (   R-   t   colitemsR/  t   resultt   colitem(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR0  l  s
    c         C` s1   |  j  |  } |  j j } | j   } | |  S(   s5  Run the "test_func" Item.

        The calling test instance (the class which contains the test
        method) must provide a ``.getrunner()`` method which should
        return a runner which can run the test protocol for a single
        item, like e.g. :py:func:`_pytest.runner.runtestprotocol`.

        (   t   getitemR}   t   instancet	   getrunner(   R-   R  RW   t   testclassinstancet   runner(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   runitemy  s    
c         G` s/   |  j  |  } t |  | g } |  j |   S(   s  Run a test module in process using ``pytest.main()``.

        This run writes "source" into a temporary file and runs
        ``pytest.main()`` on it, returning a :py:class:`HookRecorder`
        instance for the result.

        :param source: The source code of the test module.

        :param cmdlineargs: Any extra command line arguments to use.

        :return: :py:class:`HookRecorder` instance of the result.

        (   R   R   t
   inline_run(   R-   R  t   cmdlineargsR  R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   inline_runsource  s    c         G` sA   |  j  d |  } g  | j d  D] } | j ^ q" } | | f S(   s  Run ``pytest.main(['--collectonly'])`` in-process.

        Returns a tuple of the collected items and a
        :py:class:`HookRecorder` instance.

        This runs the :py:func:`pytest.main` function to run all of
        pytest inside the test process itself like
        :py:meth:`inline_run`.  However the return value is a tuple of
        the collection items and a :py:class:`HookRecorder` instance.

        s   --collect-onlyt   pytest_itemcollected(   RE  R   RW   (   R-   R  t   recR   R  (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   inline_genitems  s    %c   	      ` s7  t  j     f d   }  j j |  d   t  _ g   d d   f d     Y} | j d  ph g  } | j |    t j t |  d | }  j	   t
   d k r  j   } n d d d     Y} | | _ | d	 k r3| j d
  r3| j d  } | r3| d j j t k r3t    q3n  | S(   s  Run ``pytest.main()`` in-process, returning a HookRecorder.

        This runs the :py:func:`pytest.main` function to run all of
        pytest inside the test process itself.  This means it can
        return a :py:class:`HookRecorder` instance which gives more
        detailed results from then run then can be done by matching
        stdout/stderr from :py:meth:`runpytest`.

        :param args: Any command line arguments to pass to
           :py:func:`pytest.main`.

        :param plugin: (keyword-only) Extra plugin instances the
           ``pytest.main()`` instance should use.

        :return: A :py:class:`HookRecorder` instance.
        c           ` s     t  _ d  S(   N(   R
   t   _warn_already_imported(    (   t	   orig_warn(    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   revert  s    c          W` s   d  S(   N(   Rk   (   t   a(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   <lambda>  s    t   Collectc           ` s   e  Z    f d    Z RS(   c         ` s     j   j | j   d  S(   N(   RA   R  R&   (   R   R(   (   RI  R-   (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR*     s    (   R_   R`   R*   (    (   RI  R-   (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyRP    s   R   i   R  c           B` s   e  Z RS(    (   R_   R`   (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR    s   i   t   no_reraise_ctrlct   pytest_keyboard_interrupti(    (    (   R
   RK  R}   R   Rz   RA   R   t   mainR   R   RQ   R   R   R   t   excinfot   typet   KeyboardInterrupt(	   R-   R  R   RM  RP  R   R   R  R   (    (   RL  RI  R-   s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyRE    s&    	
	c   	      ` s8  | j  d  r |  j   n  t j   } t d t  } | j   zv y |  j | |   } WnY t k
 r   d d   f d     Y} n. t k
 r t	 j
   d d	 d     Y} n XWd | j   \ } } | j   t j j |  t j j |  Xt | j | j d  | j d  t j   |  } | | _ | S(
   sv    Return result of running pytest in-process, providing a similar
        interface to what self.runpytest() provides. R)  t   CaptureR  c           ` s   e  Z   j d  Z RS(   i    (   R_   R`   R  R   (    (   t   e(    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR    s   c           B` s   e  Z d  Z RS(   i   (   R_   R`   R   (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR    s   Ns   
(    (    (   Rz   R)  t   timeR   R   t   start_capturingRE  t
   SystemExitt	   Exceptiont	   tracebackt	   print_exct
   readouterrt   stop_capturingRM   R   R  Rc   R   R   R@   R  (	   R-   R  R   t   nowt   captureR  R.   Rq   R6  (    (   RX  s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR     s,    


		c         O` s   |  j  |  } |  j | |   S(   s    Run pytest inline or in a subprocess, depending on the command line
        option "--runpytest" and return a :py:class:`RunResult`.

        (   t   _ensure_basetempR   (   R-   R  R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR     s    c         C` sj   g  | D] } t  |  ^ q } xD | D] } t  |  j d  r& Pq& q& W| j d |  j j d   | S(   Ns
   --basetemps   --basetemp=%st   basetemp(   RS   R;   RA   R   R  (   R-   R  R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyRc  
  s    c         G` sJ   |  j  |  } d d l } | j j | |  j  } |  j j | j  | S(   s  Return a new pytest Config instance from given commandline args.

        This invokes the pytest bootstrapping code in _pytest.config
        to create a new :py:class:`_pytest.core.PluginManager` and
        call the pytest_cmdline_parse hook to create new
        :py:class:`_pytest.config.Config` instance.

        If :py:attr:`plugins` has been populated they should be plugin
        modules which will be registered with the PluginManager.

        i    N(   Rc  t   _pytest.configR(   t   _prepareconfigR   R}   R   t   _ensure_unconfigure(   R-   R  R   R(   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   parseconfig  s
    c         G` s0   |  j  |   } | j   |  j j | j  | S(   s   Return a new pytest configured Config instance.

        This returns a new :py:class:`_pytest.config.Config` instance
        like :py:meth:`parseconfig`, but also calls the
        pytest_configure hook.

        (   Rh  t   _do_configureR}   R   Rg  (   R-   R  R(   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR8  +  s    
t	   test_funcc         C` sV   |  j  |  } x! | D] } | j | k r | Sq Wd sR t d | | | f   d S(   sv  Return the test item for a test function.

        This writes the source to a python file and runs pytest's
        collection on the resulting module, returning the test item
        for the requested function name.

        :param source: The module source.

        :param funcname: The name of the test function for which the
           Item must be returned.

        i    s)   %r item not found in module:
%s
items: %sN(   t   getitemsRm   R   (   R-   R  t   funcnameR  RW   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR?  8  s    c         C` s   |  j  |  } |  j | g  S(   s   Return all test items collected from the module.

        This writes the source to a python file and runs pytest's
        collection on the resulting module, returning all test items
        contained within.

        (   t   getmodulecolR0  (   R-   R  t   modcol(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyRk  L  s    c         C` sy   i t  |  j   |  j j j 6} |  j |   } | rJ |  j d d  n  |  j | |  |  _ } |  j | |  } | S(   s  Return the module collection node for ``source``.

        This writes ``source`` to a file using :py:meth:`makepyfile`
        and then runs the pytest collection on it, returning the
        collection node for the test module.

        :param source: The source code of the module to collect.

        :param configargs: Any extra arguments to pass to
           :py:meth:`parseconfigure`.

        :param withinit: Whether to also write a ``__init__.py`` file
           to the temporary directory to ensure it is a package.

        R   t   #(	   R   R  R}   R   R_   R   R8  R(   R7  (   R-   R  t
   configargst   withinitt   kwR   R(   t   node(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyRm  W  s    "c         C` sZ   | |  j  k r+ t | j    |  j  | <n  x( |  j  | D] } | j | k r9 | Sq9 Wd S(   sC  Return the collection node for name from the module collection.

        This will search a module collection node for a collection
        node matching the given name.

        :param modcol: A module collection node, see
           :py:meth:`getmodulecol`.

        :param name: The name of the node to return.

        N(   R   R   RO   Rm   (   R-   Rn  Rm   R>  (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   collect_by_namep  s
    c         K` sr   t  j j   } t  j j t d t t  j    | j	 d d  g   | d <| | d <t
 j | d | d | | S(   s   Invoke subprocess.Popen.

        This calls subprocess.Popen making sure the current working
        directory is the PYTHONPATH.

        You probably want to use :py:meth:`run` instead.

        t
   PYTHONPATHRK   t   envR   Rc   N(   R   t   environR   t   pathsepRV   t   filterRk   RS   t   getcwdRz   R   Rh   (   R-   t   cmdargsR   Rc   Rr  Rv  (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyRp     s    	.
c         G` s   |  j  |   S(   s   Run a command with arguments.

        Run a process using subprocess.Popen saving the stdout and
        stderr.

        Returns a :py:class:`RunResult`.

        (   t   _run(   R-   R{  (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   run  s    	c      	   G` s  g  | D] } t  |  ^ q } |  j j d  } |  j j d  } t d d j |   t d t  t j j     t j t  |  d d d } t j t  |  d d d } zF t	 j	   } |  j
 | d | d | d	 t j d
 k } | j   }	 Wd  | j   | j   Xt j t  |  d d d } t j t  |  d d d } z( | j   j   }
 | j   j   } Wd  | j   | j   X|  j |
 t j  |  j | t j  t |	 |
 | t	 j	   |  S(   NR   Rc   s   running:t    s        in:t   wR  t   utf8t	   close_fdsRv   t   r(   RS   R   RV   R   R2   R   Rf   t   codecst   openRY  Rp   RM   Rx   t   waitt   closet   readt
   splitlinest   _dump_linesR   Rc   R   (   R-   R{  R   t   p1t   p2t   f1t   f2Ra  Rp   R   R.   Rq   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR|    s0    

c         C` sN   y% x | D] } t  | d | q
 WWn" t k
 rI t  d | f  n Xd  S(   Nt   files(   couldn't print to %s because of encoding(   R   t   UnicodeEncodeError(   R-   R   t   fpR<   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR    s
    c         C` s   t  j t f S(   N(   RM   Ro   R   (   R-   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   _getpytestargs  s    c         C` s   |  j  t j |  S(   sk   Run a python script using sys.executable as interpreter.

        Returns a :py:class:`RunResult`.
        (   R}  RM   Ro   (   R-   t   script(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt	   runpython  s    c         C` s   |  j  t j d |  S(   s8   Run python -c "command", return a :py:class:`RunResult`.s   -c(   R}  RM   Ro   (   R-   t   command(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   runpython_c  s    c         O` s   t  j j j d d d d d |  j  } d | f | } g  |  j D] } t | t  rB | ^ qB } | r d | d f | } n  |  j	   | } |  j
 |   S(	   s  Run pytest as a subprocess with given arguments.

        Any plugins added to the :py:attr:`plugins` list will added
        using the ``-p`` command line option.  Addtionally
        ``--basetemp`` is used put any temporary files and directories
        in a numbered directory prefixed with "runpytest-" so they do
        not conflict with the normal numberd pytest location for
        temporary files and directories.

        Returns a :py:class:`RunResult`.

        t   prefixs
   runpytest-t   keept   rootdirs   --basetemp=%ss   -pi    N(   R2   R   Rf   t   make_numbered_dirRk   R   R   R   RS   R  R}  (   R-   R  R   R  R   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR     s    +g      $@c         C` sV   |  j  j d  } d j t t |  j     } d | | | f } |  j | d | S(   s   Run pytest using pexpect.

        This makes sure to use the right pytest and sets up the
        temporary directory locations.

        The pexpect child is returned.

        s   temp-pexpectR~  s   %s --basetemp=%s %st   expect_timeout(   R   R   RV   R  RS   R  t   spawn(   R-   t   stringR  Rd  t   invoket   cmd(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   spawn_pytest  s    	c         C` s   t  j d d  } t t d  rC d t j   k rC t  j d  n  t j j d  re t  j d  n  |  j	 j
 d  j d	  } | j | d
 | } |  j j | j  | | _ | S(   sM   Run a command using pexpect.

        The pexpect child is returned.
        t   pexpects   3.0RJ   t   64s   pypy-64 bit not supportedt   freebsds)   pexpect does not work reliably on freebsds	   spawn.outR  t   logfile(   R   t   importorskipRL   RM   Rx   t   machineR|   R;   t   xfailR   RV   R  R  R}   R   R  t   timeout(   R-   R  R  R  R  t   child(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR    s    !	N(    (1   R_   R`   R   R   R   R   R   R  R   R  R  R!  R#  R&  R   R'  Rk   R)  R(  R   R.  R   R7  R;  R0  RD  RG  RJ  RE  R   R   Rc  Rh  R8  R?  Rk  R   Rm  Rt  Rp   R}  R|  R  R  R  R  R   R  R  (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR     sZ   						
							
									6	!														c         C` s=   y |  j  d  SWn% t k
 r8 d t j j |   f SXd  S(   Ns   utf-8s2   INTERNAL not-utf8-decodeable, truncated string:
%s(   t   decodeRF   R2   t   iot   saferepr(   R.   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt
   getdecoded
  s
    R   c           B` s   e  Z d    Z d   Z RS(   c         C` s   t  j j   |  _ d  S(   N(   R2   R  t   TextIOt   stringio(   R-   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR     s    c         C` sW   t  } |  j j   } |  j j d  |  j j d  | j d  } t |  j |  S(   so    assert that lines2 are contained (linearly) in lines1.
            return a list of extralines found.
        i    s   
(   RG   R  R#   t   truncatet   seekR@   R   t   fnmatch_lines(   R-   RY   R   t   valRX   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   assert_contains_lines  s    (   R_   R`   R   R  (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR     s   	c           B` s\   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z e	 d    Z
 d   Z RS(	   s   Flexible matching of text.

    This is a convenience class to test large texts like the output of
    commands.

    The constructor takes a list of lines without their trailing
    newlines, i.e. ``text.splitlines()``.

    c         C` s   | |  _  g  |  _ d  S(   N(   R   t   _log_output(   R-   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR   -  s    	c         C` s   d j  |  j  S(   s    Return the entire original text.s   
(   RV   R   (   R-   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyRS   1  s    c         C` sC   t  | t  r t |  } n  t  | t  r? | j   j } n  | S(   N(   R   RS   R   R  R   (   R-   RY   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt	   _getlines5  s
    c         C` s   |  j  |  } xw | D]o } xf |  j D]; } | | k sG t | |  r& |  j d t |   Pq& q& W|  j d |  t |  j   q Wd S(   s   Check lines exist in the output.

        The argument is a list of lines which have to occur in the
        output, in any order.  Each line can contain glob whildcards.

        s	   matched: s   line %r not found in outputN(   R  R   R   t   _logR   R   t	   _log_text(   R-   RY   R<   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   fnmatch_lines_random<  s    c         C` s^   xG t  |  j  D]6 \ } } | | k s7 t | |  r |  j | d Sq Wt d |   d S(   ss   Return all lines following the given line in the text.

        The given line can contain glob wildcards.
        i   s   line %r not found in outputN(   R   R   R   R   (   R-   t   fnlineR   R<   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   get_lines_afterM  s    c         G` s'   |  j  j d j d   | D   d  S(   NR~  c         s` s   |  ] } t  |  Vq d  S(   N(   RS   (   t   .0R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pys	   <genexpr>X  s    (   R  RA   RV   (   R-   R  (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR  W  s    c         C` s   d j  |  j  S(   Ns   
(   RV   R  (   R-   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR  Z  s    c         C` s3  |  j  |  } |  j } d } g  } t } x| D] } t } x | r| j d  } | | k r| |  j d t |   Pnz t | |  r |  j d t |   |  j d t |   Pn; | s |  j d t |   t } n  |  j d t |   | j	 |  qA W|  j d | f  t
 j |  j  q2 Wd S(	   s	  Search the text for matching lines.

        The argument is a list of lines which have to match and can
        use glob wildcards.  If they do not match an pytest.fail() is
        called.  The matches and non-matches are also printed on
        stdout.

        i    s   exact match:s   fnmatch:s      with:s   nomatch:s       and:s   remains unmatched: %rN(   R  R   Rk   RG   R   R   R  R   R   RA   R   R   R  (   R-   RY   RX   t   nextlinet
   extralinesR   R<   t   nomatchprinted(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR  ^  s.    	
		(   R_   R`   R   R   RS   R  R  R  R  t   propertyR  R  (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyR   "  s   						
	(4   R   t
   __future__R    R   R   R  RN   R   Rx   t   reR   RM   RY  R]  R   t   weakrefR   t   _pytest.captureR   R   t   _pytest._codeR   R2   R   t   _pytest.mainR   R	   t   _pytest.assertion.rewriteR
   R   R*   t   objectR$   Ry   Rr   t   fixtureR~   R   R   R   R   R   R   R   R   t   compileR   R   R   R  R   R   (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pytester.pyt   <module>   s`   		?

	.  	