o
    i4                     @   s.  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 d dl	T d dl
Zd dlmZ d dlmZ d dlmZmZmZmZmZmZ d dlZdZeejd eZejeje Z!dd	 Z"eG d
d deZ#G dd deZ$eG dd de$Z%eG dd deZ&e'dkre(  dS dS )    N)skip)*)utils)TestCasetagimport_dynamictemp_directoryhas_blasneeds_setuptoolszwindows onlywinc                   C   s   dt jv rt jd= dS dS )zVUnset MACOSX_DEPLOYMENT_TARGET because we are not building portable
    libraries
    MACOSX_DEPLOYMENT_TARGETN)osenviron r   r   d/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/numba/tests/test_pycc.pyunset_macosx_deployment_target   s   
r   c                   @   s   e Zd Zedd ZdS )TestCompilerChecksc                 C   sL   ddl m} tjdd d u}|r"tjdd d ur$| |  d S d S d S )Nr   )external_compiler_worksZCONDA_BUILDZVSINSTALLDIR)numba.pycc.platformr   r   r   get
assertTrue)selfr   Zis_running_conda_buildr   r   r   test_windows_compiler_validity*   s   z1TestCompilerChecks.test_windows_compiler_validityN)__name__
__module____qualname___windows_onlyr   r   r   r   r   r   &   s    r   c                   @   s*   e Zd Zdd Zdd Zejdd ZdS )BasePYCCTestc                 C   s   t   td| _| jt_d S )NZ	test_pycc)r   r   tmpdirtempfiletempdirr   r   r   r   setUp;   s   
zBasePYCCTest.setUpc                 C   s   d t _ddlm} |  d S )Nr   )clear_export_registry)r   r    Znumba.pycc.decoratorsr#   )r   r#   r   r   r   tearDownC   s   
zBasePYCCTest.tearDownc              
   c   sZ    t j| zt|}|V  W t j| t j|d  d S t j| t j|d  w N)syspathappendr   removemodulespop)r   Zextdirnamelibr   r   r   check_c_extN   s   zBasePYCCTest.check_c_extN)r   r   r   r"   r$   
contextlibcontextmanagerr.   r   r   r   r   r   9   s
    r   c                       s   e Zd Z fddZejdd Zdd Zdd Zd	d
 Z	dd Z
dd Zdd Zeejdko4ejdkddd Zdd Zdd Zdd Z  ZS )TestCCc                    s8   t t|   |   ddlm} || _t| j d S )Nr   )compile_with_pycc)	superr1   r"   skip_if_no_external_compilerZnumba.testsr2   _test_module	importlibreload)r   r2   	__class__r   r   r"   \   s
   zTestCC.setUpc                 c   sN    | j |_|  | | j |j}|V  W d    d S 1 s w   Y  d S r%   )r   
output_dircompiler.   r,   )r   ccr-   r   r   r   check_cc_compiledc   s   "zTestCC.check_cc_compiledc                 C   s>   d|j tj|jd }|d| }ttj	d|g d S )Na  if 1:
            import sys
            import types
            # to disable numba package
            sys.modules['numba'] = types.ModuleType('numba')
            try:
                from numba import njit
            except ImportError:
                pass
            else:
                raise RuntimeError('cannot disable numba package')

            sys.path.insert(0, %(path)r)
            import %(name)s as lib
            )r,   r'    -c)
r   r   r'   dirname__file__strip
subprocess
check_callr&   
executable)r   r-   codeprologr   r   r   check_cc_compiled_in_subprocessl   s   z&TestCC.check_cc_compiled_in_subprocessc                 C   s   | j j}| |jd | j jj}| tj|| | j jj	}| 
tj|| | tj|d| tjdrT| |d| ddlm} | | | d S d S )Npycc_test_simplezpycc_test_simple.linuxz.sor   )find_pyext_ending)r5   r<   assertEqualr,   r:   r   r   r'   isdirZoutput_fileZassertFalseexistsbasename
startswithr&   platformendswithr   rK   ZassertIn)r   r<   dfrK   r   r   r   test_cc_properties   s   

