Your IP : 18.116.86.134


Current Path : /usr/lib64/python3.6/site-packages/psutil/tests/__pycache__/
Upload File :
Current File : //usr/lib64/python3.6/site-packages/psutil/tests/__pycache__/test_unicode.cpython-36.pyc

3

��JZ[2�@s�dZddlZddlZddlZddlmZddlmZddlmZddlm	Z	ddlm
Z
ddlmZdd	lm
Z
dd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%dd lm&Z&ddlZddlZd!d"�Zd#d$�Z'e
�r�e"j(d%�d&j)d%d'�Z*ne"d(Z*Gd)d*�d*e+�Z,e%j-e	�o�e$d+�e%j-ed,�e%j-e'e#�d-�Gd.d/�d/e,e%j.����Z/e%j-e	�o*e$d+�e%j-e'e*�d0�Gd1d2�d2e,e%j.���Z0e%j-ed3�Gd4d5�d5e%j.��Z1Gd6d7�d7e%j.�Z2e3d8k�r�ee4�dS)9a�
Notes about unicode handling in psutil
======================================

In psutil these are the APIs returning or dealing with a string
('not tested' means they are not tested to deal with non-ASCII strings):

* Process.cmdline()
* Process.connections('unix')
* Process.cwd()
* Process.environ()
* Process.exe()
* Process.memory_maps()
* Process.name()
* Process.open_files()
* Process.username()             (not tested)

* disk_io_counters()             (not tested)
* disk_partitions()              (not tested)
* disk_usage(str)
* net_connections('unix')
* net_if_addrs()                 (not tested)
* net_if_stats()                 (not tested)
* net_io_counters()              (not tested)
* sensors_fans()                 (not tested)
* sensors_temperatures()         (not tested)
* users()                        (not tested)

* WindowsService.binpath()       (not tested)
* WindowsService.description()   (not tested)
* WindowsService.display_name()  (not tested)
* WindowsService.name()          (not tested)
* WindowsService.status()        (not tested)
* WindowsService.username()      (not tested)

In here we create a unicode path with a funky non-ASCII name and (where
possible) make psutil return it back (e.g. on name(), exe(), open_files(),
etc.) and make sure that:

* psutil never crashes with UnicodeDecodeError
* the returned path matches

