
    .|h                         d dl Z d dlm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
mZ d dlmZ d dlmZ edz
  Z G d d	e      Z G d
 de      Zy)    N)mock)njit)TestCase)_TIMEOUT)metadatag      N@c                       e Zd Zd Zd Zy)_DummyClassc                     || _         y Nvalue)selfr   s     [/var/www/html/test/engine/venv/lib/python3.12/site-packages/numba/tests/test_entrypoints.py__init__z_DummyClass.__init__   s	    
    c                      d| j                   z  S )Nz_DummyClass(%f, %f)r   )r   s    r   __repr__z_DummyClass.__repr__   s    $tzz11r   N)__name__
__module____qualname__r   r    r   r   r	   r	      s    2r   r	   c                       e Zd ZdZd Zd ZdZ ej                  e	j                  j                  dd      ek7  d      d        Zd	 Zd
 Zy)TestEntrypointszE
    Test registration of init() functions from Numba extensions
    c                    t        j                  d      }	 |t        j                  |j                  <   t        j                  ddd      }t         j                  j                  t
        dd|fi      5  dd	l	m
} d
|_        |j                          |j                  j                          |j                          |j                  j                          d d d        |j                  t        j                  v rt        j                  |j                  = y y # 1 sw Y   BxY w# |j                  t        j                  v rt        j                  |j                  = w w xY w)N_test_numba_extensionr   initz_test_numba_extension:init_funcnumba_extensionsentry_pointsreturn_valuer   entrypointsF)r   Mocksysmodulesr   importlib_metadata
EntryPointpatchobject
numba.corer#   _already_initializedinit_all	init_funcassert_called_once)r   modmy_entrypointr#   s       r   test_init_entrypointz$TestEntrypoints.test_init_entrypoint!   s    ii!89	.(+CKK%.999;MM """0=2BC #  3 3 490$$& 002 $$&002%3* ||s{{*KK- ++3 3* ||s{{*KK- +s%   AD$ 5A"DD$ D!D$ $:Ec                 D   t        j                  d      } |j                  di dt        d      i 	 |t        j
                  |j                  <   t        j                  ddd      }t         j                  j                  t        dd|fi	      5  d
dlm} d|_        t        j                  d      5 }|j!                          d d d        d}D ]  }|t#        |      v s n t        d      |j$                  j'                          d d d        |j                  t        j
                  v rt        j
                  |j                  = y y # 1 sw Y   xY w# 1 sw Y   NxY w# |j                  t        j
                  v rt        j
                  |j                  = w w xY w)N_test_numba_bad_extensionr   zinit_func.side_effectbrokenr   z#_test_numba_bad_extension:init_funcr   r   r    r   r"   FT)recordz2Numba extension module '_test_numba_bad_extension'z"Expected warning message not foundr   )r   r$   configure_mock
ValueErrorr%   r&   r   r'   r(   r)   r*   r+   r#   r,   warningscatch_warningsr-   strr.   r/   )r   r0   r1   r#   wbad_strxs          r   test_entrypoint_tolerancez)TestEntrypoints.test_entrypoint_toleranceG   su    ii!<=M5z(7KLM$	.(+CKK%.995"M """0=2BC #  3 3380,,D9 +Q((*+ O KA#a&(K %%IJJ 002+32 ||s{{*KK- ++ +3 32 ||s{{*KK- +sB   AE% $E6EE$(EE% E	EE"E% %:F	RUN_ENTRY_EP_MAGIC_TOKENNzneeds tokenc                 ^   dd l fd}t        j                  d      }||_        	 |t        j
                  |j                  <   t        j                  ddd      }t        j                  j                  t        dd|fi      5  t        d	        }t        d
      } ||       d d d        |j                  t        j
                  v rt        j
                  |j                  = y y # 1 sw Y   BxY w# |j                  t        j
                  v rt        j
                  |j                  = w w xY w)Nr   c                      G fddj                   j                        j                  j                  j	                  t
              fd       } j                  j                         G fddj                  j                  j                               j                  j                        fd       }j                  j                        fd       }y )Nc                   "     e Zd Z fdZ xZS )aTestEntrypoints.test_entrypoint_handles_type_extensions.<locals>.init_function.<locals>.DummyTypec                 &    t         |   d       y )N	DummyType)name)superr   )r   rG   	__class__s    r   r   zjTestEntrypoints.test_entrypoint_handles_type_extensions.<locals>.init_function.<locals>.DummyType.__init__   s    )T33Er   r   r   r   r   __classcell__)rJ   rG   s   @r   rG   rE      s    F Fr   rG   c                             S r   r   )valcrG   s     r   typer_DummyClasszhTestEntrypoints.test_entrypoint_handles_type_extensions.<locals>.init_function.<locals>.typer_DummyClass   s     {"r   c                   $     e Zd Z fdZ xZS )bTestEntrypoints.test_entrypoint_handles_type_extensions.<locals>.init_function.<locals>.DummyModelc                 Z    dj                   j                  fg}t        |   |||       y )Nr   )typesfloat64rI   r   )r   dmmfe_typemembers
