ó
Gq]c           @   sX  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z y d d l m Z Wn! e k
 ry d d l	 m Z n Xd d l
 m Z d d l m Z e j j e j j e ƒ ƒ Z d Z g  Z e j d  d k ró e j d	 d
 d d g ƒ n< e j d  d k se j d  d k r/e j d	 d g ƒ n  d „  Z d d „ Z d „  Z e ƒ  d S(   s?   
Run unit tests. This is invoked by:

$ python -m psutil.tests
iÿÿÿÿN(   t   urlopen(   t
   PYTHON_EXE(   t   runs$   https://bootstrap.pypa.io/get-pip.pyi   i   t	   ipaddresst	   unittest2t   argparses   mock==1.0.1i   i   t   mockc          C   s  y d d  l  }  Wní t k
 rÿ d d  l } t j d d ƒ } t j | ƒ ­ d t | j f GHt	 | d ƒ r~ | j
 ƒ  } n d  } | r™ t d | ƒ n i  } t t |  } | j ƒ  } | j | ƒ | j ƒ  d GHt j d t | j f ƒ } | SWd  QXn Xd  S(	   Niÿÿÿÿt   suffixs   .pys   downloading %s to %st   _create_unverified_contextt   contexts   installing pips   %s %s --user(   t   pipt   ImportErrort   sslt   tempfilet   NamedTemporaryFilet
   contextlibt   closingt   GET_PIP_URLt   namet   hasattrR   t   Nonet   dictR    t   readt   writet   flusht   ost   systemR   (   R
   R   t   ft   ctxt   kwargst   reqt   datat   code(    (    s4   lib/python2.7/site-packages/psutil/tests/__main__.pyt   install_pip$   s$    
c         C   s|   |  d k r t }  n  t |  ƒ }  |  rx t t d ƒ } | sB d n d } t ƒ  t j d t | d j	 |  ƒ f ƒ } | Sd S(   s"   Install test dependencies via pip.t   real_prefixs   --usert    s!   %s -m pip install %s --upgrade %st    N(
   R   t	   TEST_DEPSt   setR   t   sysR!   R   R   R   t   join(   t   depst   is_venvt   optsR    (    (    s4   lib/python2.7/site-packages/psutil/tests/__main__.pyt   install_test_deps;   s    		c       	   C   sÒ   d t  }  t j d |  d d ƒ } | j d d d d d	 t d
 d ƒ| j ƒ  \ } } | j rp t ƒ  t ƒ  n^ xT t	 D]L } y t
 | j d ƒ d ƒ Wqw t k
 rÂ t j d | t  f ƒ qw Xqw Wt ƒ  d  S(   Ns   %s -m psutil.tests [opts]t   usaget   descriptions   run unit testss   -is   --install-depst   actiont
   store_truet   defaultt   helps%   don't print status messages to stdouts   ==i    s>   %r lib is not installed; run %s -m psutil.tests --install-deps(   R   t   optparset   OptionParsert
   add_optiont   Falset
   parse_argst   install_depsR!   R,   R%   t
   __import__t   splitR   R'   t   exitR   (   R-   t   parserR+   t   argst   dep(    (    s4   lib/python2.7/site-packages/psutil/tests/__main__.pyt   mainI   s     
	
	(   i   i   (   i   i   (   i   i   (   t   __doc__R   R3   R   R'   R   t   urllib.requestR    R   t   urllib2t   psutil.testsR   t   psutil.tests.runnerR   t   patht   abspatht   dirnamet   __file__t   HERER   R%   t   version_infot   extendR!   R   R,   R?   (    (    (    s4   lib/python2.7/site-packages/psutil/tests/__main__.pyt   <module>   s,   &		