Format: application/x-python-code
⬇ Download File (6.0 KB)
   1  o
   2  
   3  ��h��@s~dZddlZddlZddlZddlZddlZddlmZddlmZddl	m
   4  Z
   5  mZdd�Zd*d	d
   6  �Z
   7  d*dd�Zd
   8  d�Zdd�Ze
   9  ejdkd�Ze
  10  ej�d�d�Ze
  11  ejdkd�Ze
  12  ejdkd�Ze
  13  ej�d�d�Ze
  14  ej�d�d�Zejdvo�ej�dd�dkZdZe
  15  ee�Zdd�Zed �Zed!�Z d"d�Z!zej"d#d$�Z#Wne$y�d%Z%Ynwd&Z%e#�&�ee%d'�Z'd(d)�Z(dS)+aDecorators for labeling test objects.
  16  
  17  Decorators that merely return a modified version of the original function
  18  object are straightforward.  Decorators that return a new function object need
  19  to use nose.tools.make_decorator(original_function)(decorator) in returning the
  20  decorator, in order to preserve metadata such as function name, setup and
  21  teardown functions and so on - see nose.tools for more information.
  22  
  23  This module provides a set of useful decorators meant to be ready to use in
  24  your own tests.  See the bottom of the file for the ready-made ones, and if you
  25  find yourself writing a new one that may be of generic use, add it here.
  26  
  27  Included decorators:
  28  
  29  
  30  Lightweight testing that remains unittest-compatible.
  31  
  32  - An @as_unittest decorator can be used to tag any normal parameter-less
  33    function as a unittest TestCase.  Then, both nose and normal unittest will
  34    recognize it as such.  This will make it easier to migrate away from Nose if
  35    we ever need/want to while maintaining very lightweight tests.
  36  
  37  NOTE: This file contains IPython-specific decorators. Using the machinery in
  38  IPython.external.decorators, we import either numpy.testing.decorators if numpy is
  39  available, OR use equivalent code in IPython.external._decorators, which
  40  we've copied verbatim from numpy.
  41  
  42  �N)�
  43  import_module)�	decorator�)�	ipdoctest�ipdocstringcs"G�fdd�dtj�}�j|_|S)zDDecorator to make a simple function into a normal test via unittest.cseZdZ�fdd�ZdS)zas_unittest.<locals>.Testercs
  44  ��dS�N�)�self��funcr�Pc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/testing/decorators.py�test6s
  45  z as_unittest.<locals>.Tester.testN)�__name__�
  46  __module__�__qualname__r
  47  rr
  48  rr�Tester5sr)�unittestZTestCaser)rrrr
  49  r�as_unittest3srcCs2|durd}ddl}t|t�sJ�|jj||d�S)a�Make function raise SkipTest exception if skip_condition is true
  50  
  51      Parameters
  52      ----------
  53  
  54      skip_condition : bool or callable
  55        Flag to determine whether to skip test. If the condition is a
  56        callable, it is used at runtime to dynamically make the decision. This
  57        is useful for tests that may require costly imports, to delay the cost
  58        until the test suite is actually executed.
  59      msg : string
  60        Message to give on raising a SkipTest exception.
  61  
  62      Returns
  63      -------
  64      decorator : function
  65        Decorator, which, when applied to a function, causes SkipTest
  66        to be raised when the skip_condition was True, and the function
  67        to be called normally otherwise.
  68      Nz#Test skipped due to test condition.r��reason)�pytest�
  69  isinstance�bool�mark�skipif)Zskip_condition�msgrrrrr@s
  70  rcCs |rt|t�std��td|�S)aYDecorator factory - mark a test function for skipping from test suite.
  71  
  72      Parameters
  73      ----------
  74        msg : string
  75          Optional message to be added.
  76  
  77      Returns
  78      -------
  79         decorator : function
  80           Decorator, which, when applied to a function, causes SkipTest
  81           to be raised, with the optional message added.
  82        zSinvalid object passed to `@skip` decorator, did you meant `@skip()` with brackets ?T)r�str�
  83  ValueErrorr)rrrr�skip`s
  84  rcCst||�S)z0The reverse from skipif, see skipif for details.)r)�	conditionrrrr�onlyiftsr cCs,z	t|�}d}W|Styd}Y|Sw)z�Can module be imported?  Returns true if module does NOT import.
  85  
  86      This is used to make a decorator to skip tests that require module to be
  87      available, but delay the 'import numpy' to test execution time.
  88      FT)r�ImportError)�module�modZ
  89  mod_not_availrrr�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 WindowszThis test only runs under LinuxzThis test only runs under macOS)r'r%ZDISPLAY�z.Skipped under *nix when X11/XOrg not availablecCstt|�d|�S)NzThis test requires %s)rr$)r#rrr�<lambda>�sr)�numpyZ
  90  matplotlibcCs|Srr)�frrrr)�sutmp€)�prefixFTzCThis test is only applicable where we can use unicode in filenames.cGsXtj�dd�dus
  91  Jd��|D]}d|�d�}t�|�s)ddl}|jj|d�SqtS)zN
  92      Decorator to skip test when at least one of `commands` is not found.
  93      ZIPTEST_WORKING_DIRNz#iptest deprecated since IPython 8.0z This test runs only if command 'z' is installedrr)	�os�environ�get�shutil�whichrrr�	null_deco)�commands�cmdrrrrr�onlyif_cmds_exist�s�
  94  �r5r))�__doc__r-r0�sys�tempfiler�	importlibrrZ
  95  ipunittestrrrrrr r$�platformZ
  96  skip_win32�
  97  startswithZ
  98  skip_linuxZskip_osxZskip_if_not_win32Zskip_if_not_linuxZskip_if_not_osxr.r/Z_x11_skip_condZ
  99  _x11_skip_msgZskip_if_no_x11Zskip_withoutZskipif_not_numpyZskipif_not_matplotlibr2�NamedTemporaryFiler+�UnicodeEncodeErrorZ
 100  unicode_paths�closeZonlyif_unicode_pathsr5rrrr�<module>s\ 
 101  
 102   
 103  ����
 104  �
 105  �
 106