U
    ui                     @   s   d 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 ddlmZ ddlZejdZG dd	 d	ejZG d
d dejZG dd dZdS )z"Tests for distutils._msvccompiler.    N)_msvccompiler)DistutilsPlatformError)support)get_platformz$not hasattr(_msvccompiler, "winreg")c                   @   sx   e Zd Zdd Zejje 	d ddej
dddd	e fgd
d Zedd Zeej
dddd Zd	S )Testmsvccompilerc              	   C   s:   dd }| td| tt td W 5 Q R X d S )Nc                 S   s   dS )N)NN )Z	plat_specr   r   Q/tmp/pip-unpacked-wheel-9osl9suo/setuptools/_distutils/tests/test_msvccompiler.py_find_vcvarsall   s    z:Testmsvccompiler.test_no_compiler.<locals>._find_vcvarsallr	   zwont find this version)setattrr   pytestZraisesr   _get_vc_env)selfmonkeypatchr	   r   r   r   test_no_compiler   s    z!Testmsvccompiler.test_no_compilerwinz-Only run test for non-mingw Windows platforms)reasonzplat_name, expected)	win-arm64r   )	win-amd64r   Nc                    s0   t  } fdd}|t d| || dS )zS
        Ensure a specified target platform is passed to _get_vcvars_spec.
        c                    s   | kst d S N)AssertionError)Zhost_platformplatformexpectedr   r   _get_vcvars_spec3   s    zPTestmsvccompiler.test_cross_platform_compilation_paths.<locals>._get_vcvars_specr   N)r   MSVCCompilerr
   Z
initialize)r   r   	plat_namer   compilerr   r   r   r   %test_cross_platform_compilation_paths!   s    z6Testmsvccompiler.test_cross_platform_compilation_pathsc              	   C   st   d}d}t jdd }|t j|< z2td}| |ks<t|||  ksPtW 5 t j| |rn|t jd< X d S )Nu   ṰḖṤṪ┅ṼẨṜu	   ₃⁴₅ZDISTUTILS_USE_SDKx86)osenvironpopr   r   lowerr   )r   Ztest_varZ
test_valueZold_distutils_use_sdkenvr   r   r   test_get_vc_env_unicode9   s    

z(Testmsvccompiler.test_get_vc_env_unicodeveri  i  c                 C   s^   t td| }ddd| }| \}}|s>td| d ||ksJttj|sZtd S )NZ_find_vc      r&   zVS z is not installed)getattrr   r   skipr   r   pathisdir)r   r%   lookupZexpected_versionversionr+   r   r   r   test_get_vcJ   s    
zTestmsvccompiler.test_get_vc)__name__
__module____qualname__r   r   markskipif	sysconfigr   
startswithZparametrizer   needs_winregr$   r/   r   r   r   r   r      s$   
r   c                       s(   e Zd ZdZ fddZdd Z  ZS )CheckThreadNc                    s2   zt    W n tk
r,   t | _Y nX d S r   )superrun	Exceptionsysexc_infor   	__class__r   r   r:   [   s    zCheckThread.runc                 C   s   | j  S r   )r=   r>   r   r   r   __bool__a   s    zCheckThread.__bool__)r0   r1   r2   r=   r:   rA   __classcell__r   r   r?   r   r8   X   s   r8   c                   @   s   e Zd Zdd Zdd ZdS )	TestSpawnc                    sj   t  d_d}tjd|g  fddtdD }|D ]}|  q:|D ]}|  qLt|sft	dS )zK
        Concurrent calls to spawn should have consistent results.
        r   z2import os; assert os.environ["PATH"] == "expected"z-cc                    s   g | ]}t j gd qS ))targetargs)r8   spawn).0ncommandr   r   r   
<listcomp>o   s    z2TestSpawn.test_concurrent_safe.<locals>.<listcomp>d   N)
r   r   _pathsr<   
executablerangestartjoinallr   )r   Z	inner_cmdthreadsthreadr   rI   r   test_concurrent_safef   s    

zTestSpawn.test_concurrent_safec              	   C   sd   ddl m} t }d|_dd }tj|jd| |	dg W 5 Q R X t
jddks`td	S )
zy
        If CCompiler.spawn has been monkey-patched without support
        for an env, it should still execute.
        r   )	ccompilerr   c                 S   s   t jd dkstdS )z A spawn without an env argument.PATHr   N)r   r    r   )r   cmdr   r   r   CCompiler_spawn   s    z@TestSpawn.test_concurrent_safe_fallback.<locals>.CCompiler_spawnrF   zn/arW   N)	distutilsrV   r   r   rM   mockpatchobjectZ	CCompilerrF   r   r    getr   )r   rV   r   rY   r   r   r   test_concurrent_safe_fallbackx   s    z'TestSpawn.test_concurrent_safe_fallbackN)r0   r1   r2   rU   r_   r   r   r   r   rC   e   s   rC   )__doc__r   r<   r5   	threadingZunittest.mockr[   rZ   r   distutils.errorsr   Zdistutils.testsr   distutils.utilr   r   r3   r4   r7   ZTempdirManagerr   Threadr8   rC   r   r   r   r   <module>   s   F