a
    BCCf                     @   s   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
dpLdZdev rZd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_TestPythranFuncIS_MUSLFHOST_GNU_TYPE muslTc                   @   s   e Zd ZdZdS )FPUModeChangeWarningzWarning about FPU mode changeN)__name__
__module____qualname____doc__ r   r   Q/var/www/html/django/DPS/env/lib/python3.9/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__>   s    zPytestTester.__init__fast   NFc              
   C   sT  dd l }tj| j }	tj|	jd }
ddg}|r:td|rJ|t	|7 }|rtt
|dkrt|ddt
|d   g7 }|r|d|
 g7 }|d	kr|d
dg7 }n|dkr|d
|g7 }|d u r| jg}|d ur|dkrt r|dt|g7 }ndd l}|jddd |dgt	| 7 }z||}W n, tyJ } z|j}W Y d }~n
d }~0 0 |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.   )
stacklevelz--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testsparallelr   modulemodule_pathZpytest_argsr'   r+   excr   r   r   __call__A   s>    zPytestTester.__call__)r   r   NFFNN)r
   r   r   r   r   r3   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_method   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   funcr8   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   )r4   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 d S )Nr   )rA   )r   Z
dtype_listZ	dtype_idxr   r   r   	get_dtype   s    z_TestPythranFunc.get_dtypec                 C   s`   t |  D ]N}g }| jD ]4}| | j| d |}|| j| d | q| j|  qd S )Nr   r   )rangerE   r4   rG   appendZastypepythranfunc)r   Ztype_idx
args_arrayrC   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   rF   )r4   rI   rJ   r   rK   rC   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   r   )Zaxis)r4   rI   nprepeatrJ   rM   r   r   r   test_strided   s    
z_TestPythranFunc.test_stridedN)r
   r   r   r   rO   Zint8Zint16Zint32Zint64ZintcZintpZALL_INTEGERZfloat32Zfloat64Z	ALL_FLOATZ	complex64Z
complex128ZALL_COMPLEXr6   r@   rE   rG   rL   rN   rQ   r   r   r   r   r   q   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.utilrS   rR   r   r   r   r%      s    r%   c                 C   s   ddl }z$ttjd }d| tjd }W n> tyj   t }|du rR|d |  d|d  d}Y n0 || d k r|| 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     .Az MB available)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}|rT|d|vr\tdt|d||d  S )NrU   g      ?     @@g    eAg   mBg      @g      0Ag      Ag      pB)r   br?   MGTkbZMbZGbZTbZkibZMibZGibZTibz^\s*(\d+)\s*({})\s*$|r   zInvalid size stringr   )	rematchrX   joinkeysIgroupr"   float)Zsize_strsuffixesmr   r   r   rV      s    rV   c               	   C   s   zddl } |  jW S  ttfy*   Y n0 tjdri }tdD}|D ].}|	 }t
|d d ||d d < qJW d   n1 s0    Y  d|v r|d S |d	 |d
  S dS )zD
    Get information about memory available, not counting swap.
    r   Nlinuxz/proc/meminfor   r]   :ZmemavailableZmemfreecached)psutilZvirtual_memory	availableImportErrorAttributeErrorr   platform
startswithopensplitrj   striplower)rp   infoflinepr   r   r   rZ      s    
BrZ   )r   r   rd   r   numpyrO   r7   	sysconfig__all__r   get_config_var_vRuntimeWarningr	   r   r   r%   r   rV   rZ   r   r   r   r   <module>   s$   QH	