o
    i                     @   s   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 deZ	G dd dZ
G dd	 d	Zd
d Zdd Zdd Zdd ZdS )z
Generic test utilities.

    N)PytestTestercheck_free_memory_TestPythranFuncc                   @   s   e Zd ZdZdS )FPUModeChangeWarningzWarning about FPU mode changeN)__name__
__module____qualname____doc__ r
   r
   d/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/scipy/_lib/_testutils.pyr      s    r   c                   @   s&   e Zd ZdZdd Z		d
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                 C   s
   || _ d S N)module_name)selfr   r
   r
   r   __init__3   s   
zPytestTester.__init__fast   NFc              
   C   sR  dd l }tj| j }	tj|	jd }
ddg}|rtd|r%|t	|7 }|r:t
|dkr:|ddt
|d   g7 }|rC|d|
 g7 }|d	krN|d
dg7 }n
|dkrX|d
|g7 }|d u r`| jg}|d ur}|dkr}t rt|dt|g7 }n	dd l}|d |dgt	| 7 }z
||}W |dkS  ty } z|j}W Y d }~|dkS d }~ww )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verboseZ
extra_argvZdoctestsZcoveragetestsZparallelr   modulemodule_pathZpytest_argsr!   r%   excr
   r
   r   __call__6   s@   
zPytestTester.__call__)r   r   NFFNN)r   r   r   r	   r   r,   r
   r
   r
   r   r      s    r   c                   @   s|   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d Zdd Zdd Zdd	 Zd
d Zdd Zd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                 C   s   i | _ d | _d | _d S r   )	argumentsZpartialfuncexpected)r   r
   r
   r   setup_methodv   s   
z_TestPythranFunc.setup_methodc                 C   s>   t |}i }|j D ]\}}|jt jjur|j||< q|S r   )inspect	signature
parametersitemsdefault	Parameterempty)r   funcr1   Zoptional_argskr   r
   r
   r   get_optional_args{   s   

z"_TestPythranFunc.get_optional_argsc                 C   s2   d}| j D ]}t| j | d }||kr|}q|S )Nr   r   )r-   len)r   max_lenarg_idxcur_lenr
   r
   r   get_max_dtype_list_length   s   
z*_TestPythranFunc.get_max_dtype_list_lengthc                 C   s    |t |d kr|d S || S )Nr   )r:   )r   Z
dtype_listZ	dtype_idxr
   r
   r   	get_dtype   s   z_TestPythranFunc.get_dtypec                 C   s`   t |  D ]'}g }| jD ]}| | j| d |}|| j| d | q| j|  qd S )Nr   r   )ranger>   r-   r@   appendZastypepythranfunc)r   Ztype_idx
args_arrayr<   Z	new_dtyper
   r
   r   test_all_dtypes   s   
z _TestPythranFunc.test_all_dtypesc                 C   sF   g }| j D ]}|| j | d d d d d d d  q| j|  d S )Nr   r?   )r-   rB   rC   r   rD   r<   r
   r
   r   
test_views   s   
*z_TestPythranFunc.test_viewsc                 C   sH   g }| j D ]}|tj| j | d dddd d d  q| j|  d S )Nr      )Zaxis)r-   rB   nprepeatrC   rF   r
   r
   r   test_strided   s   
z_TestPythranFunc.test_stridedN)r   r   r   r	   rI   Zint8Zint16Zint32Zint64ZintcZintpZALL_INTEGERZfloat32Zfloat64Z	ALL_FLOATZ	complex64Z
complex128ZALL_COMPLEXr/   r9   r>   r@   rE   rG   rK   r
   r
   r
   r   r   e   s    
		r   c                  C   s   ddl m}  | dduS )zQ
    Check if the pytest-xdist plugin is installed, providing parallel tests
    r   	find_specZxdistN)importlib.utilrM   rL   r
   r
   r   r      s   r   c                 C   s   ddl }zttjd }d| tjd }W n ty3   t }|du r)|d d| |d }Y nw || d k rA|| dS dS )zJ
    Check *free_mb* of memory is available, otherwise do pytest.skip
    r   NZ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)Zfree_mbr   Zmem_freemsgr
   r
   r   r      s"   

r   c                 C   sx   dddddddddddddd	d
}t dd| | t j}|r*|d|vr.tdt|d||d  S )NrO   g      ?     @@g    eAg   mBg      @g      0Ag      Ag      pB) br8   MGTkbZMbZGbZTbZkibZMibZGibZTibz^\s*(\d+)\s*({})\s*$|rH   zInvalid size stringr   )	rematchrR   joinkeysIgroupr   float)Zsize_strsuffixesmr
   r
   r   rP      s   rP   c               	   C   s   z
ddl } |  jW S  ttfy   Y nw tjdr\i }td"}|D ]}|	 }t
|d d ||d d < q%W d   n1 sGw   Y  d|v rT|d S |d	 |d
  S dS )zD
    Get information about memory available, not counting swap.
    r   Nlinuxz/proc/meminfor   rW   :ZmemavailableZmemfreecached)psutilZvirtual_memory	availableImportErrorAttributeErrorr   platform
startswithopensplitre   striplower)rk   infoflinepr
   r
   r   rT      s$   
$rT   )r	   r   r_   r   numpyrI   r0   __all__RuntimeWarningr   r   r   r   r   rP   rT   r
   r
   r
   r   <module>   s    PH	