o
    Zh                     @   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   sP   dd }| td| tt td W d    d S 1 s!w   Y  d S )Nc                 S   s   dS )N)NN )Z	plat_specr   r   d/var/www/html/lang_env/lib/python3.10/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J d S Nr   )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   Z	plat_namer   compilerr   r   r   r   %test_cross_platform_compilation_paths!   s   z6Testmsvccompiler.test_cross_platform_compilation_pathsc              	   C   s   d}d}t jdd }|t j|< z)td}| |v sJ |||  ks(J W t j| |r8|t jd< d S d S t j| |rG|t jd< w )Nu   ṰḖṤṪ┅ṼẨṜu	   ₃⁴₅ZDISTUTILS_USE_SDKx86)osenvironpopr   r   lower)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s%J tj|s-J d S )NZ_find_vc      r$   zVS z is not installed)getattrr   r   skipr   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                    s0   zt    W d S  ty   t | _Y d S w r   )superrun	Exceptionsysexc_infor   	__class__r   r   r8   [   s
   zCheckThread.runc                 C   s   | j  S r   )r;   r<   r   r   r   __bool__a   s   zCheckThread.__bool__)r.   r/   r0   r;   r8   r?   __classcell__r   r   r=   r   r6   X   s    r6   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 ]}|  q&t|s3J 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)r6   spawn).0ncommandr   r   r   
<listcomp>o   s    z2TestSpawn.test_concurrent_safe.<locals>.<listcomp>d   N)	r   r   _pathsr:   
executablerangestartjoinall)r   Z	inner_cmdthreadsthreadr   rG   r   test_concurrent_safef   s   

zTestSpawn.test_concurrent_safec                 C   sx   ddl m} t }d|_dd }tj|jd| |	dg W d   n1 s+w   Y  t
jd	dks:J 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	J dS )z A spawn without an env argument.PATHr   N)r   r   )r   cmdr   r   r   CCompiler_spawn   s   z@TestSpawn.test_concurrent_safe_fallback.<locals>.CCompiler_spawnrD   zn/aNrU   )	distutilsrT   r   r   rK   mockpatchobjectZ	CCompilerrD   r   r   get)r   rT   r   rW   r   r   r   test_concurrent_safe_fallbackx   s   z'TestSpawn.test_concurrent_safe_fallbackN)r.   r/   r0   rS   r]   r   r   r   r   rA   e   s    rA   )__doc__r   r:   r3   	threadingZunittest.mockrY   rX   r   Zdistutils.errorsr   Zdistutils.testsr   Zdistutils.utilr   r   r1   r2   r5   ZTempdirManagerr   Threadr6   rA   r   r   r   r   <module>   s    F