U
    #c,                     @   s   d Z ddlZddlZddlmZmZmZ ddddd	d
dgZdd Z	dddZ
dddZdddZddd	Zdd
 Zee dZdS )a  
Decorators for labeling and modifying behavior of test objects.

Decorators that merely return a modified version of the original
function object are straightforward. Decorators that return a new
function object need to use
::

  nose.tools.make_decorator(original_function)(decorator)

in returning the decorator, in order to preserve meta-data such as
function name, setup and teardown functions and so on - see
``nose.tools`` for more information.

    N   )SkipTestassert_warnsHAS_REFCOUNTslow	setastestskipifknownfailureif
deprecatedparametrize_needs_refcountc                 C   s   t jdtdd d| _| S )a  
    .. deprecated:: 1.21
        This decorator is retained for compatibility with the nose testing framework, which is being phased out.
        Please use the nose2 or pytest frameworks instead.

    Label a test as 'slow'.

    The exact definition of a slow test is obviously both subjective and
    hardware-dependent, but in general any individual test that requires more
    than a second or two should be labeled as slow (the whole suite consists of
    thousands of tests, so even a second is significant).

    Parameters
    ----------
    t : callable
        The test to label as slow.

    Returns
    -------
    t : callable
        The decorated test `t`.

    Examples
    --------
    The `numpy.testing` module includes ``import decorators as dec``.
    A test can be decorated as slow like this::

      from numpy.testing import *

      @dec.slow
      def test_big(self):
          print('Big, slow test')

    the np.testing.dec decorators are included for nose support, and are deprecated since NumPy v1.21. Use the nose2 or pytest frameworks instead.   
stacklevelT)warningswarnDeprecationWarningr   t r   E/tmp/pip-unpacked-wheel-b2rbor69/numpy/testing/_private/decorators.pyr      s    $ Tc                    s    t jdtdd  fdd}|S )aZ  
    .. deprecated:: 1.21
        This decorator is retained for compatibility with the nose testing framework, which is being phased out.
        Please use the nose2 or pytest frameworks instead.

    Signals to nose that this function is or is not a test.

    Parameters
    ----------
    tf : bool
        If True, specifies that the decorated callable is a test.
        If False, specifies that the decorated callable is not a test.
        Default is True.

    Notes
    -----
    This decorator can't use the nose namespace, because it can be
    called from a non-test module. See also ``istest`` and ``nottest`` in
    ``nose.tools``.

    Examples
    --------
    `setastest` can be used in the following way::

      from numpy.testing import dec

      @dec.setastest(False)
      def func_with_test_in_name(arg1, arg2):
          pass

    r   r   r   c                    s
    | _ | S N)Z__test__r   tfr   r   set_testf   s    zsetastest.<locals>.set_test)r   r   r   )r   r   r   r   r   r   C   s    ! c                    s    fdd}|S )aj  
    .. deprecated:: 1.21
        This decorator is retained for compatibility with the nose testing framework, which is being phased out.
        Please use the nose2 or pytest frameworks instead.

    Make function raise SkipTest exception if a given condition is true.

    If the condition is a callable, it is used at runtime to dynamically
    make the decision. This is useful for tests that may require costly
    imports, to delay the cost until the test suite is actually executed.

    Parameters
    ----------
    skip_condition : bool or callable
        Flag to determine whether to skip the decorated test.
    msg : str, optional
        Message to give on raising a SkipTest exception. Default is None.

    Returns
    -------
    decorator : function
        Decorator which, when applied to a function, causes SkipTest
        to be raised when `skip_condition` is True, and the function
        to be called normally otherwise.

    Notes
    -----
    The decorator itself is decorated with the ``nose.tools.make_decorator``
    function in order to transmit function name, and various other metadata.

    c                    s   dd l }tjdtdd ttjjr4fddnfddddd	 fd
d} fdd}|j	 r|}n|}|j
 |S )Nr   r   r   r   c                      s     S r   r   r   skip_conditionr   r   <lambda>       z0skipif.<locals>.skip_decorator.<locals>.<lambda>c                      s    S r   r   r   r   r   r   r      r   c                 S   s$   |dkrd}n|}d| j  d| S )z;Skip message with information about function being skipped.Nz"Test skipped due to test conditionzSkipping test: z: )__name__)funcmsgoutr   r   r   get_msg   s    z/skipif.<locals>.skip_decorator.<locals>.get_msgc                     s$    rt  n
 | |S dS )z"Skipper for normal test functions.Nr   argskwargsfr$   r"   skip_valr   r   skipper_func   s    z4skipif.<locals>.skip_decorator.<locals>.skipper_funcc                  ?   s*    rt  n | |E dH  dS )zSkipper for test generators.Nr%   r&   r)   r   r   skipper_gen   s    z3skipif.<locals>.skip_decorator.<locals>.skipper_gen)N)noser   r   r   