DummyModelrJ   numbas       r   r   zkTestEntrypoints.test_entrypoint_handles_type_extensions.<locals>.init_function.<locals>.DummyModel.__init__   s/     %++"5"56:G*d4S'7Kr   rK   )rJ   rY   rZ   s   @r   rY   rR      s    L Lr   rY   c                     |j                   j                  |d      }j                  j                  j	                  |       } ||j
                  |j                        }|j                   j                  |      |_        |j                   j                  |       |j                   j                         }j                  j                  j                  |j                  |      }j                  j                  |j                         |      S )Nr   )is_error)pyapiobject_getattr_stringcorecgutilscreate_struct_proxycontextbuilderfloat_as_doubler   decreferr_occurredis_not_null	extendingNativeValue	_getvalue)	typobjrO   	value_objdummy_struct_proxydummy_structerr_flagr\   rZ   s	           r   unbox_dummyzcTestEntrypoints.test_entrypoint_handles_type_extensions.<locals>.init_function.<locals>.unbox_dummy   s    GG99#wG	%*ZZ%7%7%K%KC%P"1!))QYYG%&WW%<%<Y%G"y)77//1 ::--99!))XN22<3I3I3K<D 3 F Fr   c                    	j                   j                  j                  |       } ||j                  |j                        }|j
                  j                  |j                        }|j
                  j                  t              }|j
                  j                  |      }|j
                  j                  ||f      }|j
                  j                  |       |j
                  j                  |       |S r   )r_   r`   ra   rb   rc   r]   float_from_doubler   serialize_objectr	   unserializecall_function_objargsre   )
rk   rN   rO   rn   ro   rm   serialized_clazz	class_objresrZ   s
            r   	box_dummyzaTestEntrypoints.test_entrypoint_handles_type_extensions.<locals>.init_function.<locals>.box_dummy   s    %*ZZ%7%7%K%KC%P"1!))QYYGGG55l6H6HI	#$77#;#;K#H GG//0@A	gg33I	|Ly)y)
r   )rT   Typerh   typeof_implregisterr	   register_modelmodelsStructModelunboxbox)rP   rq   rz   rY   rG   rZ   s      @@r   init_functionzNTestEntrypoints.test_entrypoint_handles_type_extensions.<locals>.init_function}   s    FEKK,, F __((11+># ?# __++I6LU__33?? L 7L __""9-	F .	F __  +	 ,	r   _test_numba_init_sequencer   z#_test_numba_init_sequence:init_funcr   r   r    c                     | S r   r   )r>   s    r   foozDTestEntrypoints.test_entrypoint_handles_type_extensions.<locals>.foo   s    Hr   
   )rZ   rT   
ModuleTyper.   r%   r&   r   r'   r(   r   r)   r*   r   r	   )r   r   r0   r1   r   ivalrZ   s         @r   'test_entrypoint_handles_type_extensionsz7TestEntrypoints.test_entrypoint_handles_type_extensionsv   s   
 	)	V :;%	.(+CKK%.995"M """0=2BC #  

   #2D	
 ||s{{*KK- +
 
 ||s{{*KK- +s$   AC2  C&%C2 &C/+C2 2:D,c                    t        j                  |t         j                  t         j                  |      }t        j                  t
        |j                        }	 |j                          |j                         \  }}|j                  dk7  r*t        d|j                  d|j                         d      |j                         |j                         f|j                          S # |j                          w xY w)N)stdoutstderrenvr   zprocess failed with code z: stderr follows

)
subprocessPopenPIPE	threadingTimer_TEST_TIMEOUTkillstartcommunicate
returncodeAssertionErrordecodecancel)r   cmdliner   popentimeoutouterrs          r   run_cmdzTestEntrypoints.run_cmd   s      (2(2%(*
 //-<		MMO((*HC1$$%%szz|56 6 ::<-NNGNNs   A;C' 'C9c                 >   t         j                  j                         }t        | j                        |d<   | j
                  }t        |       j                  }d}|d|d|}t        j                  dd|g}| j                  ||      \  }}d}	|	rt        ||       y y )NrA   r   .z-mznumba.runtestsF)osenvironcopyr;   rA   r   typer   r%   
executabler   print)
r   env_copythemodtheclsmethnameinjected_methodr   r   r   _DEBUGs
             r   "test_entrypoint_extension_sequencez2TestEntrypoints.test_entrypoint_extension_sequence   s    ::??$&)$*>*>&?"#d$$<(.A>>4)9?K<<2S#sO r   )r   r   r   __doc__r2   r?   rA   unittestskipIfr   r   getr   r   r   r   r   r   r   r      s^    $.L+.Z "OX__RZZ^^$5t<O"$K.$K.Z&r   r   )r%   r   r   rT   r9   r   r   r   rZ   r   numba.tests.supportr   numba.testing.mainr   _RUNNER_TIMEOUT	importlibr   r'   r   r*   r	   r   r   r   r   <module>r      sM    
     	    ( : 4#%2& 2Gh Gr   