U
    aÊ¹jÍ  ã                   @   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   úl/var/www/html/bwave/python/venv/lib/python3.8/site-packages/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