
    4[g+                        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	 g dZdZ ej4                  d	      xs d
Zdev rdZdej8                  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&y# e$ r dZY kw xY w)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y)FPUModeChangeWarningzWarning about FPU mode changeN)__name__
__module____qualname____doc__     P/var/www/html/bid-api/venv/lib/python3.12/site-packages/scipy/_lib/_testutils.pyr   r   2   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__U   s
    &r   Nc                    dd l }t        j                  | j                     }	t        j
                  j                  |	j                  d         }
ddg}|r|g dz  }|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=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/_uarray   -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__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--.ggoofooa&89%|4 	 	K 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1EE)r"   r   NFFNN)r   r   r   r   r   rA   r   r   r   r   r   7   s    :' KP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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   funcrJ   optional_argskr!   s         r   get_optional_argsz"_TestPythranFunc.get_optional_args   sd     %%d+	((..0DAqyy 1 1 7 77#$99a  1 r   c                 r    d}| j                   D ]%  }t        | j                   |   d         }||kD  s$|}' |S )Nr   r   )rD   len)r   max_lenarg_idxcur_lens       r   get_max_dtype_list_lengthz*_TestPythranFunc.get_max_dtype_list_length   sA    ~~G$..1!45G ! & r   c                 8    |t        |      dz
  kD  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        | j                               D ]v  }g }| j                  D ]T  }| j                  | j                  |   d   |      }|j	                  | j                  |   d   j                  |             V  | j                  |  x y )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>> NN4>>'+B1+E+35	!!$.."9!"<"C"CI"NO * Dj) @r   c                     g }| j                   D ]/  }|j                  | j                   |   d   d d d   d d d          1  | j                  |  y )Nr   r[   )rD   ra   rc   r   re   rW   s      r   
test_viewsz_TestPythranFunc.test_views   sS    
~~GdnnW5a82>ttDE &*%r   c                     g }| j                   D ]?  }|j                  t        j                  | j                   |   d   dd      d d d          A  | j                  |  y )Nr   r$   )axis)rD   ra   nprepeatrc   ri   s      r   test_stridedz_TestPythranFunc.test_strided   sa    
~~Gbiiw(?(B()336Q38 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	      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   r~   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   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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'/"aJJL05adc0AQqTZZ_**,-  #""
 T!''	?T(^33s     22!AB77C c                 R  	 ddl }	 t        j                  ddg       t
        j                  j                  |      d   }t        j                  || |z         | |z  dz  dz  }|d	z  	t        j                  	d
       t        |dz        }t        |d      5 }|j                  d       |j                  dt        j                   d       ddd       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 # t        $ r |j	                  d       Y zw xY w# 1 sw Y   xY w)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  j                        }t        | |      }t        |      }|j                  j	                  |       |S r   )with_suffixr   r   loaderexec_module)modnamesospecmodsuffix
target_dirs       r   loadz$_test_cython_extension.<locals>.loadI  sE    7"//7&w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     s   
 /w45
 ww}}V$Q'H
OOFHx/08#g-0BBIW$JKK
T* i"??@K	k3	1		*S^^,A./ 
  ||ww4.(#i.: #-		  	w.S^M",	  5:F %%l3F d?333U  /-./ 
 	s   E< 5F<FFF&)'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      s  
  	 	   
  D   #w}}^$w7G'HH O 
 Yo.4"	R<G ENN1--	> 	
W WtE& E&P**4224O  Fs   
C CC