Your IP : 216.73.217.32


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_mmap.cpython-35.opt-2.pyc



���]5m�@s�ddlmZmZmZmZmZmZmZmZm	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZed�ZejZGdd�de
j�ZGdd�de
j�Zdd	�Zed
kr�e�dS)�)	�TESTFN�run_unittest�
import_module�unlink�requires�_2G�_4G�
gc_collect�cpython_onlyN�mmapc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zej
eed�d�dd��Zej
eed�d�dd��Zej
eed�d�dd��Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zej
eed/�d0�d1d2��Zd3d4�Zd5d6�Z d7d8�Z!ej
ej"d9kd:�d;d<��Z#e$ej
ej"d9kd:�d=d>���Z%ej
ej"d9kd:�d?d@��Z&ej
ej"d9kd:�dAdB��Z'dCdD�Z(dEdF�Z)dGdH�Z*ej+ej"d9kdI�dJdK��Z,dLS)M�	MmapTestscCs#tjjt�rtjt�dS)N)�os�path�existsrr)�self�r�./opt/alt/python35/lib64/python3.5/test_mmap.py�setUpszMmapTests.setUpcCs*ytjt�Wntk
r%YnXdS)N)r
rr�OSError)rrrr�tearDowns
zMmapTests.tearDowncCs�ttd�}z]|jdt�|jd�|jdtd�|j�tj|j�dt�}Wd|j�Xtt	|��}|j
|jd�t�|j
t|�dt�|j
|dd�|j
|dd�d�|j
t|jt|��|j
t|jt|�d�d|d<d	|tdtdd�<|j
|dd�|j
|dd�d
�|j
|tdtd�d
�|j�tjd|�}|dkr�|jd�nC|jd�\}}||}|j
|t�|j
|td�|jdd�|j
|j�d�|jdd�|j
|j�d�|jdd�|j
|j�t|��|j
t|jd�|j
t|jdd�|j
t|jt|�dd�y|jd�Wntk
r	Yn�X|j
t|�d�|j
t|jdd�ttd�}z*|jdd�|j
|j�d�Wd|j�X|j
|j�d�|j�dS)Nzbw+ssfoo��rs�3sbars3��sfoobars	[A-Za-z]+zregex match on mmap failed!��*ii�rb�3r���)�openr�write�PAGESIZE�flushr�fileno�close�str�type�assertEqual�find�len�assertRaises�
IndexError�__getitem__�__setitem__�re�search�fail�span�seek�tell�
ValueError�resize�SystemError�size)r�f�m�tp�match�start�end�lengthrrr�
test_basicsd

 
"

$
zMmapTests.test_basicc�Cs�d}ttd��}|jd|�WdQRXttd���}tj|j�|dtj�}|j|dd�d|d�yd||dd�<Wntk
r�YnX|jd�yd|d	<Wntk
r�YnX|jd�y!|j	d	d	�|jd
�Wntk
r#YnX|jd�y!|j	d	d	�|j
d�Wntk
rfYnX|jd�y|jd|�Wn#tk
r�Yntk
r�YnX|jd
�ttd��$}|j|j
�d|d�WdQRXWdQRXttd���}y tj|j�|d�}Wn1tk
r^tjjd�rZ|jd�Yn*Xtjjd�s~|jd�|j�tjjd�r�ttd��}|j|�WdQRXWdQRXttd��q}tj|j�|dtj�}d||dd�<|j|dd�d|d�|j�|j�WdQRXttd��}|j
�}WdQRX|j|d|d�ttd���}tj|j�|dtj�}d||dd�<|j|dd�d|d�|j�ttd��$}|j|j
�d|d�WdQRX|jt|jd|�|j�WdQRXttd��,}|jttj|j�|dd�WdQRXtjdkrttd��A}|jttj|j�|dtjdtjdtj�WdQRXtjttdd	�B}ttd��[}tj|j�|d|�}|jt|jd�|jt|j
d	�|j�WdQRXdS)N�
�wb�ar�accessz#Readonly memory map data incorrect.�bz$Able to write to readonly memory maprsabc�drz"Able to resize readonly memory mapz*Readonly memory map data file was modifiedzr+br�winz0Opening mmap with size+1 should work on Windows.z1Opening mmap with size+1 should raise ValueError.�cz5Write-through memory map memory not updated properly.z8Write-through memory map data file not updated properly.z4Copy-on-write memory map data not written correctly.z4Copy-on-write test data file should not be modified.��posix�flags�protZ	PROT_EXECsabcdef)r rr!rr$�ACCESS_READr(�	TypeErrorr1r3�
write_byter6r7�readr5�sys�platform�
startswithr%�truncateZACCESS_WRITEr#ZACCESS_COPYr+r
�nameZMAP_PRIVATE�	PROT_READ�getattr)r�mapsize�fpr9r:�stuffrLrrr�test_access_parameterzs�!!










 


