Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/__pycache__/test_dbm_dumb.cpython-34.pyc

�
g fL�@s�dZddlZddlZddlZddlZddljZddlm	Z	ddl
mZe	jZ
dd�ZGdd�dej�Zed	kr�ej�ndS)
zATest script for the dumbdbm module
   Original by Roger E. Masse
�N)�support)�partialcCsHxAdddgD]0}ytjt|�Wqtk
r?YqXqWdS)Nz.dirz.datz.bak)�os�unlink�_fname�OSError)Zext�r�7/opt/alt/python34/lib64/python3.4/test/test_dbm_dumb.py�
_delete_filess

r
c@s}eZdZidd6dd6dd6dd6d	d
6dd6d
d6ddjd�6Zdd�Zejee	d�d�ejee	d�d�dd���Z
dd�Zdd�Zdd�Z
d d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Zd>S)?�DumbDBMTestCase��0sPython:�asProgramming�bsthe�csway�dsGuido�fsintended�g�!�üzutf-8cCsntjtd�}|jt|j��g�x"|jD]}|j|||<q8W|j|�|j�dS)N�c)	�dumbdbm�openr�assertEqual�list�keys�_dict�read_helper�close)�self�f�keyrrr	�test_dumbdbm_creation!s
z%DumbDBMTestCase.test_dumbdbm_creation�umaskztest needs os.umask()�chmodztest needs os.chmod()cCs�z2tjd�}tjtdd�}|j�Wdtj|�Xd}tjdkrad}nddl}tjtd�}|j|j	|j
�|�tjtd	�}|j|j	|j
�|�dS)
N�ri�i��posixi�rz.datz.dir)rr#rrrr�name�statr�S_IMODE�st_mode)rZ	old_umaskr Z
expected_moder(�strrr	�test_dumbdbm_creation_mode)s	z*DumbDBMTestCase.test_dumbdbm_creation_modecCsEtjt�}d|d<|j|dd�|j�|j�dS)Nrr)rrrrr)rr rrr	�test_close_twice?s


z DumbDBMTestCase.test_close_twicecCsL|j�tjtd�}d|jd<|d<|j|�|j�dS)N�wsindentedr)�init_dbrrrrrr)rr rrr	�test_dumbdbm_modificationFs


z)DumbDBMTestCase.test_dumbdbm_modificationcCs7|j�tjtd�}|j|�|j�dS)N�r)r/rrrrr)rr rrr	�test_dumbdbm_readMs

z!DumbDBMTestCase.test_dumbdbm_readcCs6|j�tjt�}|j|�}|j�dS)N)r/rrr�keys_helperr)rr rrrr	�test_dumbdbm_keysSs
z!DumbDBMTestCase.test_dumbdbm_keyscCs7tjt�}d|d<|jd|�|j�dS)Nshello�1)rrr�assertInr)rr rrr	�test_write_containsYs
z#DumbDBMTestCase.test_write_containscCs^tjt�}d|d<d|d<|j�tjt�}|j|dd�|j�dS)Nshellor5shello2)rrrrr)rr rrr	�test_write_write_read_s


z%DumbDBMTestCase.test_write_write_readcCsD|j�tjtd�}|j|d|jdjd��dS)Nr1rzutf-8)r/rrrrr�encode)rr rrr	�
test_str_readis
zDumbDBMTestCase.test_str_readcCs�|j�tjt�}d|d<d|d<|j�tjtd�}|jd|�|j|djd�|jdjd��|j|dd�dS)	Nrr�a�1r1zutf-8r5r)	r/rrrrr6rr9r)rr rrr	�test_str_write_containsns



z'DumbDBMTestCase.test_str_write_containscCs�tjt�}d|d<d|d<|j�tjtdd��}|j�}WdQXtjdkr||jdd	�}n|jd	d�}tjtdd
��}|j	|�WdQXtjt�}|j
|dd�|j
|dd�dS)Nshellor5shello2�2z.dir�rb�
s
s
�wb)rrrr�io�readr�linesep�replace�writer)rr �file�datarrr	�test_line_endingszs


z!DumbDBMTestCase.test_line_endingscCsB|j|�}x,|jD]!}|j|j|||�qWdS)N)r3rr)rr rr!rrr	r�szDumbDBMTestCase.read_helpercCsEtjtd�}x"|jD]}|j|||<qW|j�dS)Nr.)rrrrr)rr �krrr	r/�szDumbDBMTestCase.init_dbcCs;t|j��}t|jj��}|j||�|S)N)�sortedrrr)rr rZdkeysrrr	r3�szDumbDBMTestCase.keys_helperc	Cs<ddl}i}x#td�D]}tjt�}x�td�D]�}|jd�}|j�dkr�||kr�||=||=q�qA|jd�|jd	�}|||<|||<|j|||�qAW|j�tjt�}t	d
d�|j
�D��}t	|j
��}|j||�|j�qWdS)
Nr��dZ
abcdefghijklmg�������?rrri'css*|] \}}|jd�|fVqdS)zlatin-1N)r9)�.0rJ�vrrr	�	<genexpr>�sz.DumbDBMTestCase.test_random.<locals>.<genexpr>)rrr)�random�rangerrrZchoiceZ	randrangerrrK�items)	rrQ�dZdummyr rJrOZexpectedZgotrrr	�test_random�s(



zDumbDBMTestCase.test_randomcCs�tjtd��}d|d<WdQXtjtd��&}|jt|j��dg�WdQX|jtj��|j�WdQXdS)Nrzcontext managerzdumbdbm context managerr1sdumbdbm context manager)rrrrrr�assertRaises�error)rZdbrrr	�test_context_manager�s%z$DumbDBMTestCase.test_context_managerc
Cs$tjtd�}|j�x�ttj|�ttj|d�ttj|�ttj	|�fD]D}|j
tj��}|d�WdQX|jt
|j�d�qbWxstjd�tjd�tjd�tfD]D}|j
tj��}||�WdQX|jt
|j�d�q�WdS)Nr�b�testz"DBM object has already been closedrZiterkeysrS)rrrrr�operator�delitem�setitem�getitem�containsrVrWr�strZ	exception�methodcaller�len)rr �meth�cmrrr	�test_check_closed�s$

z!DumbDBMTestCase.test_check_closedcCs�ttdd��}|jd�WdQXtj��K}|jt��tjt��}WdQXWdQX|j|j	�d�WdQXdS)Nz.dirr.zstr(print('Hacked!')), 0
�)
rrrFrZcaptured_stdoutrV�
ValueErrorrr�getvalue)r�stream�stdoutr rrr	�	test_eval�szDumbDBMTestCase.test_evalcCst�dS)N)r
)rrrr	�tearDown�szDumbDBMTestCase.tearDowncCst�dS)N)r
)rrrr	�setUp�szDumbDBMTestCase.setUpN)�__name__�
__module__�__qualname__r9rr"�unittestZ
skipUnless�hasattrrr,r-r0r2r4r7r8r:r=rIrr/r3rUrXrerkrlrmrrrr	rs:
*

	r�__main__)�__doc__rBr[rrqZdbm.dumbZdumbrrZr�	functoolsrZTESTFNrr
ZTestCaserrn�mainrrrr	�<module>s	