For a detailed explanation of how psutil handles unicode see:
- https://github.com/giampaolo/psutil/issues/1040
- http://psutil.readthedocs.io/#unicode
�N)�closing)�BSD)�OPENBSD)�OSX)�POSIX)�WINDOWS)�PY3)�u)�APPVEYOR)�ASCII_FS)�bind_unix_socket)�chdir)�copyload_shared_lib)�
create_exe)�get_test_subprocess)�HAS_CONNECTIONS_UNIX)�HAS_ENVIRON)�HAS_MEMORY_MAPS)�mock)�
reap_children)�run_test_module_by_name)�
safe_mkdir)�safe_rmpath)�skip_on_access_denied)�TESTFILE_PREFIX)�TESTFN)�TESTFN_UNICODE)�TRAVIS)�unittest)�unix_socket_pathcCs8tr,yt|�Stk
r(tj�Yq4Xnt|�SdS)N)r
�_safe_rmpathZWindowsError�	traceback�	print_exc)�path�r$�$/usr/lib64/python3.6/test_unicode.pyr\srcCsTtrdSz>y t|�t|�t|gd�Wntk
r>dSXdSWdt�XdS)z`Return True if both the fs and the subprocess module can
    deal with a unicode file name.
    T)�cmdFN)rrrr�UnicodeEncodeErrorr)�namer$r$r%�subprocess_supports_unicodepsr)�utf8sf���surrogateescapeufc@s�eZdZdZedd��Zedd��Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
ejed�dd��Zejed�ejed�e�dd����Zdd�Zejed�ejed�dd���ZdS) �_BaseFSAPIsTestsNcCst|j�t|j�dS)N)r�
funky_namer)�clsr$r$r%�
setUpClass�s
z_BaseFSAPIsTests.setUpClasscCst�t|j�dS)N)rrr-)r.r$r$r%�
tearDownClass�sz_BaseFSAPIsTests.tearDownClasscCs
t�dS)N)r)�selfr$r$r%�tearDown�sz_BaseFSAPIsTests.tearDowncCstd��dS)Nzmust be implemented in subclass)�NotImplementedError)r1r$r$r%�expect_exact_path_match�sz(_BaseFSAPIsTests.expect_exact_path_matchcCsHt|jgd�}tj|j�}|j�}|j|t�|j�rD|j	||j�dS)N)r&)
rr-�psutil�Process�pid�exe�assertIsInstance�strr4�assertEqual)r1�subp�pr8r$r$r%�
test_proc_exe�sz_BaseFSAPIsTests.test_proc_execCs�t|jgd�}trRtjdtjtj��d�� }tj	|j
�j�}|jsFt
�WdQRXntj	|j
�j�}|j|t�|j�r�|j|tjj|j��dS)N)r&z psutil._psplatform.cext.proc_exe)�side_effect)rr-rr�patchr5�AccessDenied�os�getpidr6r7r(�called�AssertionErrorr9r:r4r;r#�basename)r1r<�mr(r$r$r%�test_proc_name�sz_BaseFSAPIsTests.test_proc_namecCsXt|jgd�}tj|j�}|j�}x|D]}|j|t�q(W|j�rT|j	||jg�dS)N)r&)
rr-r5r6r7�cmdliner9r:r4r;)r1r<r=rI�partr$r$r%�test_proc_cmdline�s
z"_BaseFSAPIsTests.test_proc_cmdlinec
Csj|jd}|jt|�t|�t|��tj�}|j�}WdQRX|j|j�t	�|j
�rf|j||�dS)N�2)r-�
addCleanuprrr
r5r6�cwdr9r:r4r;)r1�dnamer=rNr$r$r%�
test_proc_cwd�s

z_BaseFSAPIsTests.test_proc_cwdcCs�tj�}t|j��}t|jd��t|j��}WdQRX||j�j}|j|t	�t
rf|rf|jd�S|j�r�|j
tjj|�tjj|j��dS)N�rbzopen_files on BSD is broken)r5r6�setZ
open_files�openr-�popr#r9r:rZskipTestr4r;rB�normcase)r1r=�start�newr#r$r$r%�test_proc_open_files�s

z%_BaseFSAPIsTests.test_proc_open_filesz
POSIX onlycCs�tjj|j�}t|d���}yt|�}Wn&tk
rLtr>�n
tj	d��YnXt
|��8tj�j
d�d}|j|jt�ts�|j|j|�WdQRXWdQRXdS)N)�suffixz
not supported�unixr)rBr#rFr-rrr'rr�SkipTestrr5r6Zconnectionsr9�laddrr:rr;)r1rYr(�sock�connr$r$r%�test_proc_connections�s
z&_BaseFSAPIsTests.test_proc_connectionszcan't list UNIX socketscCs�dd�}tjj|j�}t|d���}yt|�}Wn&tk
rTtrF�n
tj	d��YnXt
|��:tjdd�}t
s�||�}|j|jt�|j|j|�WdQRXWdQRXdS)NcSs2x$|D]}tjj|j�jt�r|SqWtd��dS)Nzconnection not found)rBr#rFr\�
startswithr�
ValueError)�consr^r$r$r%�	find_sock�s
z8_BaseFSAPIsTests.test_net_connections.<locals>.find_sock)rYz
not supportedrZ)Zkind)rBr#rFr-rrr'rrr[rr5Znet_connectionsrr9r\r:r;)r1rcrYr(r]rbr^r$r$r%�test_net_connections�s
z%_BaseFSAPIsTests.test_net_connectionscCs,|jd}|jt|�t|�tj|�dS)NrL)r-rMrrr5Z
disk_usage)r1rOr$r$r%�test_disk_usage	s
z _BaseFSAPIsTests.test_disk_usagez
not supportedz&ctypes does not support unicode on PY2csvt|jd��`}dd���fdd�tj�j�D�}dd�|D�}|j�|�|�x|D]}|j|t�qTWWdQRXdS)N)Z
dst_prefixcSstjjtjj|��S)N)rBr#�realpathrU)r=r$r$r%�normpathsz3_BaseFSAPIsTests.test_memory_maps.<locals>.normpathcsg|]}�|j��qSr$)r#)�.0�x)rgr$r%�
<listcomp>sz5_BaseFSAPIsTests.test_memory_maps.<locals>.<listcomp>cSsg|]}t|kr|�qSr$)r)rhrir$r$r%rjs)rr-r5r6Zmemory_mapsZassertInr9r:)r1Z
funky_pathZlibpathsr#r$)rgr%�test_memory_mapss

