a
    «ˆc½  ã                   @   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
   úX/home/yuhw/wc/wire-cell-python/wcpy/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   z)
    Pytest test runner entry point.
    c                 C   s
   || _ d S ©N)Úmodule_name)Úselfr   r
   r
   r   Ú__init__   s    zPytestTester.__init__Úfasté   NFc              
   C   sP  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}| d¡ |dgt	|ƒ 7 }z| |¡}W n, t�yF } 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.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ÚtestsÚparallelr   ÚmoduleÚmodule_pathZpytest_argsr!   r%   Úexcr
   r
   r   Ú__call__   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_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   Úfuncr2   Zoptional_argsÚkr   r
   r
   r   Úget_optional_argsb   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_lengthl   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_dtypeu   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   )Úranger?   r.   rA   Ú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.   rC   rD   ©r   rE   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.   rC   ÚnpÚrepeatrD   rG   r
   r
   r   Útest_stridedŒ   s    
ÿÿz_TestPythranFunc.test_stridedN)r   r   r   r	   rJ   Zint8Úint16Úint32Úint64ZintcZintpZALL_INTEGERÚfloat32Úfloat64Z	ALL_FLOATZ	complex64Z
complex128ZALL_COMPLEXr0   r:   r?   rA   rF   rH   rL   r
   r
   r
   r   r   L   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)Z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yf   tƒ }|du rR| 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?{0} MB memory required, but environment SCIPY_AVAILABLE_MEM={1}zlCould not determine available memory; set SCIPY_AVAILABLE_MEM variable to free memory in MB to run the test.z,{0} MB memory required, but {1} 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¡}|rT| d¡|vr\tdƒ‚t| d¡ƒ|| d¡  S )NrT   g      ð?ç     @�@g    eÍÍAg   ¢”mBg      �@g      0Ag      ÐAg      pB)Ú Úbr9   ÚMÚGÚTÚkbZMbZGbZTbZkibZMibZGibZTibz^\s*(\d+)\s*({0})\s*$ú|rI   zInvalid size stringr   )	ÚreÚmatchrW   ÚjoinÚkeysÚIÚgroupr   Úfloat)Zsize_strÚsuffixesÚmr
   r
   r   rU   ³   s    üþrU   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}|D ].}| 	¡ }t
|d ƒd ||d  d¡ ¡ < qLW 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/meminfoÚrr   r\   ú:ZmemavailableZmemfreeÚcached)ÚpsutilZvirtual_memoryÚ	availableÚImportErrorÚAttributeErrorr   ÚplatformÚ
startswithÚopenÚsplitrj   ÚstripÚlower)rq   ÚinfoÚfÚlineÚpr
   r
   r   rY   Â   s    BrY   )r	   r   rd   r   ÚnumpyrJ   r1   Ú__all__ÚRuntimeWarningr   r   r   r   r   rU   rY   r
   r
   r
   r   Ú<module>   s   7H	