zTestCC.test_cc_propertiesc              	   C   s   |  | jjW}|dd}| |d |dd}| |d |d}| |d | | d  | 	t
 |dd	 W d    n1 sIw   Y  W d    d S W d    d S 1 saw   Y  d S )
N{   A  ;  i  g    lVA         r   )r=   r5   r<   multiassertPreciseEqualZmultfZsquareZassertIsZget_noneassertRaisesZeroDivisionErrordiv)r   r-   resr   r   r   test_compile   s   
"zTestCC.test_compilec                 C   sf   | j j}||_| |}|dd}| |d | |jjd W d    d S 1 s,w   Y  d S )NrV   rW   rX   rI   )r5   r<   Z
target_cpur=   r\   r]   rL   r   )r   Zcpu_namer<   r-   ra   r   r   r   check_compile_for_cpu   s   "zTestCC.check_compile_for_cpuc                 C   s   |  t  d S r%   )rc   llZget_host_cpu_namer!   r   r   r   test_compile_for_cpu   s   zTestCC.test_compile_for_cpuc                 C      |  d d S )Nhost)rc   r!   r   r   r   test_compile_for_cpu_host   s   z TestCC.test_compile_for_cpu_hostdarwin)      z4distutils incorrectly using gcc on python 3.8 buildsc                 C   s2  |  | jj}|dd}| |d ddtdfD ]}||}| |d qddtdfD ]}|	|}| |d	 q2|
d
}| |d | |d|d |d}tjd }| || |tdgd }| |d dd|i }| || W d    d S 1 sw   Y  d S )N         y              y              ?         @       @      ?g      <*   r   rj   aR  if 1:
                from numpy.testing import assert_equal, assert_allclose
                res = lib.power(2, 7)
                assert res == 128
                res = lib.random(42)
                assert_allclose(res, %(expected)s)
                res = lib.spacing(1.0)
                assert_allclose(res, 2**-52)
                expected)r=   r5   Zcc_helperlibpowerr]   npZ
complex128sqrtfloat64Znp_sqrtspacingZassertNotEqualrandomZRandomStateZrandom_samplesizerH   r   r-   ra   valru   rF   r   r   r   test_compile_helperlib   s,   



	"zTestCC.test_compile_helperlibc                 C   s   |  | jjR}| |dd |d}| t|g d tr-|	d}| |d t
g d}||}t
|}| || dttd	 }| || W d    d S 1 s\w   Y  d S )
Nr[   g        rj   )r   r   r   rp   g      >@)rr   g      @rs   g      @rq   aB  if 1:
                from numpy.testing import assert_equal
                from numpy import float64, argsort
                res = lib.zero_scalar(1)
                assert res == 0.0
                res = lib.zeros(3)
                assert list(res) == [0, 0, 0]
                if %(has_blas)s:
                    res = lib.vector_dot(4)
                    assert res == 30.0
                val = float64([2., 5., 1., 3., 4.])
                res = lib.np_argsort(val)
                expected = argsort(val)
                assert_equal(res, expected)
                )r	   )r=   r5   cc_nrtr]   Zzero_scalarZzerosrL   listr	   Z
vector_dotrw   ry   Z
np_argsortZargsortdictrH   r}   r   r   r   test_compile_nrt   s    



"zTestCC.test_compile_nrtc                 C   sv   |  | jj*}| }| |td |d}| |td d}| || W d    d S 1 s4w   Y  d S )NAzif 1:
                from numpy.testing import assert_equal
                res = lib.hash_literal_str_A()
                assert_equal(res, hash("A"))
                res = lib.hash_str("A")
                assert_equal(res, hash("A"))
                )r=   r5   r   Zhash_literal_str_Ar]   hashZhash_strrH   )r   r-   ra   rF   r   r   r   test_hashing   s   
