a
    p=icK                     @   sh   d Z ddlZddlZddlZddlZddlmZmZ g dZ	dd Z
ddd	ZG d
d dZdd ZdS )ze
Nose test running.

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

    N   )import_nosesuppress_warnings)get_package_namerun_module_suite
NoseTester_numpy_testerr   r   r   c                 C   s   | dd }g }d| v s d| v rFt j| \} }|dv r:qF|| q|sZd|v rVdS dS |  |d drz|d d	|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)r	   r
   scipynumpyr   z.egg.)ospathsplitappendreverseendswithpopjoin)filepathfullpathpkg_namep2 r   r/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/numpy/testing/_private/nosetester.pyr      s    
r   c                 C   st   | du r,t d}|jdd} | du r,t|du 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argvZ
addplugins)
sys	_getframef_localsgetAssertionErrorr   r   noseclassesr   run)Zfile_to_runr   fnoser   r   r   r   r   =   s    #

r   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 u rd}d }|d u r\t d| }|jdd }|d u r@ttj|}|jdd }n2t|t	trtj|j
}t|dd }nt|}|| _|d u rt|}|| _|| _|| _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packager2   depthr3   r1   r'   r0   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   r0   r,   r/   	TypeError)r4   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
}td|  d| jv rdd l}td	|j  tj	|j
}td
|  tjdd}td|  td|j  d S )Nr   zNumPy version )
   r   C)orderz&NumPy relaxed strides checking option:zNumPy is installed in r   zSciPy version zSciPy is installed in 
 zPython version znose version %d.%d.%d)r   r   print__version__Zonesflagsf_contiguousr   r   r+   r   r1   r   r    versionreplaceZ__versioninfo__)r4   r(   r   Zrelaxed_stridesZnpdirr   Zspdir	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%   rL   )r4   rL   r   r   r   _get_custom_doctester   s    z NoseTester._get_custom_doctesterr9   r   c                 C   s  t   | |||}|r0|d| j dddg7 }|rd|du rH|dg7 }nt|trd|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 }z&|	 }|  |dd |jD 7 }W n ty   Y n0 d|v }|dkr |r d}|  }|d	u rJ|r|s|dg7 }n6|rZ|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=z--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>(      z0NoseTester.prepare_test_args.<locals>.<listcomp>z--with-fpumodecheckpluginc                 S   s   g | ]}|qS r   r   rQ   r   r   r   rT   0  rU   z--with-doctestFdoctestz--with-)r   r>   r1   r,   intr/   Znose.plugins.builtinZnose.pluginsrN   r%   r   rO   rP   pluginsbuiltinr3   ZloadPluginsImportErrorrM   removename)r4   r;   r<   r=   doctestscoveragetimerr   r(   rN   r   rO   rP   rX   Zentrypoint_managerZdoctest_argvZplugr   r   r   prepare_test_args  sL    



zNoseTester.prepare_test_argsc              	   C   s  t |d}ddlm} ||_| ||||||\}	}
|rJtd| j  ntd| j  |   ddl}d|_	|du r~| j
}ttfdd	}t|tr|| }td
}t  td |D ]}tjd|d q|jdd |jdd |jdd |jtjd |jdd |jdd t & td ddlm} W d   n1 sR0    Y  |jt|d tjddtdd ddlm} ||	d|
d}W d   n1 s0    Y  |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://pypi.org/project/coverage/>`_).
        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 zRunning unit tests for r   Nr   )developr)   locationalwayserror)categoryzNot importing directory)messageznumpy.dtype size changedznumpy.ufunc size changedz.*boolean negative.*z.*boolean subtract.*)cpuinfo)rg   moduleignorez.*getargspec.*znose\.)rh   rg   rj   )NumpyTestProgramF)r   exitrX   )minrC   rb   r<   r`   rD   r1   rK   rV   Zmasterr2   dictWarningr,   r/   r   warningsresetwarningsfilterwarningsfilternpZModuleDeprecationWarningcatch_warningssimplefilter	distutilsri   UserWarningDeprecationWarningr%   rl   result)r4   r;   r<   r=   r]   r^   r2   r_   rb   r   rX   rV   Z
_warn_optssupZwarningtyperi   rl   tr   r   r   testF  sR    G





,.zNoseTester.testc                 C   sb   t d| 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 z--matchz(?:^|[\\b_\\.%s-])[Bb]enchr   )rO   rV   r   )
rD   r1   rK   r>   r   sepr   r%   rO   r&   )r4   r;   r<   r=   r   r(   rO   Zadd_pluginsr   r   r   bench  s    :
zNoseTester.bench)Nr)   r   F)r9   r   NFFF)r9   r   NFFNF)r9   r   N)r*   
__module____qualname____doc__r7   r>   rK   rM   r`   r~   r   r   r   r   r   r   p   s    )  
)%
  
@   
 r   c                  C   s,   t tdrdtjv rd} nd} t| dddS )NrE   z.dev0rc   r)   r   T)r2   r6   r3   )hasattrru   rE   r   )moder   r   r   r     s    r   )NN)r   r   r    rq   r   ru   rb   r   r   __all__r   r   r   r   r   r   r   r   <module>   s   )
3   .