ó
ÿ¼÷Xc           @` 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 l
 Z d d l m Z m Z d „  Z e e d „ Z d	 e f d
 „  ƒ  YZ d „  Z d S(   se   
Nose test running.

This module implements ``test()`` and ``bench()`` functions for NumPy modules.

i    (   t   divisiont   absolute_importt   print_functionN(   t
   basestringi   (   t   import_noset   suppress_warningsc         C` s¸   |  } g  } xQ d |  k s( d |  k r` t  j j |  ƒ \ }  } | d k rP Pn  | j | ƒ q W| s~ d | k rw d Sd Sn  | j ƒ  | d j d ƒ r« | j d ƒ n  d j | ƒ S(	   s&  
    Given a path where a package is installed, determine its name.

    Parameters
    ----------
    filepath : str
        Path to a file. If the determination fails, "numpy" is returned.

    Examples
    --------
    >>> np.testing.nosetester.get_package_name('nonsense')
    'numpy'

    s   site-packagess   dist-packagest   scipyt   numpyi    s   .eggt   .(   s   site-packagess   dist-packages(   t   ost   patht   splitt   appendt   reverset   endswitht   popt   join(   t   filepatht   fullpatht   pkg_namet   p2(    (    s7   /tmp/pip-build-2Vcwy8/numpy/numpy/testing/nosetester.pyt   get_package_name   s    
c         C` s­   |  d k rH t j d ƒ } | j j d d ƒ }  |  d k rH t ‚ qH n  | d k rg t j |  g } n | |  g } t ƒ  } d d l m	 } | j
 d | d | ƒ  g ƒ d S(   sÔ  
    Run a test module.

    Equivalent to calling ``$ nosetests <argv> <file_to_run>`` from
    the command line

    Parameters
    ----------
    file_to_run : str, optional
        Path to test module, or None.
        By default, run the module from which this function is called.
    argv : list of strings
        Arguments to be passed to the nose test runner. ``argv[0]`` is
        ignored. All command line arguments accepted by ``nosetests``
        will work. If it is the default value None, sys.argv is used.

        .. versionadded:: 1.9.0

    Examples
    --------
    Adding the following::

        if __name__ == "__main__" :
            run_module_suite(argv=sys.argv)

    at the end of a test module will run the tests when that module is
    called in the python interpreter.

    Alternatively, calling::

    >>> run_module_suite(file_to_run="numpy/tests/test_matlib.py")

    from an interpreter will run all the test routine in 'test_matlib.py'.
    i   t   __file__(   t   KnownFailurePlugint   argvt
   addpluginsN(   t   Nonet   syst	   _getframet   f_localst   gett   AssertionErrorR   R   t   noseclassesR   t   run(   t   file_to_runR   t   ft   noseR   (    (    s7   /tmp/pip-build-2Vcwy8/numpy/numpy/testing/nosetester.pyt   run_module_suite;   s    #	t
   NoseTesterc           B` s€   e  Z d  Z d d d d „ Z d „  Z d „  Z d „  Z d d d e e d	 „ Z	 d d d e e d d
 „ Z
 d d d d „ Z RS(   sï  
    Nose test runner.

    This class is made available as numpy.testing.Tester, and a test function
    is typically added to a package's __init__.py like so::

      from numpy.testing import Tester
      test = Tester().test

    Calling this test function finds and runs all tests associated with the
    package and all its sub-packages.

    Attributes
    ----------
    package_path : str
        Full path to the package to test.
    package_name : str
        Name of the package to test.

    Parameters
    ----------
    package : module, str or None, optional
        The package to test. If a string, this should be the full path to
        the package. If None (default), `package` is set to the module from
        which `NoseTester` is initialized.
    raise_warnings : None, str or sequence of warnings, optional
        This specifies which warnings to configure as 'raise' instead
        of being shown once during the test execution.  Valid strings are:

          - "develop" : equals ``(Warning,)``
          - "release" : equals ``()``, don't raise on any warnings.

        Default is "release".
    depth : int, optional
        If `package` is None, then this can be used to initialize from the
        module of the caller of (the caller of (...)) the code that
        initializes `NoseTester`. Default of 0 means the module of the
        immediate caller; higher values are useful for utility routines that
        want to initialize `NoseTester` objects on behalf of other code.

    t   releasei    c         C` s  | d  k r d } n  d  } | d  k rŽ t j d | ƒ } | j j d d  ƒ } | d  k rd t ‚ n  t j j | ƒ } | j j d d  ƒ } nK t	 | t
 t ƒ ƒ rÍ t j j | j ƒ } t | d d  ƒ } n t | ƒ } | |  _ | d  k rý t | ƒ } n  | |  _ | |  _ d  S(   NR'   i   R   t   __name__(   R   R   R   R   R   R   R	   R
   t   dirnamet
   isinstancet   typeR   t   getattrt   strt   package_pathR   t   package_namet   raise_warnings(   t   selft   packageR0   t   depthR/   R#   R.   (    (    s7   /tmp/pip-build-2Vcwy8/numpy/numpy/testing/nosetester.pyt   __init__˜   s&    					c         C` s¤   t  |  j d g } | rj | d k rj t | t ƒ sB t d ƒ ‚ n  | d k rW d } n  | d | g 7} n  | d t | ƒ g 7} | d g 7} | r  | | 7} n  | S(	   s   Generate argv for nosetest command

        Parameters
        ----------
        label : {'fast', 'full', '', attribute identifier}, optional
            see ``test`` docstring
        verbose : int, optional
            Verbosity value for test outputs, in the range 1-10. Default is 1.
        extra_argv : list, optional
            List with any extra arguments to pass to nosetests.

        Returns
        -------
        argv : list
            command line arguments that will be passed to nose
        s   -st   fulls"   Selection label should be a stringt   fasts   not slows   -As   --verbositys   --exe(   R   R.   R*   R   t	   TypeErrorR-   (   R1   t   labelt   verboset
   extra_argvR   (    (    s7   /tmp/pip-build-2Vcwy8/numpy/numpy/testing/nosetester.pyt
   _test_argv½   s    	c         C` sû   t  ƒ  } d d  l } t d | j ƒ | j d d d ƒj j } t d | ƒ t j j	 | j
 ƒ } t d | ƒ d	 |  j k rÃ d d  l } t d
 | j ƒ t j j	 | j
 ƒ } t d | ƒ n  t j j d d ƒ } t d | ƒ t d | j ƒ d  S(   Ni    s   NumPy version %si
   i   t   ordert   Cs&   NumPy relaxed strides checking option:s   NumPy is installed in %sR   s   SciPy version %ss   SciPy is installed in %ss   
t    s   Python version %ss   nose version %d.%d.%d(   i
   i   (   R   R   t   printt   __version__t   onest   flagst   f_contiguousR	   R
   R)   R   R/   R   R   t   versiont   replacet   __versioninfo__(   R1   R$   R   t   relaxed_stridest   npdirR   t   spdirt	   pyversion(    (    s7   /tmp/pip-build-2Vcwy8/numpy/numpy/testing/nosetester.pyt   _show_system_infoâ   s    	c         C` s   d d l  m } | ƒ  S(   s»    Return instantiated plugin for doctests

        Allows subclassing of this class to override doctester

        A return value of None means use the nose builtin doctest plugin
        i   (   t   NumpyDoctest(   R    RL   (   R1   RL   (    (    s7   /tmp/pip-build-2Vcwy8/numpy/numpy/testing/nosetester.pyt   _get_custom_doctesterö   s    R6   i   c         C` sK  t  ƒ  |  j | | | ƒ } | rB | d |  j d d d g 7} n  d d l } d d l m } m }	 | ƒ  g }
 |
 g  | j j j D] } | ƒ  ^ qƒ 7}
 d	 | k } | t	 k rÀ | rÀ t
 } n  |  j ƒ  } | d k rø | rA| rA| d	 g 7} qAnI | r| j d	 ƒ n  |
 |	 d
 ƒ | g 7}
 | rA| d | j g 7} n  | |
 f S(   sç   
        Run tests for module using nose.

        This method does the heavy lifting for the `test` method. It takes all
        the same arguments, for details see `test`.

        See Also
        --------
        test

        s   --cover-package=%ss   --with-coverages   --cover-testss   --cover-erasei    Ni   (   R   t	   Unpluggers   --with-doctestt   doctests   --with-(   R   R;   R/   t   nose.plugins.builtinR    R   RN   t   pluginst   builtint   Falset   TrueRM   R   t   removet   name(   R1   R8   R9   R:   t   doctestst   coverageR   R$   R   RN   RQ   t   pt   doctest_argvt   plug(    (    s7   /tmp/pip-build-2Vcwy8/numpy/numpy/testing/nosetester.pyt   prepare_test_args   s,    )	c         C` sÈ  t  | d ƒ } d d l m } | | _ | rB t d |  j ƒ n t d |  j ƒ |  j ƒ  d d l } d | _	 | d k rŠ |  j
 } n  t d t f d	 d$ ƒ }	 t | t ƒ r¾ |	 | } n  t d
 ƒ õ}
 t j ƒ  t j d ƒ x! | D] } t j d d | ƒqë W|
 j d d ƒ |
 j d d ƒ |
 j d d ƒ |
 j d t j ƒ |
 j d d ƒ |
 j d d ƒ t j ƒ  " t j d ƒ d d l m } Wd QX|
 j d t d | ƒ t j j d k rPt j rPd d l } |
 j t  d d | ƒ|
 j t  d d ƒ|
 j t  d d ƒ|
 j t  d d ƒ|
 j t  d d ƒ|
 j t  d d ƒn  t j d d d d t  d d ƒd d  l! m" } |  j# | | | | | ƒ \ } } | d! | d" t$ d# | ƒ } Wd QX| j% S(%   s 	  
        Run tests for module using nose.

        Parameters
        ----------
        label : {'fast', 'full', '', attribute identifier}, optional
            Identifies the tests to run. This can be a string to pass to
            the nosetests executable with the '-A' option, or one of several
            special values.  Special values are:
            * 'fast' - the default - which corresponds to the ``nosetests -A``
              option of 'not slow'.
            * 'full' - fast (as above) and slow tests as in the
              'no -A' option to nosetests - this is the same as ''.
            * None or '' - run all tests.
            attribute_identifier - string passed directly to nosetests as '-A'.
        verbose : int, optional
            Verbosity value for test outputs, in the range 1-10. Default is 1.
        extra_argv : list, optional
            List with any extra arguments to pass to nosetests.
        doctests : bool, optional
            If True, run doctests in module. Default is False.
        coverage : bool, optional
            If True, report coverage of NumPy code. Default is False.
            (This requires the `coverage module:
             <http://nedbatchelder.com/code/modules/coverage.html>`_).
        raise_warnings : None, str or sequence of warnings, optional
            This specifies which warnings to configure as 'raise' instead
            of being shown once during the test execution.  Valid strings are:

              - "develop" : equals ``(Warning,)``
              - "release" : equals ``()``, don't raise on any warnings.

            The default is to use the class initialization value.

        Returns
        -------
        result : object
            Returns the result of running the tests as a
            ``nose.result.TextTestResult`` object.

        Notes
        -----
        Each NumPy module exposes `test` in its namespace to run all tests for it.
        For example, to run all tests for numpy.lib:

        >>> np.lib.test() #doctest: +SKIP

        Examples
        --------
        >>> result = np.lib.test() #doctest: +SKIP
        Running unit tests for numpy.lib
        ...
        Ran 976 tests in 3.933s

        OK

        >>> result.errors #doctest: +SKIP
        []
        >>> result.knownfail #doctest: +SKIP
        []
        i   i   (   t   utilss&   Running unit tests and doctests for %ss   Running unit tests for %si    Nt   developR'   t   locationt   alwayst   errort   categoryt   messages   Not importing directorys   numpy.dtype size changeds   numpy.ufunc size changeds   .*boolean negative.*s   .*boolean subtract.*i   (   t   cpuinfot   modules(   sys\.exc_clear\(\) not supported in 3\.xs   in 3\.x, __setslice__s   in 3\.x, __getslice__s    buffer\(\) not supported in 3\.xs%   CObject type is not supported in 3\.xs-   comparing unequal types not supported in 3\.xt   ignores   .*getargspec.*s   nose\.(   t   NumpyTestProgramR   t   exitRQ   (    (&   t   minR>   R]   R9   R?   R/   RK   RO   R   t   masterR0   t   dictt   WarningR*   R   R   t   warningst   resetwarningst   filterwarningst   filtert   npt   ModuleDeprecationWarningt   catch_warningst   simplefiltert	   distutilsRd   t   UserWarningR   t   version_infot   majort   py3kwarningt	   threadingt   DeprecationWarningR    Rg   R\   RS   t   result(   R1   R8   R9   R:   RW   RX   R0   R]   RO   t
   _warn_optst   supt   warningtypeRd   Rz   Rg   R   RQ   t   t(    (    s7   /tmp/pip-build-2Vcwy8/numpy/numpy/testing/nosetester.pyt   test+  s`    A	
		
	!c         C` s…   t  d |  j ƒ |  j ƒ  |  j | | | ƒ } | d d t j g 7} t ƒ  } d d l m } | d ƒ g } | j	 d | d | ƒ S(	   sè  
        Run benchmarks for module using nose.

        Parameters
        ----------
        label : {'fast', 'full', '', attribute identifier}, optional
            Identifies the benchmarks to run. This can be a string to pass to
            the nosetests executable with the '-A' option, or one of several
            special values.  Special values are:
            * 'fast' - the default - which corresponds to the ``nosetests -A``
              option of 'not slow'.
            * 'full' - fast (as above) and slow benchmarks as in the
              'no -A' option to nosetests - this is the same as ''.
            * None or '' - run all tests.
            attribute_identifier - string passed directly to nosetests as '-A'.
        verbose : int, optional
            Verbosity value for benchmark outputs, in the range 1-10. Default is 1.
        extra_argv : list, optional
            List with any extra arguments to pass to nosetests.

        Returns
        -------
        success : bool
            Returns True if running the benchmarks works, False if an error
            occurred.

        Notes
        -----
        Benchmarks are like tests, but have names starting with "bench" instead
        of "test", and can be found under the "benchmarks" sub-directory of the
        module.

        Each NumPy module exposes `bench` in its namespace to run all benchmarks
        for it.

        Examples
        --------
        >>> success = np.lib.bench() #doctest: +SKIP
        Running benchmarks for numpy.lib
        ...
        using 562341 items:
        unique:
        0.11
        unique1d:
        0.11
        ratio: 1.0
        nUnique: 56230 == 56230
        ...
        OK

        >>> success #doctest: +SKIP
        True

        s   Running benchmarks for %ss   --matchs   (?:^|[\\b_\\.%s-])[Bb]enchi   (   RN   RO   R   R   (
   R?   R/   RK   R;   R	   t   sepR   R    RN   R!   (   R1   R8   R9   R:   R   R$   RN   t   add_plugins(    (    s7   /tmp/pip-build-2Vcwy8/numpy/numpy/testing/nosetester.pyt   bench¾  s    8
	N(   R(   t
   __module__t   __doc__R   R4   R;   RK   RM   RS   R\   R   R„   (    (    (    s7   /tmp/pip-build-2Vcwy8/numpy/numpy/testing/nosetester.pyR&   n   s   )%	%		
	*	’c          C` s@   t  t d ƒ r' d t j k r' d }  n d }  t d |  d d ƒ S(   NR@   s   .dev0R^   R'   R0   R3   i   (   t   hasattrRq   R@   R&   (   t   mode(    (    s7   /tmp/pip-build-2Vcwy8/numpy/numpy/testing/nosetester.pyt   _numpy_tester  s    	(   R†   t
   __future__R    R   R   R	   R   Rm   t   numpy.compatR   R   Rq   R]   R   R   R   R   R%   t   objectR&   R‰   (    (    (    s7   /tmp/pip-build-2Vcwy8/numpy/numpy/testing/nosetester.pyt   <module>   s   	)3ÿ ™