!
!
,	zMmapTests.test_access_parametercCs|jttjdd�dS)Nri���)r+rr)rrrr�test_bad_file_desc�szMmapTests.test_bad_file_descc
Cs�ttd��H}d}t|�}|j|�|j�tj|j�|�}WdQRXx�t|d�D]s}xjt||d�D]U}|||�}|j|j	|�|j	|��|j|j	|d�d�q�WqkW|j
�dS)Nzwb+saabaacdeefaar�xr)r rr*r!r#rr$�ranger(r)r%)rr9�data�nr:r=Zfinish�slicerrr�test_tougher_find�s

"%zMmapTests.test_tougher_findcCs(ttd�}d}t|�}|j|�|j�tj|j�|�}|j�|j|j	d�d�|j|j	d�d�|j|j	ddd	�d�|j|j	dd�d�|j|j	ddd
�d�|j|j	ddd�d�|j|j	t
d��d�dS)
Nzwb+sone two onessonersones�rrrrr\r)r rr*r!r#rr$r%r(r)�	bytearray)rr9r`rar:rrr�
test_find_end
s


zMmapTests.test_find_endcCs+ttd�}d}t|�}|j|�|j�tj|j�|�}|j�|j|j	d�d�|j|j	d�d�|j|j	ddd	�d�|j|j	ddd
�d�|j|j	ddd�d�|j|j	ddd�d
�|j|j	t
d��d�dS)Nzwb+sone two onessonerdsone rrrrr\rr\r)r rr*r!r#rr$r%r(�rfindre)rr9r`rar:rrr�
test_rfind s


zMmapTests.test_rfindcCs|ttd�}|jdd�|j�ttd�}tj|j�ddtj�}|j�|j�|j�dS)	Nzwb+r�rCrrDii)r rr!r%rr$rM)rr9�mfrrr�test_double_close3s
!

zMmapTests.test_double_close�statzneeds os.stat()cCs�ttd�}|jdd�|j�ttd�}tj|j�d�}|jt|�d	d�|j|jd
�dd�|j�|j�dS)Nzwb+rri�mzrb+rz Map size should equal file size.iiii)	r rr!r%rr$r(r*rP)rr9rjrrr�test_entire_file@s