"zTestCC.test_hashingc                 C   sb   |  | jj }tjdtjd}||}|| }| || W d    d S 1 s*w   Y  d S )Nrn   )Zdtype)r=   r5   r   rw   ZarangeZintpZdict_usecaser]   )r   r-   Zarrgotexpectr   r   r   test_c_extension_usecase  s   
"zTestCC.test_c_extension_usecase)r   r   r   r"   r/   r0   r=   rH   rU   rb   rc   re   rh   unittestskipIfr&   rQ   r   Z	PYVERSIONr   r   r   r   __classcell__r   r   r8   r   r1   Y   s$    
	
  r1   c                       sL   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	  Z
S )TestDistutilsSupportc                    sT   t    |   t  td| _tjt	d}tj| jd| _
t|| j
 d S )NZtest_pycc_distutilsZpycc_distutils_usecaseZwork)r3   r"   r4   r   r   r   r   r'   join	base_pathusecase_dirshutilcopytree)r   
source_dirr8   r   r   r"     s   

zTestDistutilsSupport.setUpc                       dd l }tjtjtj|j}ttj  ddr*|tj	  d   d< n| d<  fdd}||ddg d}|d	|g d S )
Nr   
PYTHONPATH c                    \   t jtjg|  jt jt j d}| \}}| }|dkr,	d|
dd  d S d S N)cwdstdoutstderrenvr   z+python failed with the following output:
%szutf-8ignorerC   Popenr&   rE   r   PIPESTDOUTcommunicatewaitZfaildecodeargspout_rcr   r   r   r   
run_python'     

z7TestDistutilsSupport.check_setup_py.<locals>.run_python	build_ext	--inplacezif 1:
            import pycc_compiled_module as lib
            assert lib.get_const() == 42
            res = lib.ones(3)
            assert list(res) == [1.0, 1.0, 1.0]
            r?   
numbar   r'   abspathr@   rA   r   r   r   pathsepr   Zsetup_py_filer   Z
numba_pathr   rF   r   r   r   check_setup_py     
z#TestDistutilsSupport.check_setup_pyc                    r   )
Nr   r   r   c                    r   r   r   r   r   r   r   r   G  r   z>TestDistutilsSupport.check_setup_nested_py.<locals>.run_pythonr   r   zif 1:
            import nested.pycc_compiled_module as lib
            assert lib.get_const() == 42
            res = lib.ones(3)
            assert list(res) == [1.0, 1.0, 1.0]
            r?   r   r   r   r   r   check_setup_nested_py<  r   z*TestDistutilsSupport.check_setup_nested_pyc                 C   rf   )Nzsetup_distutils.pyr   r!   r   r   r   test_setup_py_distutils\     z,TestDistutilsSupport.test_setup_py_distutilsc                 C   rf   )Nzsetup_distutils_nested.pyr   r!   r   r   r   test_setup_py_distutils_nested_  r   z3TestDistutilsSupport.test_setup_py_distutils_nestedc                 C   rf   )Nzsetup_setuptools.pyr   r!   r   r   r   test_setup_py_setuptoolsb  r   z-TestDistutilsSupport.test_setup_py_setuptoolsc                 C   rf   )Nzsetup_setuptools_nested.pyr   r!   r   r   r   test_setup_py_setuptools_nestede  r   z4TestDistutilsSupport.test_setup_py_setuptools_nested)r   r   r   r"   r   r   r   r   r   r   r   r   r   r8   r   r     s      r   __main__))r/   r6   r   r   rC   r&   r   r   r   ctypesnumpyrw   Zllvmlite.bindingZbindingrd   Z
numba.corer   Znumba.tests.supportr   r   r   r   r	   r
   Z_skip_reasonr   rQ   rP   r   r'   r@   r   rA   r   r   r   r   r1   r   r   mainr   r   r   r   <module>   s>       3\