
    J/Phl                     <   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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Zd dlmZ d dlmZ d dlmZm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$m%Z%m&Z&m'Z' 	 d dl(Z(n# e)$ r dZ(Y nw xY wd	 Z* e*            Z+d
Z, e	j-        e+e,          Z.d Z/d Z0d Z1d Z2d Z3d Z4 G d dee           Z5d Z6 G d de           Z7 G d de7          Z8 G d de8          Z9 G d de8          Z: G d de8          Z;e& G d de8                      Z< G d  d!e8          Z= G d" d#e7          Z>e% G d$ d%e	j                               Z?d& Z@ G d' d(e	j                   ZA G d) d*e7          ZBeCd+k    r e	jD                     dS dS ),    N)Path)njit)codegen)_UserWideCacheLocator_ZipCacheLocator)NumbaWarning)parfor)	SerialMixinTestCasecapture_cache_logimport_dynamicoverride_configrun_in_new_process_cachingskip_if_typeguardskip_parfors_unsupportedtemp_directoryc                  H   t          d          } t          j                            | d          }t          j        |           t          t          j                            |d          d          5 }|                    d           d d d            n# 1 swxY w Y   t          j        |d           	 t          t          j                            |d          d          5 }|                    d           d d d            n# 1 swxY w Y   	 t          j        |d	           t          j	        |           d
S # t          $ r- Y t          j        |d	           t          j	        |           dS w xY w# t          j        |d	           t          j	        |           w xY w)N
test_cachewritable_testwrite_okwtcheck1@  write_forbiddencheck2i  FT)r   ospathjoinmkdiropenwritechmodshutilrmtreePermissionError)tempdirtest_dirfs      X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/tests/test_caching.pycheck_access_is_preventabler*   )   s    \**GWo66HHX	bgll8Z00$	7	7 1	               HXu "',,x):;;TBB 	aGGH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  	5!!!h     
5!!!h 	5!!!hsZ   2BBB5.D< #D9D< D		D< D	D< <
E3E6 2E33E6 6+F!z9Cannot create a directory to which writes are preventablec                  (    d} t          |           | fS )Nabcd)hash)cs    r)   constant_unicode_cacher/   M   s    A77A:    c                      t           }  t          d          |           } |             \  }} |            \  }}||k    sJ ||k    sJ d S NTcache)r/   r   )pyfunccfuncexp_hvexp_strgot_hvgot_strs         r)   check_constant_unicode_cacher;   R   sg    #FDtV$$EfhhOFGeggOFGVgr0   c                      dddS )N      )ab rA   r0   r)   
dict_cacherB   [   s    r0   c                  ~    t           }  t          d          |           } |             } |            }||k    sJ d S r2   )rB   r   r5   r6   expgots       r)   check_dict_cacherG   _   sH    FDtV$$E
&((C
%''C#::::::r0   c               #      K   dD ]} | V  d S )N)r=   r>      rA   )vs    r)   generator_cacherK   g   s*         r0   c                      t           }  t          d          |           }t           |                       }t           |                      }||k    sJ d S r2   )rK   r   listrD   s       r)   check_generator_cacherN   l   sT    FDtV$$E
vvxx..C
uuww--C#::::::r0   c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )TestCachingc                 p     |             t          |          }|                     |d         d           d S )Nexitcoder   )r   assertEqual)selffuncress      r)   run_testzTestCaching.run_testu   s:    (..Z!,,,,,r0   c                 :    |                      t                     d S N)rW   r;   rT   s    r)   test_constant_unicode_cachez'TestCaching.test_constant_unicode_cachez   s    233333r0   c                 :    |                      t                     d S rY   )rW   rG   rZ   s    r)   test_dict_cachezTestCaching.test_dict_cache}   s    &'''''r0   c                 :    |                      t                     d S rY   )rW   rN   rZ   s    r)   test_generator_cachez TestCaching.test_generator_cache   s    +,,,,,r0   c                    t          | j        j                  }t          j                    }|                                }|                    t          ||df          }|                                 |	                                 |
                                \  }}|s|                     |           |                     |dd           |                    t          ||df          }|                                 |	                                 |
                                \  }}|s|                     |           |                     |dd           d S )NFtargetargs  z-Omitted function returned an incorrect outputT)r   	__class____name__multiprocessingget_contextQueueProcessomitted_child_test_wrapperstartr   getfailrS   )rT   	cache_dirctxresult_queueprocsuccessoutputs          r)   test_omittedzTestCaching.test_omitted   sc    #4>#:;;	)++yy{{{{-	51  
 
 	

		&**,,  	IIf;	
 	
 	
 {{-	40  
 
 	

		&**,,  	IIf;	
 	
 	
 	
 	
r0   N)rf   
__module____qualname__rW   r[   r]   r_   ru   rA   r0   r)   rP   rP   t   s_        - - -
4 4 4( ( (- - -(
 (
 (
 (
 (
r0   rP   c                 D   t          d|          5  t          d          dd            }	  |            }|rM|j        |j        d                  dk    s
J d            |j        |j        d                  dk    s
J d	            nL|j        |j        d                  dk    s
J d
            |j        |j        d                  dk    s
J d            d}n#  t          j                    }d}Y nxY w|                     ||f           d d d            d S # 1 swxY w Y   d S )N	CACHE_DIRTr3   rd   c                     | S rY   rA   )nums    r)   testz(omitted_child_test_wrapper.<locals>.test   s    Jr0   r   r=   zCache did not hit as expectedzCache has an unexpected misszCache did not miss as expectedzCache has an unexpected hitF)rd   )r   r   _cache_hits
signatures_cache_misses	traceback
format_excput)rq   ro   second_callr|   rt   rs   s         r)   rk   rk      s   	i	0	0 , ,	D				 	 	 
			TVVF  	2'(:;q@@@3 A@@)$/!*<=BBB2 CBBB )$/!*<=BBB4 CBB'(:;q@@@1 A@@GG	)++FGGG'6*+++1, , , , , , , , , , , , , , , , , ,s)   DB'CDC.,DDDc                   @    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d ZdS )	BaseCacheTestNc                    t          d          | _        t          j                            d| j                   t
          j                            | j        | j        dz             | _        t
          j                            | j        d          | _	        t          j        | j        | j                   t          j        | j        t          j        t          j        z             d | _        d S )Nr   r   z.py__pycache__)r   r&   sysr   insertr   r   modnamemodfilero   r#   copyusecases_filer"   statS_IREADS_IWRITEmaxDiffrZ   s    r)   setUpzBaseCacheTest.setUp   s    %l334<(((w||DL$,2FGGdlMBBD&555
