
    S_f                         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Zg dZdZ	 ej                  d      xs dZdev rdZ	 G d	 d
e      Z G d d      Z G d d      Zd Zd Zd Zd Zy)z
Generic test utilities.

    N)PytestTestercheck_free_memory_TestPythranFuncIS_MUSLFHOST_GNU_TYPE muslTc                       e Zd ZdZy)FPUModeChangeWarningzWarning about FPU mode changeN)__name__
__module____qualname____doc__     5lib/python3.12/site-packages/scipy/_lib/_testutils.pyr   r      s    'r   r   c                   "    e Zd ZdZd Z	 	 ddZy)r   a"  
    Run tests for this namespace

    ``scipy.test()`` runs tests for all of SciPy, with the default settings.
    When used from a submodule (e.g., ``scipy.cluster.test()``, only the tests
    for that namespace are run.

    Parameters
    ----------
    label : {'fast', 'full'}, optional
        Whether to run only the fast tests, or also those marked as slow.
        Default is 'fast'.
    verbose : int, optional
        Test output verbosity. Default is 1.
    extra_argv : list, optional
        Arguments to pass through to Pytest.
    doctests : bool, optional
        Whether to run doctests or not. Default is False.
    coverage : bool, optional
        Whether to run tests with code coverage measurements enabled.
        Default is False.
    tests : list of str, optional
        List of module names to run tests for. By default, uses the module
        from which the ``test`` function is called.
    parallel : int, optional
        Run tests in parallel with pytest-xdist, if number given is larger than
        1. Default is 1.

    c                     || _         y N)module_name)selfr   s     r   __init__zPytestTester.__init__>   s
    &r   Nc                    dd l }t        j                  | j                     }	t        j
                  j                  |	j                  d         }
ddg}|rt        d      |r|t        |      z  }|r&t        |      dkD  r|ddt        |      dz
  z  z   gz  }|r	|d|
z   gz  }|d	k(  r|d
dgz  }n|dk7  r|d
|gz  }|| j                  g}|7|dkD  r2t               r|dt        |      gz  }ndd l}|j                  dd       |dgt        |      z   z  }	 |j                  |      }|dk(  S # t         $ r}|j"                  }Y d }~|dk(  S d }~ww xY w)Nr   z--showlocalsz
--tb=shortzDoctests not supported   -vz--cov=fastz-mznot slowfullz-nzMCould not run tests in parallel because pytest-xdist plugin is not available.   )
stacklevelz--pyargs)pytestsysmodulesr   ospathabspath__path__
ValueErrorlistint_pytest_has_xdiststrwarningswarnmain
SystemExitcode)r   labelverbose
extra_argvdoctestscoveragetestsparallelr!   modulemodule_pathpytest_argsr-   r1   excs                  r   __call__zPytestTester.__call__A   s|   T--.ggoofooa&89%|45664
++Ks7|a'C#s7|A~"6677KH{233KF?D*--Kf_D%=(K=%%&EHqL "c(m44 F)*  , 	
|d5k11	;;{+D 	  	88D		s   D, ,	E5E

E)r   r   NFFNN)r   r   r   r   r   r=   r   r   r   r   r       s    :' KP6:-r   r   c                   "   e Zd ZdZej
                  ej                  ej                  ej                  ej                  ej                  gZej                  ej                  gZej                  ej                   gZd Zd Zd Zd Zd Zd Zd Zy	)
r   aL  
    These are situations that can be tested in our pythran tests:
    - A function with multiple array arguments and then
      other positional and keyword arguments.
    - A function with array-like keywords (e.g. `def somefunc(x0, x1=None)`.
    Note: list/tuple input is not yet tested!

    `self.arguments`: A dictionary which key is the index of the argument,
                      value is tuple(array value, all supported dtypes)
    `self.partialfunc`: A function used to freeze some non-array argument
                        that of no interests in the original function
    c                 .    i | _         d | _        d | _        y r   )	argumentspartialfuncexpected)r   s    r   setup_methodz_TestPythranFunc.setup_method   s    r   c                     t        j                  |      }i }|j                  j                         D ];  \  }}|j                  t         j
                  j                  us-|j                  ||<   = |S r   )inspect	signature
parametersitemsdefault	Parameterempty)r   funcrF   optional_argskr   s         r   get_optional_argsz"_TestPythranFunc.get_optional_args   si     %%d+	((..0 	-DAqyy 1 1 7 77#$99a 	- r   c                 r    d}| j                   D ]%  }t        | j                   |   d         }||kD  s$|}' |S )Nr   r   )r@   len)r   max_lenarg_idxcur_lens       r   get_max_dtype_list_lengthz*_TestPythranFunc.get_max_dtype_list_length   sF    ~~ 	"G$..1!45G !	" r   c                 8    |t        |      dz
  kD  r|d   S ||   S )Nr   )rQ   )r   