zMmapTests.test_entire_filecCs�ttd��}|jd
d�WdQRXttd��N}tj|j�ddddtj��}|jt|jd	�WdQRXWdQRXdS)NrBirrmrr�offsetrDi�8i)	r rr!rr$rMr+r,r-)rr9rjrrr�test_length_0_offsetOs
*zMmapTests.test_length_0_offsetcCslttd��}|jdd�WdQRXttd��,}|jttj|j�ddd�WdQRXdS)NrBi��rmzw+brroi�)r rr!r+r5rr$)rr9rrr�test_length_0_large_offset\s
z$MmapTests.test_length_0_large_offsetcCs�ttd�}|jd�|j�tj|j�d�}|jddd�|j|dd�dd�|j�|j�d}x�t	t
|��D]�}x�t	t
|��D]�}x�t	t
|�t||��D]�}|d|�||||�|||d�}tjdt
|��}||dd�<|j|||�|j|dd�|�|j�q�Wq�Wq�Wtjd
d
�}dddd	d
g}	xRtj
|	|	|	�D];\}
}}y|j|
||�Wq�tk
r�Yq�Xq�Wdddddd d"g}	x3|	D]+\}
}}|jt|j|
||�qW|j�tjd#d	�}|jt|jddd�|jt|jd	dd	�|jt|jdd	d	�|jddd	�|jddd�dS)$Nzwb+s
ABCDEabcderA�rs
ABCDEABCDEz'Map move should have duplicated front 5s
0123456789r�drrri����rrrr)rrrrr)rrrrr)rrrrr)rrrr)rrrr)rrrr)rrrr)r rr!r#rr$�mover(r%r_r*�max�	itertools�productr5r+)rr9rjr`�dest�src�countZexpectedr:Zoffsets�sourcer8rrr�	test_movegsH



&4%
	 
zMmapTests.test_movecCs�tjdt�}x+tt�D]}|j||dd�qWx<tt�D].}|d@}|||<|j|||�qMWdS)Nrrz+anonymously mmap'ed contents should be zero�r)rr"r_r()rr:�x�brrr�test_anonymous�s

zMmapTests.test_anonymouscCs�tjdd�}|j|j�|jttd���|jd�|j|j�ttd���|jd�|j|j�ttdd���|jd�|j|j�d�|jd�|j|jd�ttdd���|jd�|j|jd
�ttdd���|jd�|j|jd�ttdd���|jd
�|j|jd�ttd
d���dS)Nrrirrd�rrIrrr�	rrrr\i���)	r�
addCleanupr%r!�bytesr_r3r(rP)rr:rrr�
test_read_all�s"
"
%

(
(
(
zMmapTests.test_read_allcCsqtjdd�}|j|j�|jt|jd�|jt|jd�|jt|jdddg�dS)Nrri�foog@rrr)rr�r%r+rNrP)rr:rrr�test_read_invalid_arg�s
zMmapTests.test_read_invalid_argc
Cs�tttd���}tjd	t|��}||dd�<|j|dd�|�d}xd|D]\}xS|D]K}xB|dd�D]0}|j||||�||||��q�WqtWqgWdS)N�rrr��,r�rrr\�������)
rNrrr�r�rr\r�r�)r��reversedr_rr*r()r�sr:�indicesr=�stop�steprrr�test_extended_getslice�s

