U
    ui!                     @   s   d Z ddl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m	Z	 ddlmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZ ddlZdd ZejejdG dd dejZ dS )z$Tests for distutils.command.install.    N)	sysconfig)install)	build_ext)INSTALL_SCHEMESr   )Distribution)DistutilsOptionError)	Extension)missing_compiler_executablesupport)is_mingwc                 C   s   | t d S )N
EXT_SUFFIX)r   get_config_var)modname r   L/tmp/pip-unpacked-wheel-9osl9suo/setuptools/_distutils/tests/test_install.py_make_ext_name   s    r   Zsave_envc                   @   sT   e Zd Zejjddddd Zdd Zdd	 Zd
d Z	dd Z
dd Zdd ZdS )TestInstallz=platform.system() == "Windows" and sys.version_info > (3, 11)zpypa/distutils#148)reasonc           
      C   s*  |   }tj|d}tddi}tj|d|_tj|tj|dd|jd< t	|}||_
|  |j|kstt|j|kstdd	 }tjjd
d}tj|d|}||j| ttdd}tj|||}	||j|	 ||j| ||jtj|d|d ||jtj|d ||j| d S )NZinstallationnameZfoopkgzsetup.pylib)
build_base	build_libbuildc                 S   s(   t j| } t j|}| |ks$td S N)ospathnormpathAssertionError)gotexpectedr   r   r   
check_path8   s    z=TestInstall.test_home_installation_scheme.<locals>.check_pathcpythonpython
platlibdirincludebin)mkdtempr   r   joinr   script_namer
   ZDummyCommandcommand_objr   homeensure_finalizedinstall_baser   install_platbasesysimplementationr   replaceinstall_libgetattrinstall_platlibinstall_purelibinstall_headersinstall_scriptsinstall_data)
selfZbuilddirZdestinationdistcmdr    Z	impl_nameZlibdirZ_platlibdirr#   r   r   r   test_home_installation_scheme   s6    z)TestInstall.test_home_installation_schemec                    s      _tj}tj}|tdtj jd |tdtj jd |t	dtj |t	dtj  fdd}|tjd| dD ]}|t
kstqtd	d
i}t|}dd |jD }d|kstd|_tjtjrttjtjrt|  tjtjsttjtjs&td|jks6td|jksFttj|jtj}	tjdkrt stjtj||}
tj|
d}ntdd}tj|d
}tj|	tj|kstd S )N	USER_BASEB	USER_SITESc                    s(   |  dr$tj j| dd   S | S )N~   )
startswithr   r   r   tmpdir)r   r8   r   r   _expanduserV   s    
z/TestInstall.test_user_site.<locals>._expanduser
expanduser)nt_user
posix_userr   xxc                 S   s   g | ]\}}}|qS r   r   ).0r   shortlabelr   r   r   
<listcomp>d   s     z.TestInstall.test_user_site.<locals>.<listcomp>userTuserbaseusersitentIncluder    )r&   rC   siter>   r<   setattrr   r   r'   install_moduler   r   r   r   user_optionsrN   existsr+   config_varsrelpathr5   r   r   dirnamer   get_python_incnormcase)r8   monkeypatchZ	orig_siteZ	orig_baserE   keyr9   r:   optionsZactual_headersZ	site_pathr$   Zexpect_headersr   rD   r   test_user_siteK   s<    
zTestInstall.test_user_sitec              	   C   s   t ddd}t|}|  |jddgks0t|jdks>t|jdksLtdg|_|  |jdgkslt|jdkszt|jdkstd  |_|_|  |jd kst|jdkst|jd kstd|_tt	 |  W 5 Q R X d S )NrI   z	path,dirs)r   
extra_pathr   dirsrS   zpath,dirs,again)
r   r   handle_extra_pathrb   r   
extra_dirs	path_filepytestraisesr   r8   r9   r:   r   r   r   test_handle_extra_path   s&    z"TestInstall.test_handle_extra_pathc              	   C   s   t ddi}t|}d|_d|_tt |  W 5 Q R X d |_d|_tt |  W 5 Q R X d |_d|_	tt |  W 5 Q R X d S )Nr   rI   prefixbaser*   rN   )
r   r   rk   r,   rg   rh   r   finalize_optionsr*   rN   ri   r   r   r   test_finalize_options   s    z!TestInstall.test_finalize_optionsc                 C   s   |   }| jdgdgd\}}t| | dd | dd t|}||jd< ||_tj	|d|_
|  |  t|j
jd	d
}dd | D }ddtjj dddjtjd d  g}||kstd S )NZhelloZsayhi)
py_modulesscriptszhello.pyzdef main(): print('o hai')zfrom hello import main; main()r   filelistutf-8encodingc                 S   s   g | ]}t |jqS r   pathlibPathr   rJ   liner   r   r   rM      s     z+TestInstall.test_record.<locals>.<listcomp>zhello.z.pycUNKNOWN-0.0.0-py{}.{}.egg-info   )r&   create_distr   chdir
write_filer   r)   rootr   r'   recordr+   runrv   rw   	read_text
splitlinesr.   r/   	cache_tagformatversion_infor   )r8   install_dirproject_dirr9   r:   contentfoundr   r   r   r   test_record   s&    

zTestInstall.test_recordc           	      C   s  t  }|d k	r td|d |  }| jtddggd\}}t| t	| t
|}t| |  t|}||jd< ||jd< ||_tj|d|_|  |  t|jjd	d
}dd | D }tddjtjd d  g}||kstd S )NzThe z command is not foundrI   z
xxmodule.c)ext_modulesr   r   rq   rr   rs   c                 S   s   g | ]}t |jqS r   ru   rx   r   r   r   rM      s     z6TestInstall.test_record_extensions.<locals>.<listcomp>rz   r{   )r	   rg   skipr&   r|   r   r   r}   r
   Zcopy_xxmodule_cr   Zfixup_build_extr+   r   r)   r   r   r'   r   r   rv   rw   r   r   r   r   r.   r   r   )	r8   r:   r   r   r9   Zbuildextcmdr   r   r   r   r   r   test_record_extensions   s2    





z"TestInstall.test_record_extensionsc                 C   s>   | tdd |tj |   tdd |jD s:td S )NDEBUGTc                 s   s   | ]}|j tjkr|V  qd S r   )levelnologgingr   )rJ   Zrecr   r   r   	<genexpr>   s      z.TestInstall.test_debug_mode.<locals>.<genexpr>)	rU   rV   Z	set_levelr   r   r   anyrecordsr   )r8   Zcaplogr^   r   r   r   test_debug_mode   s    zTestInstall.test_debug_modeN)__name__
__module____qualname__rg   markZxfailr;   ra   rj   rn   r   r   r   r   r   r   r   r      s   
)7 r   )!__doc__r   r   rv   rT   r.   	distutilsr   distutils.commandr   rV   Zdistutils.command.build_extr   distutils.command.installr   distutils.corer   distutils.errorsr   distutils.extensionr   Zdistutils.testsr	   r
   distutils.utilr   rg   r   Zcombine_markersr   ZusefixturesZTempdirManagerr   r   r   r   r   <module>   s*   