t|dm;<<<r0   c                     t           j                            | j        d            t           j                            | j                   d S rY   )r   modulespopr   r   remover&   rZ   s    r)   tearDownzBaseCacheTest.tearDown   s6    d+++%%%%%r0   c                 F   t           j                            | j        d           }|2|j        g}|D ]'}	 t          j        |           # t          $ r Y $w xY wt          | j                  }| 	                    |j
                            d          | j                   |S )Nco)r   r   r   r   
__cached__r   unlinkFileNotFoundErrorr   rS   __file__rstripr   )rT   oldcachedfnmods        r)   import_modulezBaseCacheTest.import_module   s     koodlD11?n%F  IbMMMM(   DT\**,,T22DLAAA
s   A


AAc                 n    	 d t          j        | j                  D             S # t          $ r g cY S w xY w)Nc                 <    g | ]}|                     d           |S ))z.pycz.pyo)endswith).0r   s     r)   
<listcomp>z0BaseCacheTest.cache_contents.<locals>.<listcomp>   s9     : : :2;;'788:B : : :r0   )r   listdirro   r   rZ   s    r)   cache_contentszBaseCacheTest.cache_contents   sW    	: :DN!;!; : : : :  	 	 	III	s   "% 44c                 x     t           fdt                                                     D                       S )Nc              3      K   | ]H}|t           j                            t           j                            j        |                    fV  Id S rY   )r   r   getmtimer   ro   )r   r   rT   s     r)   	<genexpr>z1BaseCacheTest.get_cache_mtimes.<locals>.<genexpr>   s^       = = ))"',,t~r*J*JKKL = = = = = =r0   )dictsortedr   rZ   s   `r)   get_cache_mtimeszBaseCacheTest.get_cache_mtimes   sO     = = = =$T%8%8%:%:;;= = = = = 	=r0   c                 v    |                                  }|                     t          |          ||           d S rY   )r   rS   len)rT   nr.   s      r)   check_pycachezBaseCacheTest.check_pycache   s7    !!QA&&&&&r0   c                     d S rY   rA   rZ   s    r)   
dummy_testzBaseCacheTest.dummy_test   s    r0   )rf   rv   rw   r   r   r   r   r   r   r   r   r   rA   r0   r)   r   r      s        MG  & & &  "  = = =' ' '    r0   r   c                       e Zd Zej                            e          Zej                            ed          Z	dZ
i ddZddZdS )DispatcherCacheUsecasesTestcache_usecases.pydispatcher_caching_test_fodderenvvarsc          	         dt          | j        | j                  z  }t          j                                        }|                    |           t          j        t          j
        d|gt          j        t          j        |          }|                                \  }}|j        dk    rBt          d|j        d|                                d|                                d	          d S )
Nzif 1:
            import sys

            sys.path.insert(0, %(tempdir)r)
            mod = __import__(%(modname)r)
            mod.self_test()
            r&   r   -c)stdoutstderrenvr   process failed with code z: 
stdout follows
z
stderr follows

)r   r&   r   r   environr   update
subprocessPopenr   
executablePIPEcommunicate
returncodeAssertionErrordecode)rT   r   codesubp_envpopenouterrs          r)   run_in_separate_processz3DispatcherCacheUsecasesTest.run_in_separate_process  s     t|T\BBBC :??$$    #.$!=(2
%-/ / / $$&&Sq   . ###SZZ\\\\3::<<<<A   ! r0   Nc                    |j         }|                     t          |j                                                  ||j                   |B|                     t          |j                                                  ||j                   d S d S rY   )statsrS   sum
cache_hitsvaluescache_misses)rT   rU   hitsmissessts        r)   
check_hitsz&DispatcherCacheUsecasesTest.check_hits   s    ZR]113344dBMJJJS!7!7!9!9::F_. . . . . r0   rY   )rf   rv   rw   r   r   dirnamer   herer   r   r   r   r   rA   r0   r)   r   r     sr        7??8$$DGLL':;;M.G13     4. . . . . .r0   r   c                   z   e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Ze ej        ej        dk    d          d                         Ze ej        ej        dk    d          d                         Zd Z ej        edu pej        d         dk     d          d             ZdS )	TestCachec                     |                      d           |                                 }|                      d           |j        }|                      |dd          d           |                      d           |                      |dd          d           |                      d           |                     |dd           |j        }|                      |dd          d           |                      d           |                      |dd          d           |                      d           |                     |dd           |j        } ||j        d          }|                     t          |          d	            ||j	        d          }|                     t          |          d	           |                      d
           |                     |dd           | 
                                 d S )Nr   r>   rI            @      @   r=   )r>   g     E@	   )r   r   add_usecaseassertPreciseEqualr   add_objmode_usecaserecord_returnaligned_arrtuple
packed_arrr   )rT   r   r(   recs       r)   test_cachingzTestCache.test_caching*  s   1  ""1O!Q+++1#q		3///11a   #!Q+++1#q		3///11a   a##c

I666a""c

I66611a    	$$&&&&&r0   c                    |                      d           |                                 }|                      d           |j        }|                      |dd          d           |                      d           |                      |dt	          j        d                    dt	          j        d          z   dz              |                      d           |                     |dd           d S )Nr   r>   rI   r   r=   )r   r   r   r   nparanger   rT   r   r(   s      r)   test_caching_nrt_prunedz!TestCache.test_caching_nrt_prunedH  s    1  ""1O!Q+++1!RYq\\ 2 2A	!4Dq4HIII11a     r0   c                    |                                  }|                     |                    dd          d           |                     d           |j        }|                      |dd          d           |                     d           |                                  }|j        }|                      |dd          d           |                     d           |j        }|                      |dd          d           |                     d           |                      |dd          d           |                     d           d S )NrI   r>   r            @r   )r   r   innerr   outer_uncachedouterr   s      r)   test_inner_then_outerzTestCache.test_inner_then_outerU  sG     ""		!Q3331!Q+++1  ""!Q+++1I!Q+++1#q		3///1r0   c                 4   |                                  }|                     |                    dd          d           |                     d           |                     |                    dd          d           |                     d           |                                  }|j        }|                      |dd          d           |                     d           |                      |dd          d           |                     d           d S )NrI   r>   r   r   r   r   r   )r   r   r   r   r   r   r   s      r)   test_outer_then_innerzTestCache.test_outer_then_inneri  s	     ""		!Q3331 2 21a 8 8!<<<1  ""I!Q+++1#q		3///1r0   c                     |                                  }|j        }|                      |dd          d           |                     d           d S )Nr>   rI   r   r   )r   add_nocache_usecaser   r   r   s      r)   test_no_cachingzTestCache.test_no_cachingw  sU      ""#!Q+++1r0   c                    |                                  }t          j        d          5 }t          j        dt                     |j        }|                      |d          d           |                     d           d d d            n# 1 swxY w Y   |                     t          |          d           | 
                    dt          |d         j                             d S )	NTrecordalwaysr   r   r   r=   zBCannot cache compiled function "looplifted" as it uses lifted code)r   warningscatch_warningssimplefilterr   
loopliftedr   r   rS   r   assertInstrmessagerT   r   wr(   s       r)   test_loopliftedzTestCache.test_looplifted~  s     ""$D111 	"Q!(L999A##AAaDD!,,,q!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	Q### /03AaDL0A0A	C 	C 	C 	C 	Cs   ABBBc                    |                                  }t          j        d          5 }t          j        dt                     |j        }t          j                             |            |j	                   | 
                    d           d d d            n# 1 swxY w Y   |                     t          |          d           |                     dt          |d         j                             d S )NTr  r  r   r=   zICannot cache compiled function "use_big_array" as it uses dynamic globals)r   r  r	  r
  r   use_big_arrayr   testingassert_equalbiggier   rS   r   r  r  r  r  s       r)   test_big_arrayzTestCache.test_big_array  s!     ""$D111 	"Q!(L999!AJ##AACC444q!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	Q### 347!4E4E	G 	G 	G 	G 	Gs   A$BB!Bc                 $   |                                  }|j        |j        |j        fD ]}t	          j        d          5 }t	          j        dt                     |                      |d          d           | 	                    d           d d d            n# 1 swxY w Y   | 
                    t          |          d           |                     d                    |j                  t          |d         j                             d S )NTr  r  g        r   r=   z#Cannot cache compiled function "{}")r   	use_c_sinuse_c_sin_nest1use_c_sin_nest2r  r	  r
  r   r   r   rS   r   r  formatrf   r  r  )rT   r   r(   r  s       r)   test_ctypeszTestCache.test_ctypes  sE      ""-!4c6IJ 	 	A(555 &%h===''#444""1%%%	& & & & & & & & & & & & & & & SVVQ'''MM5<<QZHHAaDL!!   	 	s    ABB	"B	c                    |                                  }t          j                    5  t          j        dt                     |j        }|                      |d          d           |j        }|                      |d          d           |j        }|                      |d          d           |j	        }|                      |d          d           | 
                    d           d d d            d S # 1 swxY w Y   d S )NerrorrI   r      
      r   )r   r  r	  r
  r   closure1r   closure2closure3closure4r   r   s      r)   test_closurezTestCache.test_closure  sA     ""$&& 	" 	"!'<888A##AAaDD!,,,A##AAaDD!,,,A##AAaDD"---A##AAaDD"---q!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s   CC==DDc                    |                                  }|j        }|                      ||j        d          d           |                      ||j        d          d           |                      ||j        d          d           |                      ||j        d          d           |                     d           d S )Nr=   r!  d   r>         )r   first_class_function_usecaserS   first_class_function_mulfirst_class_function_addr   r   s      r)   test_first_class_functionz#TestCache.test_first_class_function  s      "",37;;Q???37<<cBBB37;;Q???37<<bAAA 	1r0   c                    |                                  }|                    dd           |                    dd           |                    dd           |                    dd           |                    dd           |                    |j        d           |                    |j        d           |                                 }| 	                    |j        dd           |                                  }| 
                    ||           |j        } |dd           | 	                    |dd            |dd           | 	                    |dd           |j        } |dd           | 	                    |dd           |                     |                                 |           |                                  |                     |                                 |           d S )Nr>   rI   r   r   r   r=   )r   r   r   r   r   r   r   r   r   r   assertIsNotrS   r   )rT   r   mtimesmod2r(   s        r)   test_cache_reusezTestCache.test_cache_reuse  s     ""1S!!!1%%%1a   		!Q#.!,,,#/1---&&((A...!!##d###	!Q1a   	#s1a   $	!Q1a    	..00&999$$&&&..00&99999r0   c                    |                                  }|j        }|                      |dd          d           t          | j        d          5 }|                    d           d d d            n# 1 swxY w Y   |                                  }|j        }|                      |dd          d           |j        }|                      |dd          d           d S )Nr>   rI   r   r?   z
Z = 10
   )r   r   r   r    r   r!   r   r   s      r)   test_cache_invalidatezTestCache.test_cache_invalidate  s     ""O!Q+++ $,$$ 	"GGL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"   ""O!Q,,,#!Q,,,,,s   A33A7:A7c                    |                                  }|j        }|                      |dd          d           |                                  }|j        }d|_        |                      |dd          d           |                                 |                      |dd          d           |                                  }|j        }|                      |dd          d           d S )Nr>   rI   r   r!  r6  )r   r   r   Z	recompiler   s      r)   test_recompilezTestCache.test_recompile  s      ""O!Q+++  ""O!Q+++	!Q,,,   ""O!Q,,,,,r0   c                     |                                  }|j        }|                      |d          d           |j        }|                      |d          d           d S )Nr>   r   r   )r   renamed_function1r   renamed_function2r   s      r)   test_same_nameszTestCache.test_same_names  se      ""!!a(((!!a(((((r0   c                    ddl m} |j        }t          ddd          }	 ||_        t	          j        |          }t          j        ||          }|                     |           dt          _
        t          j        ||          }|                     |t                     ||_        t          `