z MmapTests.test_extended_getslicec	
Cstttd���}tjd	t|��}d}x�|D]�}x�|D]�}x�|dd�D]�}||dd�<|j|dd�|�t|�}||||�}tt|��}|||||�<|||||�<|j|dd�t|��qaWqJWq=WdS)Nr�rrrr��,rr�rrr\�������)
rNrrr�r�rr\r�r�)r�r�r_rr*r(�list)	rr�r:r�r=r�r��Lr`rrr�test_extended_set_del_slice�s

z%MmapTests.test_extended_set_del_slicecCsS|jd|�|jd�|jd|d�|j�tj|j�d�S)Nssfoorr)r!r#rr$)rr9�halfsizerrr�make_mmap_file�s


zMmapTests.make_mmap_filecCsattd�}|j�ttd��2}|jtdtj|j�ddtj�WdQRXdS)Nzw+brzcannot mmap an empty filerrD)r rr%ZassertRaisesRegexr5rr$rM)rr9rrr�test_empty_file�s
	zMmapTests.test_empty_filecCsBttd�}z�tj}|j||�}|j�|j�|d}ttd�}xwdd
dgD]f}y2tj|j�|d|�}|jdd�Wntt	t
fk
r�YqjX|jdd�qjW|j�ttd�}tj|j�||d|�}|j|dd�d�|j�y|jd	�Wntk
rXYn�X|jt
|�d	�|jt|jd
d�|j|dd�d�ttd�}|jdd�|j|j�|d	�|j�|j|j�|d	�|j�Wd|j�ytjt�Wntk
r<YnXXdS)Nzw+brzr+brrorrsfooiirr\r)r rrZALLOCATIONGRANULARITYr�r%r$r(r5rN�
OverflowErrorr6r7r*r+r3r4r8r
rr)rr9r�r:rXrorrr�test_offset�sL	



"




zMmapTests.test_offsetcCs'Gdd�dtj�}|t�dS)Nc@seZdZdd�ZdS)z*MmapTests.test_subclass.<locals>.anon_mmapc_stjj|d||�S)Nrr)r�__new__)�klass�args�kwargsrrrr�/sz2MmapTests.test_subclass.<locals>.anon_mmap.__new__N)�__name__�
__module__�__qualname__r�rrrr�	anon_mmap.sr�)rr")rr�rrr�
test_subclass-szMmapTests.test_subclassrVzneeds mmap.PROT_READcCs�d}ttd��}|jd|�WdQRXttd�}tj|j�|dtj�}|jt|jd�|j�dS)NrArBrCrrLr�)	r rr!rr$rVr+rNr%)rrXrYr9r:rrr�test_prot_readonly3s!zMmapTests.test_prot_readonlycCs|jtjt�dS)N)�assertIsr�errorr)rrrr�
test_error=szMmapTests.test_errorcCsed}ttd��}|jdt|��WdQRXttd�}tj|j�t|��}|j�x[tt|��D]G}|j|j	�|�|j
||�|j|j	�|d�q�W|jt|j
d�|j|dd�|�|j
d�xdtt|��D]P}|j|j	�|�|j|j�||�|j|j	�|d�qW|jt|j�|j
d�|j|jd�d�|j|j	�d	�|j
d�|jd
�|j|j	�d	�|j|dd�d�|jtd��|j|j	�d
�|j|dd�d�|jt|jd�dS)Ns
0123456789rBr^zr+brrrs345rsbars
012bar6789sbazr�s
012barbaz9sba�x)r rr!r*rr$r%r_r(r4rOr+r5r3�	read_byterPre)rr`rYr9r:�irrr�test_io_methods@s:




zMmapTests.test_io_methodscCsuxndD]f}tjdd�}|j|�|j|d|�|jd�|j|j�|�|j�qWdS)N���r}rr)r�r�r}r)rrOr(r3r�r%)rrr:rrr�test_non_ascii_bytecs


zMmapTests.test_non_ascii_byte�ntzrequires WindowscCsXd}d}tjdt|�dd�}||dd�<tjdt|�dd�}||dd�<|j|dd�|�|j|dd�|�|j�|j�tjd	t|�dd�}||dd�<tjd
t|�dd�}||dd�<|j|dd�|�|j|dd�|�|j�|j�dS)Ns
0123456789s
abcdefghijr�tagnamer�Zboorrrr)rr*r(r%)rZdata1Zdata2�m1�m2rrr�test_tagnamels$