dtype_list	dtype_idxs      r   	get_dtypez_TestPythranFunc.get_dtype   s*     s:q((b>!i((r   c                 (   t        | j                               D ]v  }g }| j                  D ]T  }| j                  | j                  |   d   |      }|j	                  | j                  |   d   j                  |             V  | j                  |  x y )Nr   r   )rangerU   r@   rZ   appendastypepythranfunc)r   type_idx
args_arrayrS   	new_dtypes        r   test_all_dtypesz _TestPythranFunc.test_all_dtypes   s    d<<>? 	*HJ>> P NN4>>'+B1+E+35	!!$.."9!"<"C"CI"NOP Dj)	*r   c                     g }| j                   D ]/  }|j                  | j                   |   d   d d d   d d d          1  | j                  |  y )Nr   rW   )r@   r]   r_   r   ra   rS   s      r   
test_viewsz_TestPythranFunc.test_views   sZ    
~~ 	FGdnnW5a82>ttDE	F*%r   c                     g }| j                   D ]?  }|j                  t        j                  | j                   |   d   dd      d d d          A  | j                  |  y )Nr   r   )axis)r@   r]   nprepeatr_   re   s      r   test_stridedz_TestPythranFunc.test_strided   sf    
~~ 	9Gbiiw(?(B()336Q38 9	9 	*%r   N)r   r   r   r   ri   int8int16int32int64intcintpALL_INTEGERfloat32float64	ALL_FLOAT	complex64
complex128ALL_COMPLEXrC   rO   rU   rZ   rc   rf   rk   r   r   r   r   r   q   sz     77BHHbhh"''277KKRZZ(I<</K
)*&&r   r   c                  "    ddl m}   | d      duS )zQ
    Check if the pytest-xdist plugin is installed, providing parallel tests
    r   	find_specxdistN)importlib.utilr{   rz   s    r   r+   r+      s    
 )WT))r   c                 .   ddl }	 t        t        j                  d         }dj	                  | t        j                  d         }|| dz  k  r|j                  |       yy# t
        $ r+ t               }||j                  d       |  d|dz   d}Y Nw xY w)	zJ
    Check *free_mb* of memory is available, otherwise do pytest.skip
    r   NSCIPY_AVAILABLE_MEMz={} MB memory required, but environment SCIPY_AVAILABLE_MEM={}zlCould not determine available memory; set SCIPY_AVAILABLE_MEM variable to free memory in MB to run the test.z MB memory required, but     .Az MB available)r!   _parse_sizer$   environformatKeyError_get_mem_availableskip)free_mbr!   mem_freemsgs       r   r   r      s     	Orzz*?@AMTTRZZ 568 'C-C    O%'KK I J	28C<.NOs   ?A   1BBc                 d   dddddddddddddd	d
}t        j                  dj                  dj                  |j	                                     | t         j
                        }|r|j                  d      |vrt        d      t        |j                  d            ||j                  d         z  S )Nr   g      ?     @@g    eAg   mBg      @g      0Ag      Ag      pB)r   brN   MGTkbMbGbTbkibMibGibTibz^\s*(\d+)\s*({})\s*$|r   zInvalid size stringr   )	rematchr   joinkeysIgroupr(   float)size_strsuffixesms      r   r   r      s    s4Cti	)	UH
 	(//0IJ	A 
(*.//x
333r   c                     	 ddl } | j                         j                  S # t        t        f$ r Y nw xY wt
        j                  j                  d      ri }t        d      5 }|D ]F  }|j                         }t        |d         dz  ||d   j                  d      j                         <   H 	 ddd       n# 1 sw Y   nxY wd|v r|d   S |d	   |d
   z   S y)zD
    Get information about memory available, not counting swap.
    r   Nlinuxz/proc/meminfor   r   :memavailablememfreecached)psutilvirtual_memory	availableImportErrorAttributeErrorr"   platform
startswithopensplitr   striplower)r   infoflineps        r   r   r      s    $$&000(  ||w'/" 	Ba BJJL05adc0AQqTZZ_**,-B	B 	B 	B
 T!''	?T(^33s     22!AB77C )r   r$   r   r"   numpyri   rE   	sysconfig__all__r   get_config_var_vRuntimeWarningr   r   r   r+   r   r   r   r   r   r   <module>r      s   
 
 	 
    O 
 Yo.4"	R<G	> 	
N NbE& E&P**4r   