d S # ||_        t          `
w xY w)Nr=   )functionpassztests/dummy_module.pyexecT)dummy_modulerA  __code__compileinspectgetfiler   from_functionassertIsNoner   frozenassertIsInstance)rT   rA  old_codecode_objsourcelocators         r)   test_frozenzTestCache.test_frozen  s    ******$6#:FCC	 (H_X..F ,9(FKKGg&&&CJ ,9(FKKG!!'+@AAA !)H


 !)H
NNNNs   BB1 1Cc                    |                                  }|j        }|                     t          j        |j        j        d           |                      |dd          d           |                     |dd           |                                  }|j        }|                      |dd          d           |                     |dd           | 	                    d           dS )	zy
        With a disabled __pycache__, test there is a working fallback
        (e.g. on the user-wide cache dir)
        T)ignore_errorsr>   rI   r   r   r=   N)
r   r   
addCleanupr#   r$   r   
cache_pathr   r   r   )rT   r   r(   r3  s       r)   _test_pycache_fallbackz TestCache._test_pycache_fallback&  s    
   ""O 	qw'9NNN!Q+++1a    !!##!Q+++1a    	1r0   ntz3cannot easily make a directory read-only on Windowsc                     t          j        | j                  j        }t          j        | j        d           |                     t           j        | j        |           |                                  d S )Nr   )r   r   r&   st_moder"   rT  rV  )rT   	old_permss     r)   test_non_creatable_pycachez$TestCache.test_non_creatable_pycache?  s^    
 GDL))1	
