
    Ug+                        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ddlZddlm	Z	m
Z
 ddlZddlZ	 ddlZddlmZ ddlmZ dZ ej        e           ej        e          k     rdZn# e$ r dZY nw xY wg dZdZ ej        d	          pd
Zdev rdZdej        d         v Z G d de          Z G d d          Z  G d d          Z!d Z"d Z#d Z$d Z%d Z&dS )z
Generic test utilities.

    N)module_from_specspec_from_file_location)version)_pep440z3.0.8)PytestTestercheck_free_memory_TestPythranFuncIS_MUSLFHOST_GNU_TYPE muslTeditablec                       e Zd ZdZdS )FPUModeChangeWarningzWarning about FPU mode changeN)__name__
__module____qualname____doc__     T/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/scipy/_lib/_testutils.pyr   r   2   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__U   s    &r   fast   NFc                    dd l }t          j        | j                 }	t          j                            |	j        d                   }
ddg}|r|g dz  }|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}|D|dk    r>t                      r|dt          |          gz  }ndd l}|                    d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=short)z--doctest-modulesz,--ignore=scipy/interpolate/_interpnd_info.pyz$--ignore=scipy/_lib/array_api_compatz--ignore=scipy/_lib/highsz--ignore=scipy/_lib/unuranz--ignore=scipy/_lib/_gcutils.pyz--ignore=scipy/_lib/doccer.pyz--ignore=scipy/_lib/_uarrayr   -vz--cov=r   z-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__listint_pytest_has_xdiststrwarningswarnmain
SystemExitcode)r   labelverbose
extra_argvdoctestscoveragetestsparallelr&   modulemodule_pathpytest_argsr1   r5   excs                  r   __call__zPytestTester.__call__X   s   T-.goofoa&899%|4 
	 	 	 	 	K  	,4
+++K 	8s7||a''C#s7||A~"6677K 	4H{233KF??D*--KKf__D%=(K=%&EHqLL "" ,c(mm44 F)*  , , , 	
|d5kk11	;;{++DD 	 	 	8DDDDDD	 	s   %D; ;
EEE)r   r   NFFNN)r   r   r   r   r   rA   r   r   r   r   r   7   sK         :' ' ' KP6:6 6 6 6 6 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_method   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   funcrJ   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   )rD   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   )rU   )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   )rangerY   rD   r^   appendastypepythranfunc)r   type_idx
args_arrayrW   	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   r[   )rD   ra   rc   r   re   rW   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   r$   )axis)rD   ra   nprepeatrc   ri   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   rm   int8int16int32int64intcintpALL_INTEGERfloat32float64	ALL_FLOAT	complex64
complex128ALL_COMPLEXrG   rS   rY   r^   rg   rj   ro   r   r   r   r	   r	      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.utilr   r~   s    r   r/   r/      s+    
 )(((((9WT))r   c                 \   ddl }	 t          t          j        d                   }d                    | t          j        d                   }n@# t
          $ r3 t                      }||                    d           |  d|dz   d}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     .Az MB available)r&   _parse_sizer)   environformatKeyError_get_mem_availableskip)free_mbr&   mem_freemsgs       r   r   r      s     MMM	Orz*?@AAMTTRZ 568 8 O O O%''KK I J J JNN8C<NNNO 'C-C  s   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)r   brR   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group
ValueError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c                   	 ddl }	 t          j        ddg           n%# t          $ r |                    d           Y nw xY wt
          j                            |          d         }t          j	        || |z             | |z  dz  dz  }|d	z  	t          j
        	d
           t          |dz            }t          |d          5 }|                    d           |                    dt          j         d           ddd           n# 1 swxY w Y   t          j        dk    r+t          j        dddd|dt          |          g	           n(t          j        ddd|t          |          g	           t          j        g d	           t#          j        d          	fd} |d           |d          fS )z
    Helper function to test building and importing Cython modules that
    make use of the Cython APIs for BLAS, LAPACK, optimize, and special.
    r   Nmesonz	--versionzNo usable 'meson' foundr   r;   _cython_examplesbuildT)exist_okzinterpreter-native-file.iniwz[binaries]
z
python = ''win32setupz--buildtype=releasez--native-filez--vsenv)cwd)r   compilez-vv
EXT_SUFFIXc                     | z                                 }t          | |          }t          |          }|j                            |           |S r   )with_suffixr   r   loaderexec_module)modnamesospecmodsuffix
target_dirs       r   loadz$_test_cython_extension.<locals>.loadI  sR    7"//77&w33t$$$$$
r   	extendingextending_cpp)r&   
subprocess
check_callFileNotFoundErrorr   r)   r*   r   shutilcopytreemakedirsr0   r   writer'   
executabler   	sysconfigget_config_var)
tmp_pathsrcdirr&   mod_name	build_dirnative_filer   r   r   r   s
           @@r   _test_cython_extensionr     sd   
 MMM/w45555 / / /-...../ w}}V$$Q'H
OFHx/0008#g-0BBIW$JK
T**** i"??@@K	k3		 01		.S^...///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |ww4.(#i..: #-		  	  	  	  	  	w.S^^M",	  	  	  	  555:FFFF %l33F      4dd?3333s!    A A	9DDD)'r   rI   r)   r   r   r   r'   r   r   r   r   numpyrm   scipycythonCython.Compiler.Versionr   cython_version
scipy._libr   required_versionparseVersionr   __all__r
   r   _vr,   IS_EDITABLERuntimeWarningr   r   r	   r/   r   r   r   r   r   r   r   <module>r      sI   
  				 				      



     D D D D D D D D     MMM      #"""""w}^$$w7G'H'HHH    FFF O
N
N 
 Yo..4"	R<<G EN1--	 	 	 	 	> 	 	 	
W W W W W W W WtE& E& E& E& E& E& E& E&P* * *  *4 4 4  224 24 24 24 24s   
A' 'A10A1