ó
Ú6e]c           @` 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 d d	 d
 d d d g 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_warningst   get_package_namet   run_module_suitet
   NoseTestert   _numpy_testerR   R   c         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(    (    s@   lib/python2.7/site-packages/numpy/testing/_private/nosetester.pyR      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")  # doctest: +SKIP

    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   (    (    s@   lib/python2.7/site-packages/numpy/testing/_private/nosetester.pyR   @   s    #	c           B` s‰   e  Z d  Z d d d e d „ Z d „  Z d „  Z d „  Z d d d e e e d	 „ Z	 d d d e e d e 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_warningst   check_fpu_mode(   t   selft   packageR1   t   depthR2   R0   R&   R/   (    (    s@   lib/python2.7/site-packages/numpy/testing/_private/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.   (   R3   t   labelt   verboset
   extra_argvR   (    (    s@   lib/python2.7/site-packages/numpy/testing/_private/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   R0   R
   R   t   versiont   replacet   __versioninfo__(   R3   R'   R   t   relaxed_stridest   npdirR
   t   spdirt	   pyversion(    (    s@   lib/python2.7/site-packages/numpy/testing/_private/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#   RN   (   R3   RN   (    (    s@   lib/python2.7/site-packages/numpy/testing/_private/nosetester.pyt   _get_custom_doctesterÿ   s    R8   i   c         C` s%  t  ƒ  |  j | | | ƒ } | rB | d |  j d d d g 7} n  | r’ | t k rd | d g 7} q’ t | t ƒ r’ | d d t | ƒ g 7} q’ n  d d l } d d	 l m	 }	 d
 d l
 m }
 m } m } |
 ƒ  g } | g  | j j j D] } | ƒ  ^ qé 7} |  j r(| | ƒ  g 7} | d g 7} n  y7 |	 ƒ  } | j ƒ  | g  | j D] } | ^ qK7} Wn t k
 rrn Xd | k } | t k rš| ršt } n  |  j ƒ  } | d k rÒ| r| r| d g 7} qnI | rè| j d ƒ n  | | d ƒ | g 7} | r| 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-erases   --with-timers   --timer-top-ni    N(   t   EntryPointPluginManageri   (   R   t	   Unpluggert   FPUModeCheckPlugins   --with-fpumodecheckplugins   --with-doctestt   doctests   --with-(   R   R=   R0   t   TrueR+   t   intR.   t   nose.plugins.builtint   nose.pluginsRP   R#   R   RQ   RR   t   pluginst   builtinR2   t   loadPluginst   ImportErrort   FalseRO   R   t   removet   name(   R3   R:   R;   R<   t   doctestst   coveraget   timerR   R'   RP   R   RQ   RR   RX   t   pt   entrypoint_managert   doctest_argvt   plug(    (    s@   lib/python2.7/site-packages/numpy/testing/_private/nosetester.pyt   prepare_test_args	  sJ    )		
$	c         C` sË  t  | d ƒ } d d l m } | | _ |  j | | | | | | ƒ \ }	 }
 | rf 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 rtt j rt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# } | 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 <https://nedbatchelder.com/code/modules/coveragehtml>`_).
        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 ``()``, do not raise on any warnings.
        timer : bool or int, optional
            Timing of individual tests with ``nose-timer`` (which needs to be
            installed).  If True, time tests and report on all of them.
            If an integer (say ``N``), report timing results for ``N`` slowest
            tests.

        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.*(   t   cpuinfot   modulei   s(   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   exitRX   (    (&   t   minR@   Rg   R;   Rf   RA   R0   RM   RS   R   t   masterR1   t   dictt   WarningR+   R   R   t   warningst   resetwarningst   filterwarningst   filtert   npt   ModuleDeprecationWarningt   catch_warningst   simplefiltert	   distutilsRn   t   UserWarningR   t   version_infot   majort   py3kwarningt	   threadingt   DeprecationWarningR#   Rq   R\   t   result(   R3   R:   R;   R<   R_   R`   R1   Ra   Rg   R   RX   RS   t
   _warn_optst   supt   warningtypeRn   R„   Rq   t   t(    (    s@   lib/python2.7/site-packages/numpy/testing/_private/nosetester.pyt   testI  s`    G	
		
	!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   (   RQ   RS   R   R   (
   RA   R0   RM   R=   R   t   sepR   R#   RQ   R$   (   R3   R:   R;   R<   R   R'   RQ   t   add_plugins(    (    s@   lib/python2.7/site-packages/numpy/testing/_private/nosetester.pyt   benchâ  s    :
	N(   R)   t
   __module__t   __doc__R   R\   R6   R=   RM   RO   Rf   R‹   RŽ   (    (    (    s@   lib/python2.7/site-packages/numpy/testing/_private/nosetester.pyR   s   s   )	(	%		
	?		—c          C` sF   t  t d ƒ r' d t j k r' d }  n d }  t d |  d d d t ƒ S(	   NRB   s   .dev0Rh   R(   R1   R5   i   R2   (   t   hasattrR{   RB   R   RT   (   t   mode(    (    s@   lib/python2.7/site-packages/numpy/testing/_private/nosetester.pyR	   ,  s
    	(   R   t
   __future__R    R   R   R   R   Rw   t   numpy.compatR   R   R{   Rg   R   R   t   __all__R   R   R   t   objectR   R	   (    (    (    s@   lib/python2.7/site-packages/numpy/testing/_private/nosetester.pyt   <module>   s   				)3ÿ º