u%%%$,	:::##%%%%%r0   c                 >   t           j                            | j        d          }t          j        |           t          j        |          j        }t          j        |d           |                     t           j        ||           | 	                                 d S )Nr   r   )
r   r   r   r&   r   r   rY  r"   rT  rV  )rT   pycacherZ  s      r)   test_non_writable_pycachez#TestCache.test_non_writable_pycacheJ  s    
 ',,t|];;
GG$$,	
%   '9555##%%%%%r0   c                 t    t           j        ddgg dz  	 t          j        dgz             }n9# t          j        $ r'}                     d|j        z             Y d }~nd }~ww xY w|                                                                }t          j
                             j        d          t          d          5 }|                    d           d d d            n# 1 swxY w Y    fd	} |              |            }                     d
|                                           d S )N-mIPythonz--quietz--quickz--no-bannerz--colors=NoColor	--version%ipython not available: return code %dzipython_cache_usecase.txtr  }  
                import os
                import sys

                from numba import jit

                # IPython 5 does not support multiline input if stdin isn't
                # a tty (https://github.com/ipython/ipython/issues/9752)
                f = jit(cache=True)(lambda: 42)

                res = f()
                # IPython writes on stdout, so use stderr instead
                sys.stderr.write(u"cache hits = %d\n" % f.stats.cache_hits[()])

                # IPython hijacks sys.exit(), bypass it
                sys.stdout.flush()
                sys.stderr.flush()
                os._exit(res)
                c                  :   t          d          5 } t          j        | t          j        t          j        d          }|                                \  }}|j        dk    r                     d|j        ||fz             |cd d d            S # 1 swxY w Y   d S NrbT)stdinr   r   universal_newlines*   z6unexpected return code %d
