3
­?d]#P  ã               @   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d„ Zddd„ZG dd	„ d	eƒZdd
„ ZdS )ze
Nose test running.

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

é    )ÚdivisionÚabsolute_importÚprint_functionN)Ú
basestringé   )Úimport_noseÚsuppress_warningsÚget_package_nameÚrun_module_suiteÚ
NoseTesterÚ_numpy_testerr   r   c             C   sˆ   | dd… }g }x8d| ks"d| krHt jj| ƒ\} }|d	kr<P |j|ƒ qW |s^d|krZdS dS |jƒ  |d jdƒr~|jdƒ dj|ƒS )
a&  
    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'

    Núsite-packagesúdist-packagesÚscipyÚnumpyr   z.eggÚ.)r   r   )ÚosÚpathÚsplitÚappendÚreverseÚendswithÚpopÚjoin)ÚfilepathÚfullpathÚpkg_nameÚp2© r   úB/tmp/pip-build-op5p2y5_/numpy/numpy/testing/_private/nosetester.pyr	      s    
c             C   st   | dkr,t jdƒ}|jjddƒ} | dkr,t‚|dkrBt j| g }n
|| g }tƒ }ddlm} |j	||ƒ gd� dS )aæ  
    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'.
    Nr   Ú__file__)ÚKnownFailurePlugin)ÚargvÚ
addplugins)
ÚsysÚ	_getframeÚf_localsÚgetÚAssertionErrorr"   r   Únoseclassesr!   Úrun)Zfile_to_runr"   ÚfÚnoser!   r   r   r   r
   @   s    #

c               @   sP   e Zd ZdZddd„Zdd	„ Zd
d„ Zdd„ Zddd„Zddd„Z	ddd„Z
dS )r   aï  
    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.

    NÚreleaser   Fc             C   sº   |d krd}d }|d kr\t jd| ƒ}|jjdd ƒ}|d kr@t‚tjj|ƒ}|jjdd ƒ}n2t|t	tƒƒr†tjj|j
ƒ}t|dd ƒ}nt|ƒ}|| _|d kr¤t|ƒ}|| _|| _|| _d S )Nr-   r   r    Ú__name__)r$   r%   r&   r'   r(   r   r   ÚdirnameÚ
isinstanceÚtyper    ÚgetattrÚstrÚpackage_pathr	   Úpackage_nameÚraise_warningsÚcheck_fpu_mode)ÚselfÚpackager6   Údepthr7   r5   r+   r4   r   r   r   Ú__init__�   s(    
zNoseTester.__init__c             C   sl   t | jdg}|rB|dkrBt|tƒs*tdƒ‚|dkr6d}|d|g7 }|dt|ƒg7 }|dg7 }|rh||7 }|S )	a   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
        z-sÚfullz"Selection label should be a stringÚfastznot slowz-Az--verbosityz--exe)r    r4   r0   r   Ú	TypeErrorr3   )r8   ÚlabelÚverboseÚ
extra_argvr"   r   r   r   Ú
_test_argvÆ   s    

zNoseTester._test_argvc             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| ƒ tjjddƒ}td| ƒ td|j ƒ d S )Nr   zNumPy version %sé
   r   ÚC)Úorderz&NumPy relaxed strides checking option:zNumPy is installed in %sr   zSciPy version %szSciPy is installed in %sÚ
Ú zPython version %sznose version %d.%d.%d)rC   r   )r   r   ÚprintÚ__version__ZonesÚflagsÚf_contiguousr   r   r/   r    r5   r   r$   ÚversionÚreplaceZ__versioninfo__)r8   r,   r   Zrelaxed_stridesZnpdirr   ZspdirZ	pyversionr   r   r   Ú_show_system_infoë   s    

zNoseTester._show_system_infoc             C   s   ddl m} |ƒ S )z» 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
        r   )ÚNumpyDoctest)r)   rO   )r8   rO   r   r   r   Ú_get_custom_doctesterÿ   s    z NoseTester._get_custom_doctesterr=   r   c             C   sŠ  t ƒ  | j|||ƒ}|r.|d| j dddg7 }|rb|dkrF|dg7 }nt|tƒrb|ddt|ƒg7 }dd	l}dd
