ó
ØÆ÷Xc           @` s
  d  Z  d d l m Z m Z m Z d d l Z d d l m Z m	 Z	 m
 Z
 m Z d d l Z d d l m Z m Z d d l Z d d l m Z m Z d d l m Z d d l m Z d d	 l m Z e	 e e
 e j ƒ d
 d ƒ ƒ Z e d „ Z e e ƒ d „  ƒ Z d S(   s\    Test scripts

Test that we can run executable scripts that have been installed with numpy.
i    (   t   divisiont   print_functiont   absolute_importN(   t   joint   isfilet   dirnamet   basename(   t   Popent   PIPE(   t
   basestringt   asbytes(   t   assert_equal(   t   skipif(   t   assert_s   ..s   setup.pyc      
   C` s  t  |  t ƒ r |  g n	 t |  ƒ }  t j d k rj g  |  D]' } d | k r[ d j | ƒ n | ^ q: }  n  t |  d t d t ƒ} | j ƒ  \ } } | j	 ƒ  d k r³ | j ƒ  n  | r| j d k rt d j d d d	 d
 d d d	 d g ƒ j |  | | ƒ ƒ ‚ n  | j | | f S(   sp   Run command sequence `cmd` returning exit code, stdout, stderr

    Parameters
    ----------
    cmd : str or sequence
        string with command name or sequence of strings defining command
    check_code : {True, False}, optional
        If True, raise error for non-zero return code

    Returns
    -------
    returncode : int
        return code from execution of `cmd`
    stdout : bytes (python 3) or str (python 2)
        stdout from `cmd`
    stderr : bytes (python 3) or str (python 2)
        stderr from `cmd`

    Raises
    ------
    RuntimeError
        If `check_code` is True, and return code !=0
    t   ntt    s   "{0}"t   stdoutt   stderri    s   
s   Command "{0}" failed withs   ------s   {1}t    s   {2}N(   t
   isinstanceR	   t   listt   ost   namet   formatR   R   t   communicatet   pollt   Nonet	   terminatet
   returncodet   RuntimeErrorR   (   t   cmdt
   check_codet   ct   procR   R   (    (    s7   /tmp/pip-build-X4mzal/numpy/numpy/tests/test_scripts.pyt   run_command   s    $7	'c          C` sN  t  j d k r t t  j ƒ }  |  j d ƒ r: d |  } n
 d |  } t t  j | d g ƒ \ } } } | j ƒ  t d ƒ k } t | d ƒ n½ t  j	 } t
 | j ƒ } t
 | j ƒ } d d | d | d	 | f }	 t } xW |	 D]O } y? t | d g ƒ \ } } } t | j ƒ  t d ƒ ƒ t } PWqà qà Xqà Wd
 |	 }
 t | |
 ƒ d  S(   Nt   win32t   Scriptss
   %s\f2py.pys   %s\Scripts\f2py.pys   -vt   2s   Warning: f2py not found in patht   f2pyt   .s/   Warning: neither %s nor %s nor %s found in path(   t   syst   platformR   t
   executablet   endswithR"   t   stripR
   R   t   version_infot   strt   majort   minort   FalseR   t   True(   t   exe_dirt   f2py_cmdt   codeR   R   t   successt   versionR/   R0   t	   f2py_cmdst   msg(    (    s7   /tmp/pip-build-X4mzal/numpy/numpy/tests/test_scripts.pyt	   test_f2py>   s.    
!	
(    t   __doc__t
   __future__R    R   R   R   t   os.pathR   t   pathjoinR   R   R   R(   t
   subprocessR   R   t   numpyt   npt   numpy.compat.py3kR	   R
   t
   nose.toolsR   t   numpy.testing.decoratorsR   t   numpy.testingR   t   __file__t
   is_inplaceR2   R"   R:   (    (    (    s7   /tmp/pip-build-X4mzal/numpy/numpy/tests/test_scripts.pyt   <module>   s   "!*