-- stdout:
%s
-- stderr:
%s
r    r   r   r   r   r   rn   ri  pr   r   base_cmdinputfnrT   s       r)   execute_with_inputz2TestCache.test_ipython.<locals>.execute_with_inputx      gt$$ $XU,6O,6O8<> > > ==??S<2%%II 1 "#sC 89 : : :                     A1BBBcache hits = 1)r   r   r   check_outputCalledProcessErrorskipTestr   stripr   r   r   r   r&   r    r!   r  )rT   verer(   rq  r   ro  rp  s   `     @@r)   test_ipythonzTestCache.test_ipythonW  s   ND)4MMMM	*)(k]*BCCCC, 	* 	* 	*MMAL) * * * * * * * *	* iikk  ""',,t|-HII'3 	1GG    	 	 	 	 	 	 	 	 	 	 	 	 	 	 	*	 	 	 	 	 	 	 	  ""&		44444s'   4 A*A%%A*C**C.1C.Nr   r   zrequires ipykernel >= 6c                 ^    t           j        ddgg dz  	 t          j        dgz             }n9# t          j        $ r'}                     d|j        z             Y d }~nd }~ww xY w|                                                                }ddl	m
} |                                t          d          5 }|                    d	           d d d            n# 1 swxY w Y    fd
} |              |            }                     d|                                           d S )Nr`  ra  rb  rc  rd  r   )compilerr  re  c                  :   t          d          5 } t          j        | t          j        t          j        d          }|                                \  }}|j        dk    r                     d|j        ||fz             |cd d d            S # 1 swxY w Y   d S rg  rl  rm  s       r)   rq  z4TestCache.test_ipykernel.<locals>.execute_with_input  rr  rs  rt  )r   r   r   ru  rv  rw  r   rx  r   	ipykernelr}  get_tmp_directoryr    r!   r  )	rT   ry  rz  r}  r(   rq  r   ro  rp  s	   `      @@r)   test_ipykernelzTestCache.test_ipykernel  s   
 ND)4MMMM	*)(k]*BCCCC, 	* 	* 	*MMAL) * * * * * * * *	* iikk  ""&&&&&&,,..'3 	1GG    	 	 	 	 	 	 	 	 	 	 	 	 	 	 	*	 	 	 	 	 	 	 	  ""&		44444s'   4 A*A%%A*=CC#&C#)rf   rv   rw   r   r   r   r   r  r  r  r  r'  r/  r4  r7  r;  r?  rQ  rV  skip_bad_accessunittestskipIfr   namer[  r^  r{  r  version_infor  rA   r0   r)   r   r   (  s       ' ' '<! ! !  (    C C CG G G  $" " " 	 	 	: : :<- - -- - -$) ) )  .  2 X_RW_JL L& &L L _& X_RW_JL L& &L L _&35 35 35j X_i4'KY-CA-F-J.0 055 550 055 55 55r0   r   c                   *     e Zd Z fdZd Zd Z xZS )TestCacheZipc                 r   t                                                       d}d}d}t          j                            | j        |          }t          j        |d          5 }|                    ||           d d d            n# 1 swxY w Y   t          j        
                    d|           d| _        d S )NzI
from numba import jit

@jit(cache=True)
def add(x, y):
    return x + y
ztest_module.pyztest_archive.zipr  r   test_module)superr   r   r   r   r&   zipfileZipFilewritestrr   r   r   )rT   mod_contentmod_filenamezip_filenamezip_pathzfre   s         r)   r   zTestCacheZip.setUp  s     () 7<<l;;_Xs++ 	3rKKk222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	8$$$$s   "BB	B	c                     t           j                            d           t           j                            dd            d S )Nr   r  )r   r   r   r   rZ   s    r)   r   zTestCacheZip.tearDown  s/    Qt,,,,,r0   c                    dd l }|                    dd          }|                     |d           |                     |j        dd           |                     |j        d           t          j        d= t          j                     dd l }|                    dd          }|                     |d           |                     |j        d           d S )Nr   r>   rI   r   r=   r  )r  addrS   r   r   r   	importlibinvalidate_caches)rT   r  result1result2s       r)   test_zip_cachingzTestCacheZip.test_zip_caching  s     	//!Q''!$$$A... 	+++ K&#%%% //!Q''!$$$ 	+++++r0   )rf   rv   rw   r   r   r  __classcell__re   s   @r)   r  r    sV        % % % % %.- - -, , , , , , ,r0   r  c                       e Zd ZdZd Zd ZdS )TestCacheZipLibzR
    ZipCache tests that don't require the setup/teardown from `TestCacheZip`
    c                    d }d}t          j        ||          }|                     |           |                     |j        t          t          d                               |                     |j        d           d S )Nc                      d S rY   rA   rA   r0   r)   	mock_funcz<TestCacheZipLib.test_zip_locator_creation.<locals>.mock_func      Dr0   z/path/to/archive.zip/module.pyz/path/to/archive.zipz	module.py)r   rI  assertIsNotNonerS   	_zip_pathr  r   _internal_path)rT   r  r  rP  s       r)   test_zip_locator_creationz)TestCacheZipLib.test_zip_locator_creation  s    	 	 	 4"0HEEW%%%*C5K0L0L,M,MNNN/=====r0   c                 d    d }d}t          j        ||          }|                     |           d S )Nc                      d S rY   rA   rA   r0   r)   r  z@TestCacheZipLib.test_zip_locator_non_zip_path.<locals>.mock_func  r  r0   z/path/to/module.py)r   rI  rJ  )rT   r  non_zip_pathrP  s       r)   test_zip_locator_non_zip_pathz-TestCacheZipLib.test_zip_locator_non_zip_path  sD    	 	 	 ,"0LII'"""""r0   N)rf   rv   rw   __doc__r  r  rA   r0   r)   r  r    s<         