zMmapTests.test_tagnamecCsdtjdd�}d}tjddd|�}|jtj|�tj|�t|�d�dS)Nrrsr�r�rr)rr(rQ�	getsizeofr*)rr�r�r�rrr�test_sizeof�s
zMmapTests.test_sizeofcCs�tjdddd�}y$tjdddd�dd�WnYnX|j�ttd��}|jd
�WdQRXttd	�}tj|j�d
�}|j�y|jd
�WnYnXy|dd�WnYnX|j�dS)Nri�r�r�i�rBr^rAzr+brrrs
xxxxxxxxxx)rr%r rr!r$r6)rr:rYr9rrr�test_crasher_on_windows�s($

z!MmapTests.test_crasher_on_windowscCsQtj�}z3|jt��tj|j�d�}WdQRXWd|j�XdS)NrA)�socketr+rrr$r%)rr�r:rrr�test_invalid_descriptor�s
#z!MmapTests.test_invalid_descriptorc	Cs@tjdd��}|j|j�WdQRX|j|j�dS)NrrAr)rZassertFalse�closed�
assertTrue)rr:rrr�test_context_manager�szMmapTests.test_context_managercCsh|jt��)}tjdd��
}t�WdQRXWdQRX|j|jtd�|j|jd�dS)NrrAz)wrong exception raised in context managerzcontext manager failedr)r+�	ExceptionrrZassertIsInstance�	exceptionr�r�)r�excr:rrr�test_context_manager_exception�sz(MmapTests.test_context_manager_exceptioncCsUtjdd�}tj|�}|j|�|�~t�|j|�d�dS)Nrrir)r�weakref�refr�r	)rZmm�wrrrr�test_weakref�szMmapTests.test_weakrefz(cannot resize anonymous mmaps on WindowscCs�tjd
d�}|j|j�|jd�y|jd�Wntk
ra|jd�YnX|j|jd�d�|jt	|j
�|jt	|jd�|jt	|jd	�dS)Nri i�izresizing not supported�r�rsabcr)
rr�r%rPr6r7ZskipTestr(r+r5r�rOr!)rr:rrr�test_resize_past_pos�s

zMmapTests.test_resize_past_posN)-r�r�r�rrr@r[r]rcrfrhrk�unittest�
skipUnless�hasattrr
rnrprqr|r�r�r�r�r�r�r�r�r�rr�r�r�r�rUr�r
r�r�r�r�r�r�ZskipIfr�rrrrrsF^}
''
'1	9'
#	'*''		rc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	j
eje
kd
�dd��Ze	j
eje
kd
�dd��ZdS)�LargeMmapTestscCstt�dS)N)rr)rrrrr�szLargeMmapTests.setUpcCstt�dS)N)rr)rrrrr�szLargeMmapTests.tearDowncCs�tjdd�dks(tjdkr?tddtd��ttd�}y(|j|�|j|�|j�WnSt	t
tfk
r�y|j�Wnt	t
fk
r�YnXt
jd��YnX|S)	NrrG�darwinZ	largefilez-test requires %s bytes and a long time to runlzw+bz*filesystem does not have largefile support)rQrRrr&r rr3r!r#rr�r5r%r�ZSkipTest)rZ
num_zeroes�tailr9rrr�_make_test_file�s(

zLargeMmapTests._make_test_filecCse|jdd��L}tj|j�ddddtj��}|j|dd�WdQRXWdQRXdS)	Nl��� rrolrDi���� )r�rr$rMr()rr9r:rrr�test_large_offset�s*z LargeMmapTests.test_large_offsetcCs�|jdd���}tjdkr�|jt��$tj|j�ddtj�WdQRX|jt��$tj|j�ddtj�WdQRXtj|j�ddtj��}|j	|j
�d�WdQRXWdQRXdS)Nl��r�lrDri)r�rQ�maxsizer+r�rr$rMr5r(r8)rr9r:rrr�test_large_filesize�s&&$z"LargeMmapTests.test_large_filesizecCs�d}|t|�d}|t|�}|j||��L}tj|j�ddtj��!}|j|||�|�WdQRXWdQRXdS)Ns  DEARdear  rrrD)r*r�rr$rMr()r�boundaryr�r=r>r9r:rrr�_test_around_boundarys$z$LargeMmapTests._test_around_boundaryz!test cannot run on 32-bit systemscCs|jt�dS)N)r�r)rrrr�test_around_2GBszLargeMmapTests.test_around_2GBcCs|jt�dS)N)r�r)rrrr�test_around_4GBszLargeMmapTests.test_around_4GBN)r�r�r�rrr�r�r�r�r�r�rQr�rr�r�rrrrr��s'r�cCsttt�dS)N)rrr�rrrr�	test_mainsr��__main__)Ztest.supportrrrrrrrr	r
r�r
r/rvr�rQr�rr"ZTestCaserr�r�r�rrrr�<module>s @	���=