
    ge                         d Z ddlZddlZddlZddlZddlZg dZ G d de          Z	 G d d          Z
 G d d	          Zd
 Zd Zd Zd ZdS )z
Generic test utilities.

    N)PytestTestercheck_free_memory_TestPythranFuncc                       e Zd ZdZdS )FPUModeChangeWarningzWarning about FPU mode changeN)__name__
__module____qualname____doc__     5lib/python3.11/site-packages/scipy/_lib/_testutils.pyr   r      s        ''Dr   r   c                   $    e Zd ZdZd Z	 	 ddZdS )	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                     || _         d S N)module_name)selfr   s     r   __init__zPytestTester.__init__3   s    &r   fast   NFc                    dd l }t          j        | j                 }	t          j                            |	j        d                   }
ddg}|rt          d          |r|t          |          z  }|r/t          |          dk    r|ddt          |          dz
  z  z   gz  }|r	|d|
z   gz  }|d	k    r|d
dgz  }n|dk    r|d
|gz  }|| j        g}|B|dk    r<t                      r|dt          |          gz  }ndd l}|                    d           |dgt          |          z   z  }	 |                    |          }n# t           $ r}|j        }Y d }~nd }~ww xY w|dk    S )Nr   z--showlocalsz
--tb=shortzDoctests not supportedr   -vz--cov=r   z-mznot slowfullz-nzMCould not run tests in parallel because pytest-xdist plugin is not available.z--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'   r+   excs                  r   __call__zPytestTester.__call__6   s   T-.goofoa&899%|4 	75666 	,4
+++K 	8s7||a''C#s7||A~"6677K 	4H{233KF??D*--KKf__D%=(K=%&EHqLL "" Gc(mm44 F G G G 	
|d5kk11	;;{++DD 	 	 	8DDDDDD	 	s   +E 
EEE)r   r   NFFNN)r   r	   r
   r   r   r7   r   r   r   r   r      sK         :' ' ' 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d	S )
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                 0    i | _         d | _        d | _        d S r   )	argumentspartialfuncexpected)r   s    r   setup_methodz_TestPythranFunc.setup_methodv   s    r   c                     t          j        |          }i }|j                                        D ]'\  }}|j        t           j        j        ur
|j        ||<   (|S r   )inspect	signature
parametersitemsdefault	Parameterempty)r   funcr@   optional_argskr   s         r   get_optional_argsz"_TestPythranFunc.get_optional_args{   sa     %d++	(..00 	- 	-DAqy 1 777#$9a r   c                 n    d}| j         D ]*}t          | j         |         d                   }||k    r|}+|S )Nr   r   )r:   len)r   max_lenarg_idxcur_lens       r   get_max_dtype_list_lengthz*_TestPythranFunc.get_max_dtype_list_length   sG    ~ 	" 	"G$.1!455G  !r   c                 N    |t          |          dz
  k    r|d         S ||         S )Nr   )rK   )r   
dtype_list	dtype_idxs      r   	get_dtypez_TestPythranFunc.get_dtype   s/     s:q(((b>!i((r   c                 :   t          |                                           D ]x}g }| j        D ]b}|                     | j        |         d         |          }|                    | j        |         d                             |                     c | j        |  yd S )Nr   r   )rangerO   r:   rT   appendastypepythranfunc)r   type_idx
args_arrayrM   	new_dtypes        r   test_all_dtypesz _TestPythranFunc.test_all_dtypes   s    d<<>>?? 	* 	*HJ> P P NN4>'+B1+E+35 5	!!$."9!"<"C"CI"N"NOOOODj)))	* 	*r   c                     g }| j         D ]:}|                    | j         |         d         d d d         d d d                    ; | j        |  d S )Nr   rQ   )r:   rW   rY   r   r[   rM   s      r   
test_viewsz_TestPythranFunc.test_views   si    
~ 	F 	FGdnW5a82>tttDEEEE*%%%%r   c                     g }| j         D ]F}|                    t          j        | j         |         d         dd          d d d                    G | j        |  d S )Nr      )axis)r:   rW   nprepeatrY   r_   s      r   test_stridedz_TestPythranFunc.test_strided   s    
~ 	9 	9Gbiw(?(B()3 3 3363Q38 9 9 9 9*%%%%r   N)r   r	   r
   r   rd   int8int16int32int64intcintpALL_INTEGERfloat32float64	ALL_FLOAT	complex64
complex128ALL_COMPLEXr=   rI   rO   rT   r]   r`   rf   r   r   r   r   r   e   s          7BHbh"'27KKRZ(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.utilrv   ru   s    r   r%   r%      s+    
 )(((((9WT))r   c                 x   ddl }	 t          t          j        d                   }d                    | t          j        d                   }nN# t
          $ rA t                      }||                    d           d                    | |dz            }Y nw xY w|| dz  k     r|                    |           dS dS )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 {} MB available    .A)r   _parse_sizer   environformatKeyError_get_mem_availableskip)free_mbr   mem_freemsgs       r   r   r      s     MMM
#rz*?@AAMTTRZ 568 8 # # #%''KK I J J J:AAXc\# ## 'C-C  s   AA ABBc                    dddddddddddddd	d
}t          j        d                    d                    |                                                    | t           j                  }|r|                    d          |vrt          d          t          |                    d                    ||                    d                   z  S )Nr{   g      ?     @@g    eAg   mBg      @g      0Ag      Ag      pB) brH   MGTkbMbGbTbkibMibGibTibz^\s*(\d+)\s*({})\s*$|rb   zInvalid size stringr   )	rematchr~   joinkeysIgroupr"   float)size_strsuffixesms      r   r|   r|      s    s4Cti	)	U UH
 	(//0I0IJJ	 	A  0

(**.///x

333r   c                     	 ddl } |                                 j        S # t          t          f$ r Y nw xY wt
          j                            d          ri }t          d          5 }|D ]\}|	                                }t          |d                   dz  ||d                             d                                          <   ]	 ddd           n# 1 swxY w Y   d|v r|d         S |d	         |d
         z   S dS )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      sc   $$&&00(    |w'' 4/"" 	Ba B BJJLL05adc0AQqTZZ__**,,--B	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B
 T!!''	?T(^334s    33&A CCC)r   r   r   r   numpyrd   r?   __all__RuntimeWarningr   r   r   r%   r   r|   r   r   r   r   <module>r      s!   
 
			 				 



      D
C
C	 	 	 	 	> 	 	 	
M M M M M M M M`E& E& E& E& E& E& E& E&P* * *  ,4 4 4    r   