z!_BaseFSAPIsTests.test_memory_maps)�__name__�
__module__�__qualname__r-�classmethodr/r0r2r4r>rHrKrPrXr�skipIfrr_rrrdrerrrkr$r$r$r%r,�s"	r,zunreliable on TRAVISzASCII fsz"subprocess can't deal with unicodec@s eZdZdZeZedd��ZdS)�
TestFSAPIsz1Test FS APIs with a funky, valid, UTF8 path name.c
CsNtrdSt|jt�rdntd�}tj��tjd�|jtj	|�kSQRXdS)NT�.�ignore)
r�
isinstancer-r:r	�warnings�catch_warnings�simplefilterrB�listdir)r.�herer$r$r%r4(s

z"TestFSAPIs.expect_exact_path_matchN)rlrmrn�__doc__rr-ror4r$r$r$r%rq srqz*subprocess can't deal with invalid unicodec@s eZdZdZeZedd��ZdS)�TestFSAPIsWithInvalidPathz-Test FS APIs with a funky, invalid path name.cCsdS)NTr$)r.r$r$r%r4<sz1TestFSAPIsWithInvalidPath.expect_exact_path_matchN)rlrmrnrz�INVALID_NAMEr-ror4r$r$r$r%r{5sr{zWINDOWS onlyc@seZdZdd�ZdS)�TestWinProcessNamec
CsFtjdtjtj��d��$}|jtj�j�t	�|j
s8t�WdQRXdS)Nz psutil._psplatform.cext.proc_exe)r?)rr@r5rArBrCr9r6r(r:rDrE)r1rGr$r$r%�test_name_typeEsz!TestWinProcessName.test_name_typeN)rlrmrnr~r$r$r$r%r}Bsr}c@s.eZdZdZdd�Zejed�dd��ZdS)�
TestNonFSAPISz&Unicode tests for non fs-related APIs.cCs
t�dS)N)r)r1r$r$r%r2WszTestNonFSAPIS.tearDownz
not supportedcCs~tjj�}trtnd}||d<t|d�}tj|j�}|j�}x,|j	�D] \}}|j
|t�|j
|t�qFW|j|d|�dS)N�èZ	FUNNY_ARG)�env)
rB�environ�copyrrrr5r6r7�itemsr9r:r;)r1r�Z	funky_strZsprocr=�k�vr$r$r%�test_proc_environZs

zTestNonFSAPIS.test_proc_environN)	rlrmrnrzr2rrprr�r$r$r$r%rTsr�__main__)5rzrBr!ru�
contextlibrr5rrrrrZpsutil._compatrr	Zpsutil.testsr
rrr
rrrrrrrrrrrr rrrrrrrr)�encode�decoder|�objectr,rpZTestCaserqr{r}rrl�__file__r$r$r$r%�<module>4sr






?>