a
    QýIh-  ã                   @   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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
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
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
mZ ej ed¡Zej ed¡Zejjeo(ej e¡ ddG dd„ deƒƒZejjeoXej e¡ ddG dd„ deƒƒZ ejjeoˆej e¡ ddG dd„ deƒƒZ!dS )zTest various scripts.é    N)ÚPOSIX)ÚWINDOWS)Ú
CI_TESTING)ÚHAS_BATTERY)ÚHAS_MEMORY_MAPS)ÚHAS_SENSORS_BATTERY)ÚHAS_SENSORS_FANS)ÚHAS_SENSORS_TEMPERATURES)Ú
PYTHON_EXE)ÚPYTHON_EXE_ENV)ÚROOT_DIR)ÚSCRIPTS_DIR)ÚPsutilTestCase)Úimport_module_by_path)Úpsutil)ÚshZinternalzsetup.pyzcan't find scripts/ directory©Úreasonc                   @   s   e Zd Zedd„ ƒZedd„ ƒZdd„ Zejj	e
 ddd	d
„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zejj	eote ¡  dddd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zejj	e dddd „ ƒZd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zejj	e  d-dd.d/„ ƒZ!d0d1„ Z"ejj	e# ddd2d3„ ƒZ$ejj	e% ddd4d5„ ƒZ&ejj	e' ddejj	e( d6dd7d8„ ƒƒZ)ejj	e' ddejj	e( d6dd9d:„ ƒƒZ*d;S )<ÚTestExampleScriptsc              
   O   s¦   |  dt¡ tj t| ¡} t| g}|D ]}| |¡ q&zt|fi |¤Ž 	¡ }W nF t
y” } z.dt|ƒv r~t|ƒW  Y d }~S ‚ W Y d }~n
d }~0 0 |s¢J |ƒ‚|S )NÚenvZAccessDenied)Ú
setdefaultr   ÚosÚpathÚjoinr   r
   Úappendr   ÚstripÚRuntimeErrorÚstr)ÚexeÚargsÚkwargsÚcmdÚargÚoutÚerr© r%   úS/var/www/html/venv_bot_3.9/lib/python3.9/site-packages/psutil/tests/test_scripts.pyÚassert_stdout1   s    z TestExampleScripts.assert_stdoutc                 C   sP   t j t| ¡} t| dd}| ¡ }W d   ƒ n1 s80    Y  t |¡ d S ©NÚutf8)Úencoding)r   r   r   r   ÚopenÚreadÚastÚparse)r   ÚfÚsrcr%   r%   r&   Úassert_syntaxB   s    &z TestExampleScripts.assert_syntaxc                 C   sZ   t | ƒ}t t¡D ]B}| d¡rdtj |¡d  |vr|  dtj t|¡›d¡‚qd S )Nú.pyZtest_r   zno test defined for z script)	Údirr   Úlistdirr   Úendswithr   ÚsplitextÚfailr   )ÚselfZmethsÚnamer%   r%   r&   Útest_coverageI   s    