> 
> 
># # # # #r0   r  c                   .     e Zd Z fdZ fdZd Z xZS )TestSequentialParForsCachec                 n    t          t          |                                            dt          _        d S )NT)r  r  r   r	   sequential_parfor_loweringrT   re   s    r)   r   z TestSequentialParForsCache.setUp  s.    ($//55777,0)))r0   c                 n    t          t          |                                            dt          _        d S )NF)r  r  r   r	   r  r  s    r)   r   z#TestSequentialParForsCache.tearDown#  s.    ($//88:::,1)))r0   c                 v   |                                  }|                     d           |j        }t          j        d          }|                      ||          ||z  |z              d |j                                        D             }|                     |dg           |                     d           d S )Nr   r!  c                 &    g | ]}|j         j        S rA   )libraryhas_dynamic_globals)r   cress     r)   r   z;TestSequentialParForsCache.test_caching.<locals>.<listcomp>.  s-     = = =#  <; = = =r0   Fr>   )	r   r   parfor_usecaser   onesr   	overloadsr   rS   )rT   r   r(   arydynamic_globalss        r)   r   z'TestSequentialParForsCache.test_caching(  s      ""1gbkk#c	C888= ='({'9'9';';= = =5'2221r0   )rf   rv   rw   r   r   r   r  r  s   @r)   r  r    s`        1 1 1 1 1
2 2 2 2 2
	 	 	 	 	 	 	r0   r  c                   $    e Zd ZdZd Zd Zd ZdS )TestCacheWithCpuSettingFc                     d}|                                                                  D ]*\  }}||v r!|                     |||                    |dz  }+|                     |dd           d S )Nr   r=   znothing to comparemsg)r   itemsassertGreaterEqualassertGreater)rT   
mtimes_oldmatch_countkrJ   s        r)   check_later_mtimesz*TestCacheWithCpuSetting.check_later_mtimes8  s    ))++1133 	! 	!DAqJ'':a=999q ;3 	 	5 	5 	5 	5 	5r0   c                    |                      d           |                                 }|                                 t          |                                           }|                                 }|                     ddi           |                     |           |                     t          |                                           |           |j	        j
        }|j        }|                                }|                     t          |          d           |                                \  }}|d         d         t          j                    k    r||}
}	n||}
}	|                     |	d         d         t          j                               |                     |	d         d         t#          j                               |                     |
d         d         d           |                     |
d         d         d           d S )Nr   NUMBA_CPU_NAMEgenericr   r>   r=    )r   r   	self_testr   r   r   r   r  r  r   _cache_cache_file_load_indexrS   keysllget_host_cpu_namer   get_host_cpu_features)rT   r   
cache_sizer2  r4   
cache_filecache_indexkey_akey_bkey_hostkey_generics              r)   test_user_set_cpu_namez.TestCacheWithCpuSetting.test_user_set_cpu_nameA  s   1  "",,..//
&&(($$.>	-J$KKK'''3t224455zBBB&&
 ,,..[))1---$))++8A;".0000$)5kHH$)5kH!Q)=)?)?@@@!Q)F)H)HIIIQ*I666Q*B/////r0   c                 P   |                      d           |                                 }|                                 t          |                                           }|                                 }d}t          j                    }|                     ||           | 	                    d|i           | 
                    |           |                     t          |                                           |           |j        j        }|j        }|                                }|                     t          |          d           |                                \  }	}
|	d         d         |k    r|	|
}}n|
|	}}|                     |d         d         t%          j                               |                     |d         d         |           |                     |d         d         t%          j                               |                     |d         d         |           d S )Nr   z	-sse;-avxNUMBA_CPU_FEATURESr   r>   r=   )r   r   r  r   r   r   r   r  assertNotEqualr   r  r  r   r  r  r  rS   r  r  r  )rT   r   r  r2  my_cpu_featuressystem_featuresr4   r  r  r  r  r  r  s                r)   test_user_set_cpu_featuresz2TestCacheWithCpuSetting.test_user_set_cpu_features\  s   1  "",,..//
&&((%!799O_===$$)?; 	% 	
 	
 	
 	'''3t224455zBBB&&
 ,,..[))1---$))++8A;/))$)5kHH$)5kH!Q)=)?)?@@@!Q999Q*B,@,B,BCCCQ*O<<<<<r0   N)rf   rv   rw   _numba_parallel_test_r  r  r  rA   r0   r)   r  r  4  sG        !5 5 50 0 06!= != != != !=r0   r  c                       e Zd ZdZej                            e          Zej        	                    ed          Z
dZd ZdS )TestMultiprocessCacheFr   r   c                    |                                  }|j        }d}	 t          j        d          }n# t          $ r
 t          }Y nw xY w|                    |          }	 t          |                    |t          |                              }|	                                 n# |	                                 w xY w| 
                    |||dz
  z  dz             d S )NrI   spawnr=   r>   )r   simple_usecase_callerrg   rh   AttributeErrorPoolr   imaprangecloserS   )rT   r   r(   r   rp   poolrV   s          r)   test_multiprocessingz*TestMultiprocessCache.test_multiprocessing  s      "" %	"!-g66CC 	" 	" 	"!CCC	"xx{{	dii588,,--CJJLLLLDJJLLLLa1q5kQ./////s   4 AA!0B& &B<N)rf   rv   rw   r  r   r   r   r   r   r   r   r   r  rA   r0   r)   r  r    sY         "7??8$$DGLL':;;M.G0 0 0 0 0r0   r  c                       e Zd ZdZej                            e          Zej        	                    ed          Z
