o
    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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oeje ddG dd deZejjeoeje ddG dd deZ ejjeoe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)sh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o:e  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 n t
yD } zdt|v r?t|W  Y d }~S  d }~ww |sKJ ||S )NenvAccessDenied)
setdefaultr   ospathjoinr   r
   appendr   stripRuntimeErrorstr)exeargskwargscmdargouterr r'   M/var/www/vscode/kcb/lib/python3.10/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 sw   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 ]!}|dr*dtj|d  |vr*| dtjt|dq	d S )N.pytest_r   zno test defined for z script)	dirr   listdirr   endswithr   splitextfailr   )selfmethsnamer'   r'   r(   test_coverageI   s   
z TestExampleScripts.test_coveragez
POSIX onlyr   c                 C   sb   t tD ])\}}}|D ]!}|dr-t j||}tjt |tj @ s-| 	|dqqd S )Nr4   z is not executable)
r   walkr   r8   r   r   statS_IXUSRST_MODEr:   )r;   rootdirsfilesfiler   r'   r'   r(   test_executableU   s   
z"TestExampleScripts.test_executablec                 C      |  d d S )Nzdisk_usage.pyr)   r;   r'   r'   r(   test_disk_usage^      z"TestExampleScripts.test_disk_usagec                 C   rH   )Nzfree.pyrI   rJ   r'   r'   r(   	test_freea   rL   zTestExampleScripts.test_freec                 C   rH   )Nz
meminfo.pyrI   rJ   r'   r'   r(   test_meminfod   rL   zTestExampleScripts.test_meminfoc                 C      |  dtt  d S )Nzprocinfo.pyr)   r   r   getpidrJ   r'   r'   r(   test_procinfog   s   z TestExampleScripts.test_procinfozno usersc                 C   rH   )Nzwho.pyrI   rJ   r'   r'   r(   test_whoj      zTestExampleScripts.test_whoc                 C   rH   )Nzps.pyrI   rJ   r'   r'   r(   test_psn   rL   zTestExampleScripts.test_psc                 C   rH   )Nz	pstree.pyrI   rJ   r'   r'   r(   test_pstreeq   rL   zTestExampleScripts.test_pstreec                 C   rH   )Nz
netstat.pyrI   rJ   r'   r'   r(   test_netstatt   rL   zTestExampleScripts.test_netstatc                 C   rH   )Nzifconfig.pyrI   rJ   r'   r'   r(   test_ifconfigw   rL   z TestExampleScripts.test_ifconfignot supportedc                 C   rO   )Nzpmap.pyrP   rJ   r'   r'   r(   	test_pmapz   s   zTestExampleScripts.test_pmapc                 C   s*   dt   jvrtd| d d S )NussrY   zprocsmem.py)r   Processmemory_full_info_fieldspytestskipr)   rJ   r'   r'   r(   test_procsmem~   s   
z TestExampleScripts.test_procsmemc                 C   rH   )Nz
killall.pyr3   rJ   r'   r'   r(   test_killall   rL   zTestExampleScripts.test_killallc                 C   rH   )Nz	nettop.pyrb   rJ   r'   r'   r(   test_nettop   rL   zTestExampleScripts.test_nettopc                 C   rH   )Nztop.pyrb   rJ   r'   r'   r(   test_top   rL   zTestExampleScripts.test_topc                 C   rH   )Nziotop.pyrb   rJ   r'   r'   r(   
test_iotop   rL   zTestExampleScripts.test_iotopc                 C   s,   |  dt  }tt |v sJ d S )Nzpidof.py)r)   r   r\   r=   r   r   rQ   )r;   outputr'   r'   r(   
test_pidof   s   zTestExampleScripts.test_pidofzWINDOWS onlyc                 C   rH   )Nzwinservices.pyrI   rJ   r'   r'   r(   test_winservices   rT   z#TestExampleScripts.test_winservicesc                 C   rH   )Nzcpu_distribution.pyrb   rJ   r'   r'   r(   test_cpu_distribution   rL   z(TestExampleScripts.test_cpu_distributionc                 C       t  s	td| d d S )Nzno temperaturesztemperatures.py)r   sensors_temperaturesr_   r`   r)   rJ   r'   r'   r(   test_temperatures      
z$TestExampleScripts.test_temperaturesc                 C   rk   )Nzno fanszfans.py)r   sensors_fansr_   r`   r)   rJ   r'   r'   r(   	test_fans   rn   zTestExampleScripts.test_fansz
no batteryc                 C   rH   )Nz
battery.pyrI   rJ   r'   r'   r(   test_battery      zTestExampleScripts.test_batteryc                 C   rH   )Nz
sensors.pyrI   rJ   r'   r'   r(   test_sensors   rr   zTestExampleScripts.test_sensorsN)+__name__
__module____qualname__staticmethodr)   r3   r>   r_   markskipifr   rG   rK   rM   rN   rR   r   r   usersrS   rU   rV   rW   rX   r   rZ   ra   rc   rd   re   rf   rh   r   ri   rj   r	   rm   r   rp   r   r   rq   rs   r'   r'   r'   r(   r   ,   sN    







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   s0    t tD ]} | drt jt| V  qd S )Nr4   )r   r7   INTERNAL_SCRIPTS_DIRr8   r   r   )r=   r'   r'   r(   ls   s   
zTestInternalScripts.lsc              	   C   sP   |   D ]!}t|dd}| }W d    n1 sw   Y  t| qd S r*   )r}   r-   r.   r/   r0   )r;   r   r1   datar'   r'   r(   test_syntax_all   s   
z#TestInternalScripts.test_syntax_allz	not on CIr   c              	   C   s0   |   D ]}zt| W q ty   Y qw d S N)r}   r   
SystemExit)r;   r   r'   r'   r(   test_import_all   s   z#TestInternalScripts.test_import_allN)rt   ru   rv   rw   r}   r   r_   rx   ry   r   r   r'   r'   r'   r(   r{      s    
r{   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 sw   Y  | tjks&J d S r   )	r   SETUP_PYr_   raisesr   setupget_versionr   __version__)r;   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 |r"J d|v s(J d|v s.J 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whichr   PIPEcommunicatewait)r;   pr   r   r'   r'   r(   test_python2   s   zTestSetupScript.test_python2N)
rt   ru   rv   r   r_   rx   ry   r   r   r   r'   r'   r'   r(   r      s    r   )"__doc__r/   r   r   r@   r   r_   r   r   r   psutil.testsr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r|   r   rx   ry   existsr   r{   r   r'   r'   r'   r(   <module>   sP    