a
    –§»a   ã                   @   sš   d dl Z d dlZd dlZd dlmZmZmZ d dlmZ zd dl	Z	dZ
W n ey^   dZ
Y n0 dZe e
 e¡ZeG dd„ deƒƒZed	kr–e ¡  dS )
é    N)ÚTestCaseÚtemp_directoryÚoverride_env_config)ÚconfigTFz*pyyaml needed for configuration file testsc                       sP   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
‡  ZS )Ú
TestConfigFc                    s"   t dƒ| _d| _tt| ƒ ¡  d S )NZ
config_tmpiÄ	  )r   ÚtmppathZmaxDiffÚsuperr   ÚsetUp©Úself©Ú	__class__© úQ/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/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   sN   t j |tj¡}t|dƒ� }tj||dd� W d  ƒ n1 s@0    Y  dS )z<
        Injects a mock configuration at 'location'
        ÚwtF)Zdefault_flow_styleN)ÚosÚpathÚjoinr   Z_config_fnameÚopenÚyamlÚdump)r   ÚlocationÚcfgZ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 sB0    Y  |  ||¡ z@tddƒ� |  ¡ }W d  ƒ n1 s‚0    Y  W t  |¡ nt  |¡ 0 ||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   r$   r   )r   r   Zoriginal_cwdZ
launch_dirÚoriginalÚcurrentr   r   r   Úcreate_config_effect6   s    
&(zTestConfig.create_config_effectc                 C   s„   d}t jt jfD ]n}|  ||ƒdi¡\}}|  ||k¡ |  || || k¡ |  || d¡ | |¡ | |¡ |  ||¡ qd S )NZCOLOR_SCHEMEZlight_bg)ÚstrÚupperÚlowerr*   Ú
assertTrueÚassertEqualÚpop)r   ÚkeyZcaseÚorigÚcurrr   r   r   Útest_configW   s    

zTestConfig.test_configc                 C   s   |   i ¡\}}|  ||¡ d S )N)r*   r/   )r   r2   r3   r   r   r   Útest_empty_confige   s    zTestConfig.test_empty_config)Ú__name__Ú
__module__Ú__qualname__Z_numba_parallel_test_r	   r   r   r$   r*   r4   r5   Ú__classcell__r   r   r   r   r      s   
!r   Ú__main__)r   r   ZunittestZnumba.tests.supportr   r   r   Z
numba.corer   r   Z
_HAVE_YAMLÚImportErrorZ	_skip_msgZskipIfZ
needs_yamlr   r6   Úmainr   r   r   r   Ú<module>   s   
Y