o
    û›h²  ã                   @   s~  d Z ddlZddlZddlZddlZddlZddlmZ ddlmZ ddl	m
Z
mZ dd„ Zd*d	d
„Zd*dd„Zdd„ Zdd„ ZeejdkdƒZeej d¡dƒZeejdkdƒZeejdkdƒZeej d¡ dƒZeej d¡ dƒZejdvo‚ej dd¡dkZdZeeeƒZdd„ Zed ƒZed!ƒZ d"d„ Z!zej"d#d$�Z#W n e$y­   d%Z%Y nw d&Z%e# &¡  ee%d'ƒZ'd(d)„ Z(dS )+a  Decorators for labeling 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 metadata such as function name, setup and
teardown functions and so on - see nose.tools for more information.

This module provides a set of useful decorators meant to be ready to use in
your own tests.  See the bottom of the file for the ready-made ones, and if you
find yourself writing a new one that may be of generic use, add it here.

Included decorators:


Lightweight testing that remains unittest-compatible.

- An @as_unittest decorator can be used to tag any normal parameter-less
  function as a unittest TestCase.  Then, both nose and normal unittest will
  recognize it as such.  This will make it easier to migrate away from Nose if
  we ever need/want to while maintaining very lightweight tests.

NOTE: This file contains IPython-specific decorators. Using the machinery in
IPython.external.decorators, we import either numpy.testing.decorators if numpy is
available, OR use equivalent code in IPython.external._decorators, which
we've copied verbatim from numpy.

é    N)Úimport_module)Ú	decoratoré   )Ú	ipdoctestÚipdocstringc                    s"   G ‡ fdd„dt jƒ}ˆ j|_|S )zDDecorator to make a simple function into a normal test via unittest.c                       s   e Zd Z‡ fdd„ZdS )zas_unittest.<locals>.Testerc                    s
   ˆ ƒ  d S ©N© )Úself©Úfuncr   úPc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/testing/decorators.pyÚtest6   s   
z as_unittest.<locals>.Tester.testN)Ú__name__Ú
__module__Ú__qualname__r   r   r
   r   r   ÚTester5   s    r   )ÚunittestZTestCaser   )r   r   r   r
   r   Úas_unittest3   s   r   c                 C   s2   |du rd}ddl }t| tƒsJ ‚|jj| |d�S )aÅ  Make function raise SkipTest exception if skip_condition is true

    Parameters
    ----------

    skip_condition : bool or callable
      Flag to determine whether to skip test. 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.
    msg : string
      Message to give on raising a SkipTest exception.

    Returns
    -------
    decorator : function
      Decorator, which, when applied to a function, causes SkipTest
      to be raised when the skip_condition was True, and the function
      to be called normally otherwise.
    Nz#Test skipped due to test condition.r   ©Úreason)ÚpytestÚ
isinstanceÚboolÚmarkÚskipif)Zskip_conditionÚmsgr   r   r   r   r   @   s
   r   c                 C   s    | rt | tƒstdƒ‚td| ƒS )aY  Decorator factory - mark a test function for skipping from test suite.

    Parameters
    ----------
      msg : string
        Optional message to be added.

    Returns
    -------
       decorator : function
         Decorator, which, when applied to a function, causes SkipTest
         to be raised, with the optional message added.
      zSinvalid object passed to `@skip` decorator, did you meant `@skip()` with brackets ?T)r   ÚstrÚ
ValueErrorr   )r   r   r   r   Úskip`   s   
r   c                 C   s   t |  |ƒS )z0The reverse from skipif, see skipif for details.)r   )Ú	conditionr   r   r   r   Úonlyift   s   r    c                 C   s,   z	t | ƒ}d}W |S  ty   d}Y |S w )z×Can module be imported?  Returns true if module does NOT import.

    This is used to make a decorator to skip tests that require module to be
    available, but delay the 'import numpy' to test execution time.
    FT)r   ÚImportError)ÚmoduleÚmodZmod_not_availr   r   r   Úmodule_not_available{   s   ýýr$   Úwin32z$This test does not run under WindowsÚlinuxz"This test does not run under LinuxÚdarwinz!This test does not run under OS Xz!This test only runs under WindowszThis test only runs under LinuxzThis test only runs under macOS)r'   r%   ZDISPLAYÚ z.Skipped under *nix when X11/XOrg not availablec                 C   s   t t| ƒd|  ƒS )NzThis test requires %s)r   r$   )r#   r   r   r   Ú<lambda>§   s    r)   ÚnumpyZ
matplotlibc                 C   s   | S r   r   )Úfr   r   r   r)   ¯   s    u   tmpâ‚¬)ÚprefixFTzCThis test is only applicable where we can use unicode in filenames.c                  G   sX   t j dd¡du sJ dƒ‚| D ]}d|› d�}t |¡s)ddl}|jj|d�  S qtS )zN
    Decorator to skip test when at least one of `commands` is not found.
    ZIPTEST_WORKING_DIRNz#iptest deprecated since IPython 8.0z This test runs only if command 'z' is installedr   r   )	ÚosÚenvironÚgetÚshutilÚwhichr   r   r   Ú	null_deco)ÚcommandsÚcmdr   r   r   r   r   Úonlyif_cmds_exist¿   s   ÿ
ýr5   r   ))Ú__doc__r-   r0   ÚsysÚtempfiler   Ú	importlibr   r   Z
ipunittestr   r   r   r   r   r    r$   ÚplatformZ
skip_win32Ú
startswithZ
skip_linuxZskip_osxZskip_if_not_win32Zskip_if_not_linuxZskip_if_not_osxr.   r/   Z_x11_skip_condZ_x11_skip_msgZskip_if_no_x11Zskip_withoutZskipif_not_numpyZskipif_not_matplotlibr2   ÚNamedTemporaryFiler+   ÚUnicodeEncodeErrorZunicode_pathsÚcloseZonlyif_unicode_pathsr5   r   r   r   r   Ú<module>   s\    

 
ÿÿÿÿ
ÿ
ÿ
