
    fy                        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 Zd"dZd"d	Zd
 Zd Z eej"                  dk(  d      Z eej"                  j'                  d      d      Z eej"                  dk(  d      Z eej"                  dk7  d      Z eej"                  j'                  d       d      Zej"                  dvxr ej0                  j3                  dd      dk(  ZdZ eee      Zd Z ed      Z ed      Zd Z 	  ejB                  d      Z"dZ#e"jI                           ee#d       Z&d! Z'y# e%$ r dZ#Y w xY w)#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                 `      G  fddt         j                        } j                  |_        |S )zDDecorator to make a simple function into a normal test via unittest.c                       e Zd Z fdZy)as_unittest.<locals>.Testerc                              y N )selffuncs    U/var/www/cvtools/html/venv/lib/python3.12/site-packages/IPython/testing/decorators.pytestz as_unittest.<locals>.Tester.test6   s    F    N)__name__
__module____qualname__r   )r   s   r   Testerr
   5   s    	r   r   )unittestTestCaser   )r   r   s   ` r   as_unittestr   3   s'    ""  mmFOMr   c                 p    |d}ddl }t        | t              sJ |j                  j	                  | |      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)skip_conditionmsgr   s      r   r!   r!   @   s;    * {3nd+++;;nS99r   c                 T    | 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#   s    r   skipr'   `   s/     :c3' ; < 	<$r   c                     t        |  |      S )z0The reverse from skipif, see skipif for details.)r!   )	conditionr#   s     r   onlyifr*   t   s     i-%%r   c                 F    	 t        |       }d}|S # t        $ r d}Y |S w xY w)zCan 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modmod_not_avails      r   module_not_availabler0   {   s:    F#   s      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 Linux)r3   r1   DISPLAY z.Skipped under *nix when X11/XOrg not availablec                 2    t        t        |       d| z        S )NzThis test requires %s)r!   r0   )r.   s    r   <lambda>r7      s    6"6s";=TWZ=Z[ r   numpy
matplotlibc                     | S r   r   )fs    r   r7   r7      s    a r   u   tmp€)prefixTFzCThis test is only applicable where we can use unicode in filenames.c                      t         j                  j                  dd      J d       | D ]?  }d| d}t        j                  |      rddl}|j                  j                  |      c S  t        S )zN
    Decorator to skip test when at least one of `commands` is not found.
    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   s       r   onlyif_cmds_existrG      sv    
 	

+T2:-,-: 33C5G||C ;;##6#223 r   r   )(__doc__r?   rB   systempfiler   	importlibr   r   
ipunittestr   r   r   r!   r'   r*   r0   platform
skip_win32
startswith
skip_linuxskip_osxskip_if_not_win32skip_if_not_linuxr@   rA   _x11_skip_cond_x11_skip_msgskip_if_no_x11skip_withoutskipif_not_numpyskipif_not_matplotlibrD   NamedTemporaryFiler;   unicode_pathscloseUnicodeEncodeErroronlyif_unicode_pathsrG   r   r   r   <module>r_      s  @ 
  
   #  /:@(&& CLLG+:<
CLL++G48:
#,,(*+NO 3<<72>@ s||66w??<>  ,,&99 6**..B/25 @6
 \( $\2  	###95A MGGIm /M O   Ms   E EE