ÿÿz TestExampleScripts.test_coveragez
POSIX onlyr   c                 C   sb   t  t¡D ]R\}}}|D ]B}| d¡rt j ||¡}tjt  |¡tj @ s|  	|›d¡‚qq
d S )Nr2   z is not executable)
r   Úwalkr   r5   r   r   ÚstatÚS_IXUSRÚST_MODEr7   )r8   ÚrootÚdirsÚfilesÚfiler   r%   r%   r&   Útest_executableU   s    
z"TestExampleScripts.test_executablec                 C   s   |   d¡ d S )Nzdisk_usage.py©r'   ©r8   r%   r%   r&   Útest_disk_usage^   s    z"TestExampleScripts.test_disk_usagec                 C   s   |   d¡ d S )Nzfree.pyrD   rE   r%   r%   r&   Ú	test_freea   s    zTestExampleScripts.test_freec                 C   s   |   d¡ d S )Nz
meminfo.pyrD   rE   r%   r%   r&   Útest_meminfod   s    zTestExampleScripts.test_meminfoc                 C   s   |   dtt ¡ ƒ¡ d S )Nzprocinfo.py©r'   r   r   ÚgetpidrE   r%   r%   r&   Útest_procinfog   s    z TestExampleScripts.test_procinfozno usersc                 C   s   |   d¡ d S )Nzwho.pyrD   rE   r%   r%   r&   Útest_whoj   s    zTestExampleScripts.test_whoc                 C   s   |   d¡ d S )Nzps.pyrD   rE   r%   r%   r&   Útest_psn   s    zTestExampleScripts.test_psc                 C   s   |   d¡ d S )Nz	pstree.pyrD   rE   r%   r%   r&   Útest_pstreeq   s    zTestExampleScripts.test_pstreec                 C   s   |   d¡ d S )Nz
netstat.pyrD   rE   r%   r%   r&   Útest_netstatt   s    zTestExampleScripts.test_netstatc                 C   s   |   d¡ d S )Nzifconfig.pyrD   rE   r%   r%   r&   Útest_ifconfigw   s    z TestExampleScripts.test_ifconfigúnot supportedc                 C   s   |   dtt ¡ ƒ¡ d S )Nzpmap.pyrI   rE   r%   r%   r&   Ú	test_pmapz   s    zTestExampleScripts.test_pmapc                 C   s*   dt  ¡  ¡ jvrt d¡‚|  d¡ d S )NZussrQ   zprocsmem.py)r   ÚProcessZmemory_full_infoÚ_fieldsÚpytestÚskipr'   rE   r%   r%   r&   Útest_procsmem~   s    
z TestExampleScripts.test_procsmemc                 C   s   |   d¡ d S )Nz
killall.py©r1   rE   r%   r%   r&   Útest_killallƒ   s    zTestExampleScripts.test_killallc                 C   s   |   d¡ d S )Nz	nettop.pyrX   rE   r%   r%   r&   Útest_nettop†   s    zTestExampleScripts.test_nettopc                 C   s   |   d¡ d S )Nztop.pyrX   rE   r%   r%   r&   Útest_top‰   s    zTestExampleScripts.test_topc                 C   s   |   d¡ d S )Nziotop.pyrX   rE   r%   r%   r&   Ú
test_iotopŒ   s    zTestExampleScripts.test_iotopc                 C   s,   |   dt ¡  ¡ ¡}tt ¡ ƒ|v s(J ‚d S )Nzpidof.py)r'   r   rS   r9   r   r   rJ   )r8   Úoutputr%   r%   r&   Ú
test_pidof   s    zTestExampleScripts.test_pidofzWINDOWS onlyc                 C   s   |   d¡ d S )Nzwinservices.pyrD   rE   r%   r%   r&   Útest_winservices“   s    z#TestExampleScripts.test_winservicesc                 C   s   |   d¡ d S )Nzcpu_distribution.pyrX   rE   r%   r%   r&   Útest_cpu_distribution—   s    z(TestExampleScripts.test_cpu_distributionc                 C   s    t  ¡ st d¡‚|  d¡ d S )Nzno temperaturesztemperatures.py)r   Zsensors_temperaturesrU   rV   r'   rE   r%   r%   r&   Útest_temperaturesš   s    
z$TestExampleScripts.test_temperaturesc                 C   s    t  ¡ st d¡‚|  d¡ d S )Nzno fanszfans.py)r   Zsensors_fansrU   rV   r'   rE   r%   r%   r&   Ú	test_fans    s    
zTestExampleScripts.test_fansz
no batteryc                 C   s   |   d¡ d S )Nz
battery.pyrD   rE   r%   r%   r&   Útest_battery¦   s    zTestExampleScripts.test_batteryc                 C   s   |   d¡ d S )Nz
sensors.pyrD   rE   r%   r%   r&   Útest_sensors«   s    zTestExampleScripts.test_sensorsN)+Ú__name__Ú
__module__Ú__qualname__Ústaticmethodr'   r1   r:   rU   ÚmarkÚskipifr   rC   rF   rG   rH   rK   r   r   ZusersrL   rM   rN   rO   rP   r   rR   rW   rY   rZ   r[   r\   r^   r   r_   r`   r	   ra   r   rb   r   r   rc   rd   r%   r%   r%   r&   r   ,   sL   







r   z&can't find scripts/internal/ directoryc                   @   s8   e Zd Zedd„ ƒZdd„ Zejje	dddd„ ƒZ
d	S )
ÚTestInternalScriptsc                  c   s.   t  t¡D ]} |  d¡r
t j t| ¡V  q
d S )Nr2   )r   r4   ÚINTERNAL_SCRIPTS_DIRr5   r   r   )r9   r%   r%   r&   Úls»   s    
zTestInternalScripts.lsc              	   C   sP   |   ¡ D ]B}t|dd}| ¡ }W d   ƒ n1 s60    Y  t |¡ qd S r(   )rm   r+   r,   r-   r.   )r8   r   r/   Údatar%   r%   r&   Útest_syntax_allÁ   s    &z#TestInternalScripts.test_syntax_allz	not on CIr   c              	   C   s2   |   ¡ D ]$}zt|ƒ W q ty*   Y q0 qd S ©N)rm   r   Ú
SystemExit)r8   r   r%   r%   r&   Útest_import_allÇ   s
    z#TestInternalScripts.test_import_allN)re   rf   rg   rh   rm   ro   rU   ri   rj   r   rr   r%   r%   r%   r&   rk   ¶   s
   
rk   zcan't find setup.pyc                   @   s4   e Zd Zdd„ Zejje d¡ dddd„ ƒZ	dS )	ÚTestSetupScriptc                 C   sP   t tƒ}t t¡ | ¡  W d   ƒ n1 s00    Y  | ¡ tjksLJ ‚d S rp   )	r   ÚSETUP_PYrU   Zraisesrq   ÚsetupÚget_versionr   Ú__version__)r8   Úmoduler%   r%   r&   Útest_invocationÙ   s    &zTestSetupScript.test_invocationú	python2.7zpython2.7 not installedr   c                 C   s`   t jt d¡tgt jt jdd}| ¡ \}}| ¡ dks<J ‚|rDJ ‚d|v sPJ ‚d|v s\J ‚d S )Nrz   T)ÚstdoutÚstderrÚuniversal_newlinesé   z$psutil no longer supports Python 2.7z'Latest version supporting Python 2.7 is)Ú
subprocessÚPopenÚshutilÚwhichrt   ÚPIPEÚcommunicateÚwait)r8   Úpr{   r|   r%   r%   r&   Útest_python2ß   s    üzTestSetupScript.test_python2N)
re   rf   rg   ry   rU   ri   rj   r   r‚   r‡   r%   r%   r%   r&   rs   Õ   s
   ÿrs   )"Ú__doc__r-   r   r   r<   r   rU   r   r   r   Zpsutil.testsr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   rl   rt   ri   rj   Úexistsr   rk   rs   r%   r%   r%   r&   Ú<module>   sN   þ þÿ