ó
@¾^Yc           @   sž  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 m Z m Z d  d l	 m	 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 d „  Z e j d „  ƒ Z e j d „  ƒ Z d d d „  ƒ  YZ d d d „  ƒ  YZ e j d „  ƒ Z e j d „  ƒ Z d d d „  ƒ  YZ d „  Z d d  d „  ƒ  YZ d d! d „  ƒ  YZ  e j d „  ƒ Z! d „  Z" d S("   iÿÿÿÿN(   t   _isbytest   _istextt   print_(   t   fnmatchi   (   t   parseconfig(   t
   VirtualEnv(   t   Action(   t	   ResultLogc           C   s<   d t  j k r t  j d =n  d t  j k r8 t  j d =n  d  S(   Nt   TOXENVt
   HUDSON_URL(   t   ost   environ(    (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   pytest_configure   s    c         C   s#   |  j  d d d d d d d ƒd  S(   Ns   --no-networkt   actiont
   store_truet   destt
   no_networkt   helps!   don't run tests requiring network(   t	   addoption(   t   parser(    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   pytest_addoption   s    c           C   s   d t  j S(   Ns   tox comes from: %r(   t   toxt   __file__(    (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   pytest_report_header   s    c            s   d  d ‡  f d † } | S(   Nc            s~   | d  k r |  } g  }  n  t j j j | ƒ } ˆ  j d ƒ } | j | ƒ ˆ  j ƒ  } z t |  d | ƒSWd  | j ƒ  Xd  S(   Ns   tox.init   plugins(	   t   Nonet   pyt   stdt   textwrapt   dedentt   joint   writet   chdirR   (   t   argst   sourceR   t   st   pt   old(   t   tmpdir(    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt	   newconfig"   s    	(    (   R   (   t   requestR&   R'   (    (   R&   s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyR'       s    c         C   s)   |  j  j j r t j d ƒ n  t |  ƒ S(   Ns+   --no-network was specified, test cannot run(   t   configt   optionR   t   pytestt   skipt   Cmd(   R(   (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   cmd1   s    t   ReportExpectMockc           B   sP   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d e d „ Z d d „ Z	 RS(   c         C   s   g  |  _  d |  _ | |  _ d  S(   Niÿÿÿÿ(   t   _callst   _indext   session(   t   selfR2   (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   __init__9   s    		c         C   s   g  |  j  (d  S(   N(   R0   (   R3   (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   clear>   s    c            sE   ˆ  d d k r t  ˆ  ƒ ‚ n ˆ  d k r/ d S‡  ‡ f d †  } | S(   Ni    t   _t	   verbosityc             s.   ˆ j  j ˆ  f |  ƒ d ˆ j  d f GHd  S(   Ns   %siÿÿÿÿ(   R0   t   append(   R!   t   kwargs(   t   nameR3   (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   generic_reportH   s    (   t   AttributeError(   R3   R:   R;   (    (   R:   R3   s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   __getattr__A   s    c         G   sB   |  j  j d | | f ƒ d |  j  d f GHt |  j | | | ƒ S(   NR   s   %siÿÿÿÿ(   R0   R8   R   R2   (   R3   t   venvt   msgR!   (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyR   M   s    c         C   s“   t  } |  j d } xV | t |  j ƒ k  rk |  j | } | d } t | | ƒ r^ | |  _ | S| d 7} q Wt d | |  j d |  j f ƒ ‚ d  S(   Ni   i    s.   looking for %r, no reports found at >=%d in %r(   t   TrueR1   t   lenR0   R   t   LookupError(   R3   t   catt   __tracebackhide__t   newindext   callt   lcat(    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   getnextR   s    
	t   *c         C   sû   t  } | j d ƒ s" d | } n  x£ |  j t |  j ƒ k  rÇ y |  j | ƒ } Wn t k
 rd Pn Xx\ | d D]P } t | ƒ j d d ƒ } t	 | | ƒ rp | r¼ t
 d | | f ƒ ‚ n  d  Sqp Wq% W| s÷ t
 d | | |  j d |  j f ƒ ‚ n  d  S(   NRI   i   s   
t    s   found %s(%r), didn't expect its2   looking for %s(%r), no reports found at >=%d in %r(   R@   t
   startswithR1   RA   R0   RH   RB   t   strt   replaceR   t   AssertionError(   R3   RC   t   messagepatternt   invertRD   RF   t   lmsg(    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   expect`   s&    c         C   s   |  j  | | d t ƒS(   NRP   (   RR   R@   (   R3   RC   RO   (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt
   not_expectu   s    (
   t   __name__t
   __module__R4   R5   R=   R   RH   t   FalseRR   RS   (    (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyR/   8   s   					t	   pcallMockc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   sK   | d |  _  | d |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   Ni    i   (   t   arg0R!   t   cwdt   envt   stdoutt   stderrt   shell(   R3   R!   RY   RZ   R[   R\   R]   (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyR4   z   s    				c         C   s   d S(   Nt    (   R^   R^   (    (   R3   (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   communicateƒ   s    c         C   s   d  S(   N(    (   R3   (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   wait†   s    (   RT   RU   R4   R_   R`   (    (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyRW   y   s   			c            s3   d d l  m } d | f ‡  f d †  ƒ  Y} | ƒ  S(   Niÿÿÿÿ(   t   Sessiont   MockSessionc              sJ   e  Z ‡  f d  †  Z d „  Z d „  Z d „  Z d e d d d d „ Z RS(   c            s>   |  j  ƒ  ˆ  j d ƒ g  d ƒ |  _ t ƒ  |  _ g  |  _ d  S(   NR'   R^   (   t   _clearmockst   getfuncargvalueR)   R   t	   resultlogt   _actions(   R3   (   R(   (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyR4      s    
c         S   s   t  |  j j | d |  ƒS(   NR2   (   R   R)   t
   envconfigs(   R3   R:   (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   getenv•   s    c         S   s%   g  |  _  i  |  _ t |  ƒ |  _ d  S(   N(   t   _pcallst	   _spec2pkgR/   t   report(   R3   (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyRc   ˜   s    		c         S   s   d  S(   N(    (   R3   t   path(    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   make_emptydir   s    c   	      S   s/   t  | | | | | | ƒ } |  j j | ƒ | S(   N(   RW   Ri   R8   (	   R3   R!   RY   R]   t   universal_newlinesR[   R\   RZ   t   pm(    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   popen    s    N(	   RT   RU   R4   Rh   Rc   Rm   R   RV   Rp   (    (   R(   (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyRb   Ž   s   			(   t   tox.sessionRa   (   R(   Ra   Rb   (    (   R(   s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   mocksessionŠ   s    c            s7   |  j  d ƒ ‰  |  j  d ƒ ‰ d ‡  ‡ f d † } | S(   NRr   R'   c            s   ˆ |  | d | ƒˆ  _  ˆ  S(   NR   (   R)   (   R!   R"   R   (   Rr   R'   (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   newmocksession®   s    (    (   Rd   (   R(   Rs   (    (   Rr   R'   s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyRs   ©   s    R-   c           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   sA   | j  d ƒ |  _ | |  _ t j j ƒ  } |  j j | j ƒ d  S(   NR&   (   Rd   R&   R(   R   Rl   t   localt   addfinalizerR    (   R3   R(   t   current(    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyR4   µ   s    	c         C   s   | j  ƒ  d  S(   N(   R    (   R3   t   target(    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyR    »   s    c         K   sš   t  t j d ƒ s% t j j d ƒ n  t j j ƒ  } d j t	 d  t t j ƒ  ƒ | j d d ƒ g ƒ ƒ | d <| | d <t j j j | d | d | | S(	   Nt
   subprocesss   no subprocess modulet   :t
   PYTHONPATHR^   RZ   R[   R\   (   t   hasattrR   R   t   testR,   R
   R   t   copyR   t   filterR   RL   t   getcwdt   getRx   t   Popen(   R3   t   argvR[   R\   t   kwRZ   (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyRp   ¾   s    .
c      	   G   s¿  | d d k r3 t  j d  d k  r3 t j d ƒ n  g  | D] } t | ƒ ^ q: } t j j j t | d ƒ ƒ s t	 | d ƒ ‚ |  j
 j d ƒ } |  j
 j d ƒ } d t j ƒ  d	 j | ƒ f GH| j d
 ƒ } | j d
 ƒ } t j ƒ  } |  j | d | d | d t  j d k ƒ} | j ƒ  }	 | j ƒ  | j ƒ  | j d ƒ }
 t |
 ƒ j ƒ  }
 | j d ƒ } t | ƒ j ƒ  } d „  } | |
 t  j ƒ | | t  j ƒ t |	 |
 | t j ƒ  | ƒ S(   Ni    R   i   i   sf   can not run tests involving calling tox on python2.6. (and python2.6 is about to be deprecated anyway)R[   R\   s   %s$ %sRJ   t   wbt	   close_fdst   win32t   rbc         S   sO   y+ x$ |  D] } t  j j | d | ƒq
 WWn t k
 rJ d | f GHn Xd  S(   Nt   files(   couldn't print to %s because of encoding(   R   t   builtinR   t   UnicodeEncodeError(   t   linest   fpt   line(    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt
   dump_linesÞ   s
    (   i   i   (   t   syst   version_infoR+   R,   RL   R   Rl   Rt   t   sysfindRN   R&   R   R
   R   t   opent   timeRp   t   platformR`   t   closet   readt
   getdecodedt
   splitlinesR[   R\   t	   RunResult(   R3   R‚   t   xt   p1t   p2t   f1t   f2t   nowRp   t   rett   outt   errRŽ   (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   runÈ   s.    #/

	(   RT   RU   R4   R    Rp   R£   (    (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyR-   ´   s   			
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   decodet   UnicodeDecodeErrorR   t   iot   saferepr(   R¡   (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyR—   é   s
    R™   c           B   s   e  Z d  „  Z RS(   c         C   sF   | |  _  | |  _ | |  _ t | ƒ |  _ t | ƒ |  _ | |  _ d  S(   N(   R    t   outlinest   errlinest   LineMatcherR[   R\   t   duration(   R3   R    R¨   R©   R«   (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyR4   ò   s    			(   RT   RU   R4   (    (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyR™   ñ   s   Rª   c           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   R‹   (   R3   R‹   (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyR4   ü   s    c         C   s   d j  |  j ƒ S(   Ns   
(   R   R‹   (   R3   (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyRL   ÿ   s    c   	      C   s^  t  | t ƒ r$ t j j | ƒ } n  t  | t j j ƒ rK | j ƒ  j } n  d d l m } |  j } d  } g  } t	 } xà | D]Ø } t
 } xÉ | rC| j d ƒ } | | k rÅ t d t | ƒ ƒ Pnn | | | ƒ rþ t d t | ƒ ƒ t d t | ƒ ƒ Pn5 | s t d t | ƒ ƒ t	 } n  t d t | ƒ ƒ | j | ƒ q W| | k s~ t ‚ q~ Wd  S(	   Niÿÿÿÿ(   R   i    s   exact match:s   fnmatch:s      with:s   nomatch:s       and:(   t
   isinstanceRL   R   t   codet   Sourcet   stripR‹   R   R   R@   RV   t   popR   t   reprR8   RN   (	   R3   t   lines2R   t   lines1t   nextlinet
   extralinesRD   R   t   nomatchprinted(    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   fnmatch_lines  s4    
		(   RT   RU   R4   RL   R·   (    (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyRª   û   s   		c            s   d d ‡  f d † } | S(   s:    create a factory function for creating example projects. t   .c   
         s|  | d  k r i  } n  t |  ƒ s- t |  ƒ rm |  j d ƒ } t | ƒ d k r^ | j d ƒ n  | \ } } n |  \ } } ˆ  j | d d ƒ} t | | ƒ d | k rÅ t | i d t ƒ  d 6ƒ n  | | k r| j | d d ƒ} t | i i d | d 6| 6ƒ n  g  } x4 | j	 d	 „  ƒ D]  }	 | j d
 |	 j
 | ƒ ƒ q!Wt | i d j | ƒ d 6ƒ d | f GH| j ƒ  d  S(   Nt   -i   s   0.1t   dirs   setup.pys»  
                from setuptools import setup, find_packages
                setup(
                    name='%(name)s',
                    description='%(name)s project',
                    version='%(version)s',
                    license='MIT',
                    platforms=['unix', 'win32'],
                    packages=find_packages('%(src_root)s'),
                    package_dir={'':'%(src_root)s'},
                )
            s   __version__ = %rs   __init__.pyc         S   s   |  j  d d ƒ S(   NRˆ   i   (   t   check(   Rš   (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   <lambda>D  s    s
   include %ss   
s   MANIFEST.ins   created project in %s(   R   R   R    t   splitRA   R8   t   ensuret   create_filest   localst   visitt   reltoR   R    (
   t   nameversiont   filedefst   src_roott   partsR:   t   versiont   baset   src_dirt   manifestlinesR$   (   R&   (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   initproj%  s.    			N(   R   (   R(   R&   RË   (    (   R&   s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyRË   "  s    $c         C   sŒ   x… | j  ƒ  D]w \ } } t | t ƒ rG t |  j | d d ƒ| ƒ q t | t ƒ r t j j j	 | ƒ } |  j
 | ƒ j | ƒ q q Wd  S(   NRº   i   (   t   itemsR¬   t   dictR¿   R¾   RL   R   R   R   R   R   R   (   RÈ   RÄ   t   keyt   valueR#   (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyR¿   L  s    (    (    (    (    (    (#   R   R+   R   R
   R   t
   py.builtinR    R   R   R   R“   R)   R   R>   R   R2   R   t   resultR   R   R   R   t   fixtureR'   R.   R/   RW   Rr   Rs   R-   R—   R™   Rª   RË   R¿   (    (    (    s.   /tmp/pip-build-UnxK1c/tox/tox/_pytestplugin.pyt   <module>   s4   			A5	
'*