isinstancecollectionsabcCallableutilisgeneratortoolsmake_decorator)r*   r.   r,   r-   skipperr"   r   )r*   r$   r+   r   skip_decorator   s     
zskipif.<locals>.skip_decoratorr   )r   r"   r9   r   r8   r   r   k   s    !0c                    sV   t jdtdd dkrdt tjjr8 fddn fddfd	d
}|S )a  
    .. deprecated:: 1.21
        This decorator is retained for compatibility with the nose testing framework, which is being phased out.
        Please use the nose2 or pytest frameworks instead.

    Make function raise KnownFailureException exception if given condition is true.

    If the condition is a callable, it is used at runtime to dynamically
    make the decision. This is useful for tests that may require costly
    imports, to delay the cost until the test suite is actually executed.

    Parameters
    ----------
    fail_condition : bool or callable
        Flag to determine whether to mark the decorated test as a known
        failure (if True) or not (if False).
    msg : str, optional
        Message to give on raising a KnownFailureException exception.
        Default is None.

    Returns
    -------
    decorator : function
        Decorator, which, when applied to a function, causes
        KnownFailureException to be raised when `fail_condition` is True,
        and the function to be called normally otherwise.

    Notes
    -----
    The decorator itself is decorated with the ``nose.tools.make_decorator``
    function in order to transmit function name, and various other metadata.

    r   r   r   Nz!Test skipped due to known failurec                      s     S r   r   r   fail_conditionr   r   r      r   z knownfailureif.<locals>.<lambda>c                      s    S r   r   r   r:   r   r   r      r   c                    s6   dd l }ddlm   fdd}|j|S )Nr   r   )KnownFailureExceptionc                     s    r n
| |S d S r   r   r&   )r<   r*   fail_valr"   r   r   knownfailer   s    
z@knownfailureif.<locals>.knownfail_decorator.<locals>.knownfailer)r.   Znoseclassesr<   r5   r6   )r*   r.   r>   )r=   r"   )r<   r*   r   knownfail_decorator   s    z+knownfailureif.<locals>.knownfail_decorator)r   r   r   r/   r0   r1   r2   )r;   r"   r?   r   )r;   r=   r"   r   r	      s    # c                    s    fdd}|S )a_  
    .. deprecated:: 1.21
        This decorator is retained for compatibility with the nose testing framework, which is being phased out.
        Please use the nose2 or pytest frameworks instead.

    Filter deprecation warnings while running the test suite.

    This decorator can be used to filter DeprecationWarning's, to avoid
    printing them during the test suite run, while checking that the test
    actually raises a DeprecationWarning.

    Parameters
    ----------
    conditional : bool or callable, optional
        Flag to determine whether to mark test as deprecated or not. If the
        condition is a callable, it is used at runtime to dynamically make the
        decision. Default is True.

    Returns
    -------
    decorator : function
        The `deprecated` decorator itself.

    Notes
    -----
    .. versionadded:: 1.4.0

    c                    sZ   dd l }tjdtdd  fdd}ttjjr: }n}|rR|j	 |S  S d S )Nr   r   r   r   c               	      s"   t t  | | W 5 Q R X d S r   )r   r   r&   r*   r   r   _deprecated_imp#  s    
z@deprecated.<locals>.deprecate_decorator.<locals>._deprecated_imp)
r.   r   r   r   r/   r0   r1   r2   r5   r6   )r*   r.   rA   Zcondconditionalr@   r   deprecate_decorator  s     z'deprecated.<locals>.deprecate_decoratorr   )rC   rD   r   rB   r   r
      s    c                 C   s$   ddl m } tjdtdd ||S )a  
    .. deprecated:: 1.21
        This decorator is retained for compatibility with the nose testing framework, which is being phased out.
        Please use the nose2 or pytest frameworks instead.

    Pytest compatibility class. This implements the simplest level of
    pytest.mark.parametrize for use in nose as an aid in making the transition
    to pytest. It achieves that by adding a dummy var parameter and ignoring
    the doc_func parameter of the base class. It does not support variable
    substitution by name, nor does it support nesting or classes. See the
    pytest documentation for usage.

    .. versionadded:: 1.14.0

    r   )parameterizedr   r   r   )rE   r   r   r   )varsinputrE   r   r   r   r   3  s     zpython has no sys.getrefcount)T)N)N)T)__doc__collections.abcr0   r   utilsr   r   r   __all__r   r   r   r	   r
   r   r   r   r   r   r   <module>   s   
 *
(
T
>
6