o
    LK&h!                     @   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   [/var/www/html/venv/lib/python3.10/site-packages/setuptools/_distutils/tests/test_install.py_make_ext_name   s   r   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s:J |j|ksAJ 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 )Ninstallationnamefoopkgzsetup.pylib)
build_base	build_libbuildc                 S   s(   t j| } t j|}| |ksJ d S N)ospathnormpath)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
   DummyCommandcommand_objr   homeensure_finalizedinstall_baseinstall_platbasesysimplementationr   replaceinstall_libgetattrinstall_platlibinstall_purelibinstall_headersinstall_scriptsinstall_data)
selfbuilddirdestinationdistcmdr"   	impl_namelibdir_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
v sMJ qEtd	d
i}t|}dd |jD }d|v sfJ d|_tjtjrrJ tjtjr{J |  tjtjsJ tjtjsJ d|jv sJ d|jv sJ 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sJ 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   r;   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(   rK   siterF   rD   setattrr   r   r)   install_moduler   r   r   user_optionsrV   existsr.   config_varsrelpathr8   r   r   dirnamer   get_python_incnormcase)r;   monkeypatch	orig_site	orig_baserM   keyr>   r?   optionsactual_headers	site_pathr&   expect_headersr   rL   r   test_user_siteK   s<   
 zTestInstall.test_user_sitec                 C   s  t ddd}t|}|  |jddgksJ |jdksJ |jdks&J dg|_|  |jdgks6J |jdks=J |jdksDJ d  |_|_|  |jd u sUJ |jdks\J |jd u scJ d|_tt |  W d    d S 1 s{w   Y  d S )NrQ   z	path,dirs)r   
extra_pathr   dirsr[   zpath,dirs,again)	r   r   handle_extra_pathro   
extra_dirs	path_filepytestraisesr   r;   r>   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 d    n1 s$w   Y  d |_d|_tt |  W d    n1 sCw   Y  d |_d|_	tt |  W d    d S 1 scw   Y  d S )Nr   rQ   prefixbaser-   rV   )
r   r   rx   r/   rt   ru   r   finalize_optionsr-   rV   rv   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siJ d S )Nhellosayhi)
py_modulesscriptszhello.pyzdef main(): print('o hai')zfrom hello import main; main()r   filelistutf-8encodingc                 S      g | ]}t |jqS r   pathlibPathr   rR   liner   r   r   rU          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.   runr   r   	read_text
splitlinesr1   r2   	cache_tagformatversion_info)r;   install_dirproject_dirr>   r?   contentfoundr!   r   r   r   test_record   s&   

zTestInstall.test_recordc           	      C   s  t  }|d u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sJ d S )NzThe z command is not foundrQ   z
xxmodule.c)ext_modulesr   r   r   r   r   c                 S   r   r   r   r   r   r   r   rU      r   z6TestInstall.test_record_extensions.<locals>.<listcomp>r   r   )r	   rt   skipr(   r   r   r   r   r
   copy_xxmodule_cr   fixup_build_extr.   r   r,   r   r   r)   r   r   r   r   r   r   r   r   r1   r   )	r;   r?   r   r   r>   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J d S )NDEBUGTc                 s   s     | ]}|j tjkr|V  qd S r   )levelnologgingr   )rR   recr   r   r   	<genexpr>   s    z.TestInstall.test_debug_mode.<locals>.<genexpr>)r]   r^   	set_levelr   r   r   anyrecords)r;   caplogrf   r   r   r   test_debug_mode   s   zTestInstall.test_debug_modeN)__name__
__module____qualname__rt   markxfailrC   rn   rw   r{   r   r   r   r   r   r   r   r      s    
)7 r   )!__doc__r   r   r   r\   r1   	distutilsr   distutils.commandr   r^   distutils.command.build_extr   distutils.command.installr   distutils.corer   distutils.errorsr   distutils.extensionr   distutils.testsr	   r
   distutils.utilr   rt   r   combine_markersr   usefixturesTempdirManagerr   r   r   r   r   <module>   s,    