dZdZdZd Zd Zd Zd	 Zd
 Z ej         eed          d          d             ZdS )TestCacheFileCollisionFr   caching_file_loc_fodderzD
from numba import njit
@njit(cache=True)
def bar():
    return 123
zD
from numba import njit
@njit(cache=True)
def bar():
    return 321
c                    t          d          | _        t          j                            d| j                   d| _        |                     | j        t          j                   | j        | _        d	                    | j        dg          | _
        t          j        	                    | j        | j                  }t          j        |           t          t          j        	                    |d          d          5 }t          | j        |           d d d            n# 1 swxY w Y   t          t          j        	                    |d	          d          5 }t          | j        |           d d d            d S # 1 swxY w Y   d S )
Ntest_cache_file_locr   module_name_that_is_unlikely.fooz__init__.pyr  filezfoo.py)r   r&   r   r   r   r   assertNotInr   modname_bar1r   modname_bar2r   r   r    printsource_text_1source_text_2)rT   foomodfouts      r)   r   zTestCacheFileCollision.setUp  s   %&;<<4<(((5s{333 LHHdlE%:;;dlDL99
"',,v}55s;; 	1t$$40000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1"',,vx00#66 	1$$$40000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s$   ?D""D&)D&E??FFc                     t           j                            | j        d            t           j                            | j        d            t           j                            | j                   d S rY   )r   r   r   r  r  r   r   r&   rZ   s    r)   r   zTestCacheFileCollision.tearDown  sP    )4000)4000%%%%%r0   c                 4    t          | j                  j        S rY   )r   r  barrZ   s    r)   import_bar1z"TestCacheFileCollision.import_bar1      d/0044r0   c                 4    t          | j                  j        S rY   )r   r  r  rZ   s    r)   import_bar2z"TestCacheFileCollision.import_bar2  r  r0   c                 f   |                                  }|                                 }|j        j        j        }|j        j        j        }|                     ||           |                     |                    d                     |                     |                    d                     d S )Nz__init__.bar-3.pyzfoo.bar-3.py)r  r  r  r  _index_namer  
assertTrue
startswith)rT   bar1bar2idxname1idxname2s        r)   test_file_locationz)TestCacheFileCollision.test_file_location  s    !!!!;*6;*6Hh///++,?@@AAA++N;;<<<<<r0   rh   z)Test requires multiprocessing.get_contextc                    |                                  }|                                 }t                      5 } |            }d d d            n# 1 swxY w Y   |                                }|                     |                    d          d           |                     |                    d          d           |                     |                    d          d           |                     |                    d          d           t                      5 } |            }d d d            n# 1 swxY w Y   |                                }|                     |                    d          d           |                     |                    d          d           |                     |                    d          d           |                     |                    d          d           |                     ||           	 t          j        d          }n# t          $ r t          d           Y nw xY w|                                }|                    t          || j        | j        | j        f	          }	|	                                 |                                }
|                                }|                                }|                                }|	                                 |                     ||           |                     ||           |                     |
                    d          d           |                     |
                    d          d           |                     |
                    d          d           |                     |
                    d          d           |                     |                    d          d           |                     |                    d          d           |                     |                    d          d           |                     |                    d          d           d S )
