U
    ç;ãg-  ã                   @   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|Ž 	¡ }W n@ t
k
rŠ } z"dt|ƒkrxt|ƒ W Y ¢S ‚ W 5 d }~X Y nX |s˜t|ƒ‚|S )NÚenvZAccessDenied)Ú
setdefaultr   ÚosÚpathÚjoinr   r
   Úappendr   ÚstripÚRuntimeErrorÚstrÚAssertionError)ÚexeÚargsÚkwargsÚcmdÚargÚoutÚerr© r&   úY/opt/bot/vods_filmes/script/venv/lib/python3.8/site-packages/psutil/tests/test_scripts.pyÚassert_stdout1   s    z TestExampleScripts.assert_stdoutc              	   C   s<   t j t| ¡} t| dd}| ¡ }W 5 Q R X 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  |k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 )Nr3   z is not executable)
r   Úwalkr   r6   r   r   ÚstatÚS_IXUSRÚST_MODEr8   )r9   ÚrootÚdirsÚfilesÚfiler   r&   r&   r'   Útest_executableU   s    
z"TestExampleScripts.test_executablec                 C   s   |   d¡ d S )Nzdisk_usage.py©r(   ©r9   r&   r&   r'   Útest_disk_usage^   s    z"TestExampleScripts.test_disk_usagec                 C   s   |   d¡ d S )Nzfree.pyrE   rF   r&   r&   r'   Ú	test_freea   s    zTestExampleScripts.test_freec                 C   s   |   d¡ d S )Nz
meminfo.pyrE   rF   r&   r&   r'   Útest_meminfod   s    zTestExampleScripts.test_meminfoc                 C   s   |   dtt ¡ ƒ¡ d S )Nzprocinfo.py©r(   r   r   ÚgetpidrF   r&   r&   r'   Útest_procinfog   s    z TestExampleScripts.test_procinfozno usersc                 C   s   |   d¡ d S )Nzwho.pyrE   rF   r&   r&   r'   Útest_whoj   s    zTestExampleScripts.test_whoc                 C   s   |   d¡ d S )Nzps.pyrE   rF   r&   r&   r'   Útest_psn   s    zTestExampleScripts.test_psc                 C   s   |   d¡ d S )Nz	pstree.pyrE   rF   r&   r&   r'   Útest_pstreeq   s    zTestExampleScripts.test_pstreec                 C   s   |   d¡ d S )Nz
netstat.pyrE   rF   r&   r&   r'   Útest_netstatt   s    zTestExampleScripts.test_netstatc                 C   s   |   d¡ d S )Nzifconfig.pyrE   rF   r&   r&   r'   Útest_ifconfigw   s    z TestExampleScripts.test_ifconfigúnot supportedc                 C   s   |   dtt ¡ ƒ¡ d S )Nzpmap.pyrJ   rF   r&   r&   r'   Ú	test_pmapz   s    zTestExampleScripts.test_pmapc                 C   s*   dt  ¡  ¡ jkrt d¡‚|  d¡ d S )NZussrR   zprocsmem.py)r   ÚProcessZmemory_full_infoÚ_fieldsÚpytestÚskipr(   rF   r&   r&   r'   Útest_procsmem~   s    
z TestExampleScripts.test_procsmemc                 C   s   |   d¡ d S )Nz
killall.py©r2   rF   r&   r&   r'   Útest_killallƒ   s    zTestExampleScripts.test_killallc                 C   s   |   d¡ d S )Nz	nettop.pyrY   rF   r&   r&   r'   Útest_nettop†   s    zTestExampleScripts.test_nettopc                 C   s   |   d¡ d S )Nztop.pyrY   rF   r&   r&   r'   Útest_top‰   s    zTestExampleScripts.test_topc                 C   s   |   d¡ d S )Nziotop.pyrY   rF   r&   r&   r'   Ú
test_iotopŒ   s    zTestExampleScripts.test_iotopc                 C   s,   |   dt ¡  ¡ ¡}tt ¡ ƒ|ks(t‚d S )Nzpidof.py)r(   r   rT   r:   r   r   rK   r   )r9   Úoutputr&   r&   r'   Ú
test_pidof   s    zTestExampleScripts.test_pidofzWINDOWS onlyc                 C   s   |   d¡ d S )Nzwinservices.pyrE   rF   r&   r&   r'   Útest_winservices“   s    z#TestExampleScripts.test_winservicesc                 C   s   |   d¡ d S )Nzcpu_distribution.pyrY   rF   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_temperaturesrV   rW   r(   rF   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_fansrV   rW   r(   rF   r&   r&   r'   Ú	test_fans    s    
zTestExampleScripts.test_fansz
no batteryc                 C   s   |   d¡ d S )Nz
battery.pyrE   rF   r&   r&   r'   Útest_battery¦   s    zTestExampleScripts.test_batteryc                 C   s   |   d¡ d S )Nz
sensors.pyrE   rF   r&   r&   r'   Útest_sensors«   s    zTestExampleScripts.test_sensorsN)+Ú__name__Ú
__module__Ú__qualname__Ústaticmethodr(   r2   r;   rV   ÚmarkÚskipifr   rD   rG   rH   rI   rL   r   r   ZusersrM   rN   rO   rP   rQ   r   rS   rX   rZ   r[   r\   r]   r_   r   r`   ra   r	   rb   r   rc   r   r   rd   re   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 )Nr3   )r   r5   ÚINTERNAL_SCRIPTS_DIRr6   r   r   )r:   r&   r&   r'   Úls»   s    
zTestInternalScripts.lsc              
   C   s<   |   ¡ D ].}t|dd}| ¡ }W 5 Q R X t |¡ qd S r)   )rn   r,   r-   r.   r/   )r9   r   r0   Údatar&   r&   r'   Útest_syntax_allÁ   s    z#TestInternalScripts.test_syntax_allz	not on CIr   c              	   C   s4   |   ¡ D ]&}zt|ƒ W q tk
r,   Y qX qd S ©N)rn   r   Ú
SystemExit)r9   r   r&   r&   r'   Útest_import_allÇ   s
    z#TestInternalScripts.test_import_allN)rf   rg   rh   ri   rn   rp   rV   rj   rk   r   rs   r&   r&   r&   r'   rl   ¶   s
   
rl   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   s<   t tƒ}t t¡ | ¡  W 5 Q R X | ¡ tjks8t	‚d S rq   )
r   ÚSETUP_PYrV   Zraisesrr   ÚsetupÚget_versionr   Ú__version__r   )r9   Ú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<t‚|rDt‚d|ksPt‚d|ks\t‚d S )Nr{   T)ÚstdoutÚstderrÚuniversal_newlinesé   z$psutil no longer supports Python 2.7z'Latest version supporting Python 2.7 is)	Ú
subprocessÚPopenÚshutilÚwhichru   ÚPIPEÚcommunicateÚwaitr   )r9   Úpr|   r}   r&   r&   r'   Útest_python2ß   s    üzTestSetupScript.test_python2N)
rf   rg   rh   rz   rV   rj   rk   r‚   rƒ   rˆ   r&   r&   r&   r'   rt   Õ   s   
 ÿrt   )"Ú__doc__r.   r   r‚   r=   r€   rV   r   r   r   Zpsutil.testsr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   rm   ru   rj   rk   Úexistsr   rl   rt   r&   r&   r&   r'   Ú<module>   sP   þ þ ÿ