a
    ˆù»jÃ   ã                   @   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_MUSLFZ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   ú;E:\soccer\ml_env\Lib\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rþtƒ 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coverageZ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   r1   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   Úfuncr6   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   )r2   Ú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   éÿÿÿÿ)r?   )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   )ÚrangerC   r2   rE   ÚappendZastypeÚpythranfunc)r   Ztype_idxÚ
args_arrayrA   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   rD   )r2   rG   rH   ©r   rI   rA   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)r2   rG   ÚnpÚrepeatrH   rK   r   r   r   Útest_strided±   s    
ÿÿz_TestPythranFunc.test_stridedN)r	   r
   r   r   rM   Zint8Zint16Zint32Zint64ZintcZintpZALL_INTEGERZfloat32Zfloat64Z	ALL_FLOATZ	complex64Z
complex128ZALL_COMPLEXr4   r>   rC   rE   rJ   rL   rO   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.utilrQ   rP   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 )NrS   g      ð?ç     @�@g    eÍÍAg   ¢”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ÚmatchrV   ÚjoinÚkeysÚIÚgroupr!   Úfloat)Úsize_strÚsuffixesÚmr   r   r   rT   ×   s    üþrT   c               	   C   s¼   zddl } |  ¡ jW S  ttfy*   Y n0 tj d¡r¸i }tdƒ�D}|D ].}| 	¡ }t
|d ƒd ||d  d¡ ¡ < qJW d  ƒ n1 sŽ0    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Úsplitrh   ÚstripÚlower)ro   ÚinfoÚfÚlineÚpr   r   r   rX   æ   s    
BrX   )r   r   rb   r   ÚnumpyrM   r5   Ú	sysconfigÚ__all__r   Úget_config_varÚ_vÚRuntimeWarningr   r   r   r$   r   rT   rX   r   r   r   r   Ú<module>   s$   QH	