Nzindex savedr=   z
data savedzindex loadedr   zdata loadedr  zmissing spawn contextra   )r  r  r   getvaluerS   countr  rg   rh   
ValueErrorr  ri   rj   cache_file_collision_testerr&   r  r  rl   rm   r   )rT   r  r  bufres1cachelogres2mpqrr   log1got1log2got2s                 r)   test_no_collisionz(TestCacheFileCollision.test_no_collision  s[    !!!!   	C466D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	<<>>66:::55q99977;;;66:::   	C466D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	<<>>66:::55q99977;;;66:::D$'''	+ !,W55BB 	+ 	+ 	+)*****	+ HHJJzz!< !4< $ 1 $ 1 3  4 4 	

uuwwuuwwuuwwuuww		 	t$$$t$$$ 	M22A666L111555N33Q777M22A666 	M22A666L111555N33Q777M22A66666s5   AAAD66D:=D:H% %I IN)rf   rv   rw   r  r   r   r   r   r   r   r   r   r  r  r   r   r  r  r  r  
skipUnlesshasattrrg   r!  rA   r0   r)   r  r    s        !7??8$$DGLL':;;M'GMM1 1 1& & &
5 5 55 5 5= = = X-@@DF F97 97F F97 97 97r0   r  c                 F   t           j                            d|           t          |          j        }t          |          j        }t                      5 } |            }d d d            n# 1 swxY w Y   |                     |                                           |                     |           t                      5 } |            }d d d            n# 1 swxY w Y   |                     |                                           |                     |           d S )Nr   )r   r   r   r   r  r   r   r  )	r  r&   r  r  r  r  r  r1r2s	            r)   r  r    s`   HOOAw,''+D,''+D			 TVV              EE#,,..EE"III			 TVV              EE#,,..EE"IIIIIs$   A..A25A2CC!Cc                   ,    e Zd ZdZdZdZd Zd Zd ZdS )#TestCacheMultipleFilesWithSignatureFz
from file2 import function2
z
from numba import njit

@njit('float64(float64)', cache=True)
def function1(x):
    return x

@njit('float64(float64)', cache=True)
def function2(x):
    return x
c                    t          d          | _        t          j                            | j        d          | _        t          | j        d          5 }t          | j        |           d d d            n# 1 swxY w Y   t          j                            | j        d          | _	        t          | j	        d          5 }t          | j
        |           d d d            d S # 1 swxY w Y   d S )Nr  zfile1.pyr  r  zfile2.py)r   r&   r   r   r   file1r    r  source_text_file1file2source_text_file2)rT   r  s     r)   r   z)TestCacheMultipleFilesWithSignature.setUp4  sI   %&;<<W\\$,
;;
$*c"" 	5d$(t4444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 W\\$,
;;
$*c"" 	5d$(t4444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s$   A77A;>A;C%%C),C)c                 8    t          j        | j                   d S rY   )r#   r$   r&   rZ   s    r)   r   z,TestCacheMultipleFilesWithSignature.tearDown?  s    dl#####r0   c                 t   t          j        t          j        | j        gt           j        t           j                  }|                                \  }}d|                                 d|                                 }|                     |j	        d|           t          j        t          j        | j
        gt           j        t           j                  }|                                \  }}d|                                 d|                                 }|                     |j	        d|           d S )Nr   r   zstdout:
z


stderr:
r   r  )r   r   r   r   r*  r   r   r   rS   r   r,  )rT   r   r   r   r  s        r)   *test_caching_mutliple_files_with_signaturezNTestCacheMultipleFilesWithSignature.test_caching_mutliple_files_with_signatureB  s    #.$*!=(2(29 9 9 $$&&SC#**,,CCSZZ\\CC)1#666  #.$*!=(2(29 9 9 $$&&SC#**,,CCSZZ\\CC)1c22222r0   N)	rf   rv   rw   r  r+  r-  r   r   r1  rA   r0   r)   r(  r(     sY         "
	5 	5 	5$ $ $3 3 3 3 3r0   r(  c                       e Zd Zej                            e          Zej                            ed          Z	dZ
d Zd Zd ZdS )TestCFuncCachezcfunc_cache_usecases.pycfunc_caching_test_fodderc                 P   dt          | j        | j                  z  }t          j        t
          j        d|gt          j        t          j                  }|                                \  }}|j	        dk    r-t          d|j	         d|                                 d          d S )	Naf  if 1:
            import sys

            sys.path.insert(0, %(tempdir)r)
            mod = __import__(%(modname)r)
            mod.self_test()

            f = mod.add_usecase
            assert f.cache_hits == 1
            f = mod.outer
            assert f.cache_hits == 1
            f = mod.div_usecase
            assert f.cache_hits == 1
            r   r   r0  r   r   z:stderr follows
r   )r   r&   r   r   r   r   r   r   r   r   r   r   )rT   r   r   r   r   s        r)   r   z&TestCFuncCache.run_in_separate_processZ  s     t|T\BBBC  #.$!=(2
Q Q Q$$&&Sq    "EU=M "E "E47JJLL"E "E "E F F F ! r0   c                 .    |                                  d S rY   )r  rT   r   s     r)   check_modulezTestCFuncCache.check_moduler  s    r0   c                 P   |                      d           |                                 }|                      d           |                     |j        j        d           |                     |j        j        d           |                     |j        j        d           |                     |j        j        d           |                     |           |                                 }|                      d           |                     |j        j        d           |                     |j        j        d           |                     |j        j        d           |                     |j        j        d           |                     |           | 	                                 d S )Nr   r   r=   )
r   r   rS   r   r   r   r  div_usecaser8  r   r7  s     r)   r   zTestCFuncCache.test_cachingu  s|   1  ""13Q777-q1110;Q???3Q777#   ""13Q777-q1110;Q???3Q777#$$&&&&&r0   N)rf   rv   rw   r   r   r   r   r   r   r   r   r   r8  r   rA   r0   r)   r3  r3  T  sr        7??8$$DGLL'@AAM)GF F F0  ' ' ' ' 'r0   r3  __main__)Er  rG  rg   r   r#   r   r   r   r   r  r  r  pathlibr   llvmlite.bindingbindingr  numpyr   numbar   
numba.corer   numba.core.cachingr   r   numba.core.errorsr   numba.parforsr	   numba.tests.supportr
   r   r   r   r   r   r   r   r   r  ImportErrorr*   _access_preventable_access_msgr"  r  r/   r;   rB   rG   rK   rN   rP   rk   r   r   r   r  r  r  r  r  r  r  r(  r3  rf   mainrA   r0   r)   <module>rJ     s            				       



                                    F F F F F F F F * * * * * *            
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
   III     > 2133 I%(%&9;GG  
        
  7
 7
 7
 7
 7
+x 7
 7
 7
t, , ,84 4 4 4 4H 4 4 4n$. $. $. $. $.- $. $. $.N[5 [5 [5 [5 [5+ [5 [5 [5|8, 8, 8, 8, 8,. 8, 8, 8,v# # # # #1 # # #6     !<   .I= I= I= I= I=9 I= I= I=X0 0 0 0 0M 0 0 0: q7 q7 q7 q7 q7X. q7 q7 q7h  13 13 13 13 13(*; 13 13 13h6' 6' 6' 6' 6'] 6' 6' 6'r zHMOOOOO s   8A= =BB