lm}	 ddl	m
}
m}m} |
ƒ g}|dd„ |jjjD ƒ7 }| jrÆ||ƒ g7 }|dg7 }y&|	ƒ }|jƒ  |dd„ |jD ƒ7 }W n tk
�r   Y nX d|k}|dk�r |�r d}| jƒ }|d	k�rL|�r‚| �r‚|dg7 }n6|�r\|jdƒ ||dƒ|g7 }|�r‚|d|j g7 }||fS )zç
        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

        z--cover-package=%sz--with-coveragez--cover-testsz--cover-eraseTz--with-timerz--timer-top-nr   N)ÚEntryPointPluginManagerr   )r!   Ú	UnpluggerÚFPUModeCheckPluginc             S   s   g | ]
}|ƒ ‘qS r   r   )Ú.0Úpr   r   r   ú
<listcomp>+  s    z0NoseTester.prepare_test_args.<locals>.<listcomp>z--with-fpumodecheckpluginc             S   s   g | ]}|‘qS r   r   )rT   rU   r   r   r   rV   3  s    z--with-doctestFÚdoctestz--with-)r   rB   r5   r0   Úintr3   Znose.plugins.builtinZnose.pluginsrQ   r)   r!   rR   rS   ÚpluginsÚbuiltinr7   ZloadPluginsÚImportErrorrP   ÚremoveÚname)r8   r?   r@   rA   ÚdoctestsÚcoverageÚtimerr"   r,   rQ   r!   rR   rS   rY   Zentrypoint_managerZdoctest_argvZplugr   r   r   Úprepare_test_args	  sJ    




zNoseTester.prepare_test_argsc             C   s  t |dƒ}ddlm} ||_| j||||||ƒ\}	}
|rHtd| j ƒ ntd| j ƒ | jƒ  ddl}d|_	|dkrz| j
}ttff d�}t|tƒrš|| }td	ƒ��V}tjƒ  tjd
ƒ x|D ]}tjd|d� q¾W |jdd� |jdd� |jdd� |jtjd� |jdd� |jdd� tjƒ � tjd
ƒ ddlm} W dQ R X |jt|d� tjjdk�rÊtj�rÊ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� tjddt dd � dd!l!m"} ||	d"|
d#�}W dQ R X |j#S )$aù	  
        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
        []
        é   r   )Úutilsz&Running unit tests and doctests for %szRunning unit tests for %sr   N)Údevelopr-   ÚlocationÚalwaysÚerror)ÚcategoryzNot importing directory)Úmessageznumpy.dtype size changedznumpy.ufunc size changedz.*boolean negative.*z.*boolean subtract.*)Úcpuinfo)rh   Úmoduleé   z(sys\.exc_clear\(\) not supported in 3\.x)rk   zin 3\.x, __setslice__zin 3\.x, __getslice__z buffer\(\) not supported in 3\.xz%CObject type is not supported in 3\.xz-comparing unequal types not supported in 3\.xÚignorez.*getargspec.*znose\.)ri   rh   rk   )ÚNumpyTestProgramF)r"   ÚexitrY   )$ÚminrG   rc   r@   ra   rH   r5   rN   rW   Zmasterr6   ÚdictÚWarningr0   r   r   ÚwarningsÚresetwarningsÚfilterwarningsÚfilterÚnpZModuleDeprecationWarningÚcatch_warningsÚsimplefilterÚ	distutilsrj   ÚUserWarningr$   Úversion_infoÚmajorZpy3kwarningÚ	threadingÚDeprecationWarningr)   rn   Úresult)r8   r?   r@   rA   r^   r_   r6   r`   rc   r"   rY   rW   Z
_warn_optsÚsupZwarningtyperj   r~   rn   Útr   r   r   ÚtestI  s`    G





zNoseTester.testc             C   s`   t d| j ƒ | jƒ  | j|||ƒ}|ddtj g7 }tƒ }ddlm} |dƒg}|j	||d�S )aì  
        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

        zRunning benchmarks for %sz--matchz(?:^|[\\b_\\.%s-])[Bb]enchr   )rR   rW   )r"   r#   )
rH   r5   rN   rB   r   Úsepr   r)   rR   r*   )r8   r?   r@   rA   r"   r,   rR   Zadd_pluginsr   r   r   Úbenchâ  s    :
zNoseTester.bench)Nr-   r   F)r=   r   NFFF)r=   r   NFFNF)r=   r   N)r.   Ú
__module__Ú__qualname__Ú__doc__r;   rB   rN   rP   ra   rƒ   r…   r   r   r   r   r   s   s   ) 
(%
 
?  
 c              C   s,   t tdƒrdtjkrd} nd} t| ddd�S )NrI   z.dev0rd   r-   r   T)r6   r:   r7   )Úhasattrrw   rI   r   )Úmoder   r   r   r   ,  s
    )NN)rˆ   Ú
__future__r   r   r   r   r$   rs   Znumpy.compatr   r   rw   rc   r   r   Ú__all__r	   r
   Úobjectr   r   r   r   r   r   Ú<module>   s"   )
3   <