
    
f                     "   d dl Z d dlZd dlmZ d dlZd dlmZ d dlmZmZm	Z	m
Z
 d dlmZ 	 d dlZdZn# e$ r dZY nw xY wdZ ej        e e          Ze G d	 d
e                      Z G d de          Zedk    r ej                     dS dS )    N)dedent)mock)TestCasetemp_directoryoverride_env_configrun_in_subprocess)configTFz*pyyaml needed for configuration file testsc                   L     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
d	 Z xZS )

TestConfigFc                     t          d          | _        d| _        t          t          |                                            d S )N
config_tmpi	  )r   tmppathmaxDiffsuperr   setUp)self	__class__s    7lib/python3.11/site-packages/numba/tests/test_config.pyr   zTestConfig.setUp   s;    %l33j$%%'''''    c                 6    t          j        | j                  S )zT
        Creates a mock launch location.
        Returns the location path.
        )dir)tempfilemkdtempr   )r   s    r   mock_cfg_locationzTestConfig.mock_cfg_location    s    
 DL1111r   c                     t           j                            |t          j                  }t          |d          5 }t          j        ||d           ddd           dS # 1 swxY w Y   dS )z<
        Injects a mock configuration at 'location'
        wtF)default_flow_styleN)ospathjoinr	   _config_fnameopenyamldump)r   locationcfgtmpcfgfs        r   inject_mock_cfgzTestConfig.inject_mock_cfg'   s     h(<==&$ 	81Ic17777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s   A  A$'A$c                     t                      }t          t                    D ].}|                                rt	          t          |          ||<   /|S )z8
        Gets the current numba config settings
        )dictr   r	   isuppergetattr)r   storexs      r   get_settingszTestConfig.get_settings/   sK     V 	. 	.Ayy{{ ."61--ar   c                    t          j                    }|                                 }t          j        |           t	          dd          5  |                                 }ddd           n# 1 swxY w Y   |                     ||           	 t	          dd          5  |                                 }ddd           n# 1 swxY w Y   t          j        |           n# t          j        |           w xY w||fS )z
        Returns a config "original" from a location with no config file
        and then the impact of applying the supplied cfg dictionary as
        a config file at a location in the returned "current".
        _N)r   getcwdr   chdirr   r0   r)   )r   r&   original_cwd
launch_diroriginalcurrents         r   create_config_effectzTestConfig.create_config_effect9   sw    y{{ ++--
 	 !c** 	+ 	+((**H	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	Z---	# %S#.. . .++--. . . . . . . . . . . . . . . H\""""BH\""""  sB   A--A14A1C  C 4C   CC  CC   C6c                    d}t           j        t           j        fD ]}|                      ||          di          \  }}|                     ||k               |                     ||         ||         k               |                     ||         d           |                    |           |                    |           |                     ||           d S )NCOLOR_SCHEMElight_bg)strupperlowerr9   
assertTrueassertEqualpop)r   keycaseorigcurrs        r   test_configzTestConfig.test_configZ   s     Y	* 	) 	)D22DDIIz3JKKJD$OODDL)))OODIc2333T#Y
333HHSMMMHHSMMMT4((((	) 	)r   c                 b    |                      i           \  }}|                     ||           d S N)r9   rA   )r   rE   rF   s      r   test_empty_configzTestConfig.test_empty_configh   s5    ..r22
dt$$$$$r   c                 z   t           j                                        }d|d<   d}d| d}t          t	          |          |          \  }}d}|                    d          }|                     ||           d	}|                     ||           |                     ||                    d                     d S )
Nnot_a_known_styleNUMBA_CAPTURED_ERRORSzthe source compiledz0from numba import njit
@njit
def foo():
	print('z')
foo())envzyEnvironment variable 'NUMBA_CAPTURED_ERRORS' is defined but its associated value 'not_a_known_style' could not be parsed.zutf-8z9Invalid style in NUMBA_CAPTURED_ERRORS: not_a_known_style)r   environcopyr   r   decodeassertIn)	r   new_envsource_compiledcodeouterrexpectederr_msgex_expecteds	            r   !test_illegal_error_style_handlingz,TestConfig.test_illegal_error_style_handlingm   s    *//##+>'(/5)5 5 5$VD\\w???S! **W%%h(((+k7+++oszz'':':;;;;;r   )__name__
__module____qualname___numba_parallel_test_r   r   r)   r0   r9   rG   rJ   r[   __classcell__)r   s   @r   r   r      s         "( ( ( ( (2 2 28 8 8  ! ! !B) ) )% % %
< < < < < < <r   r   c                   $   e Zd Zd Z ej        ddi          d             Z ej        ddi          d             Z ej        ddi          d	             Z ej                    d
             Z	 ej        ddi          d             Z
dS )TestNumbaOptLevelc                    	 ddl m}m}                      |j        |                                |j        j        |           ddlm} d	 	fd}t          j	        
                    |d|          5                       t                    5 }  |d                        d d d            n# 1 swxY w Y                        	t          |j                             d d d            d S # 1 swxY w Y   d S )	Nr   )r	   njit)
CPUCodegenzexpected side effectc                  N                         |           t                    rI   )rA   RuntimeError)argskwargsrX   r   side_effect_messages     r   side_effectz,TestNumbaOptLevel.check.<locals>.side_effect   s(    VX...2333r   _module_pass_manager)rk   c                      dS )N. rn   r   r   <lambda>z)TestNumbaOptLevel.check.<locals>.<lambda>   s    c r   )numbar	   rd   rA   OPT
_raw_valuenumba.core.codegenre   r   patchobjectassertRaisesrg   rR   r=   	exception)
r   rX   	opt_value	raw_valuer	   rd   re   rk   raisesrj   s
   ``       @r   checkzTestNumbaOptLevel.check   s   &&&&&&&& 	Y///.	::: 	2111114	4 	4 	4 	4 	4 	4 	4 Zz+A+6  8 8 	F 	F""<00 %F"\\""$$$% % % % % % % % % % % % % % % MM-s63C/D/DEEE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs6   8C4B4(C44B8	8C4;B8	<+C44C8;C8	NUMBA_OPTmax)envvarsc                 B    ddddd}|                      |dd           d S )NTF   cheaploop_vectorizeslp_vectorizeoptcostr}   r{   r   rX   s     r   test_opt_maxzTestNumbaOptLevel.test_opt_max   s:     '+%*#% % 	

8Q&&&&&r   3c                 B    ddddd}|                      |dd           d S NFr   r   r   r   r   r   s     r   
test_opt_3zTestNumbaOptLevel.test_opt_3   :     ',%*#% % 	

8Q"""""r   0c                 B    ddddd}|                      |dd           d S )NFr   r   r   r   r   s     r   
test_opt_0zTestNumbaOptLevel.test_opt_0   r   r   c                 B    ddddd}|                      |dd           d S r   r   r   s     r   test_opt_defaultz"TestNumbaOptLevel.test_opt_default   s:     ',%*#% % 	

8Q"""""r   invalidc                 B    ddddd}|                      |dd           d S r   r   r   s     r   test_opt_invalidz"TestNumbaOptLevel.test_opt_invalid   r   r   N)r\   r]   r^   r{   r   run_test_in_subprocessr   r   r   r   r   rn   r   r   rb   rb      s       F F F8 %X$k5-ABBB' ' CB' %X$k3-?@@@# # A@# %X$k3-?@@@# # A@# %X$&&# # '&# %X$k9-EFFF# # GF# # #r   rb   __main__)r   r   textwrapr   unittestr   numba.tests.supportr   r   r   r   
numba.corer	   r#   
_HAVE_YAMLImportError	_skip_msgskipIf
needs_yamlr   rb   r\   mainrn   r   r   <module>r      s   				              4 4 4 4 4 4 4 4 4 4 4 4      KKKJJ   JJJ 9	X_^Y77
 h< h< h< h< h< h< h< h<VL# L# L# L# L# L# L# L#^ zHMOOOOO s   3 ==