o
    8ήc                     @   s   d dl Z d dlZd dlmZ d dlZd dlmZmZmZm	Z	 d dl
mZ zd dlZdZW n ey7   dZY nw dZee eZeG dd	 d	eZed
krUe  dS dS )    N)dedent)TestCasetemp_directoryoverride_env_configrun_in_subprocess)configTFz*pyyaml needed for configuration file testsc                       sX   e Zd 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
dd Z  ZS )
TestConfigFc                    s"   t d| _d| _tt|   d S )N
config_tmpi	  )r   tmppathmaxDiffsuperr   setUpself	__class__ >/tmp/pip-target-vg8gfxp4/lib/python/numba/tests/test_config.pyr      s   
zTestConfig.setUpc                 C   s   t j| jdS )zT
        Creates a mock launch location.
        Returns the location path.
        )dir)tempfilemkdtempr
   r   r   r   r   mock_cfg_location   s   zTestConfig.mock_cfg_locationc                 C   sP   t j|tj}t|d}tj||dd W d   dS 1 s!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fr   r   r   inject_mock_cfg&   s   "zTestConfig.inject_mock_cfgc                 C   s.   t  }ttD ]}| rtt|||< q|S )z8
        Gets the current numba config settings
        )dictr   r   isuppergetattr)r   storexr   r   r   get_settings.   s   zTestConfig.get_settingsc              	   C   s   t  }|  }t | tdd |  }W d   n1 s!w   Y  | || z-tdd |  }W d   n1 sAw   Y  W t | ||fS W t | ||fS t | w )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   r+   r%   )r   r"   original_cwd
launch_diroriginalcurrentr   r   r   create_config_effect8   s"   




zTestConfig.create_config_effectc                 C   s   d}t jt jfD ]7}| ||di\}}| ||k | || || k | || d || || | || qd S )NCOLOR_SCHEMElight_bg)strupperlowerr3   
assertTrueassertEqualpop)r   keycaseorigcurrr   r   r   test_configY   s   

zTestConfig.test_configc                 C   s   |  i \}}| || d S )N)r3   r:   )r   r>   r?   r   r   r   test_empty_configg   s   zTestConfig.test_empty_configc                 C   sb   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())envzMenviron NUMBA_CAPTURED_ERRORS defined but failed to parse 'not_a_known_style'zutf-8)r   environcopyr   r   assertIndecode)r   new_envsource_compiledcodeouterrexpectedr   r   r   !test_illegal_error_style_handlingl   s   
z,TestConfig.test_illegal_error_style_handling)__name__
__module____qualname___numba_parallel_test_r   r   r%   r+   r3   r@   rA   rO   __classcell__r   r   r   r   r      s    
!r   __main__)r   r   textwrapr   unittestnumba.tests.supportr   r   r   r   
numba.corer   r   
_HAVE_YAMLImportError	_skip_msgskipIf
needs_yamlr   rP   mainr   r   r   r   <module>   s&    f