Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/test_dbm_dumb.cpython-311.pyc
�

�KeN,����dZddlZddlZddlZddlZddlZddlZddlmZ	ddl
mZddlm
Z
ddlmZe
jZd�ZGd�dej��Zed	krej��dSdS)
zATest script for the dumbdbm module
   Original by Roger E. Masse
�N)�support)�	os_helper)�partialc�j�dD]/}	tjt|z��� #t$rY�,wxYwdS)N��.dir�.dat�.bak)�os�unlink�_fname�OSError)�exts �</usr/local/apps/python3/lib/python3.11/test/test_dbm_dumb.py�
_delete_filesrsW��'����	��I�f�s�l�#�#�#�#���	�	�	��D�	�����s�#�
0�0c��eZdZddddddddd	d
ddd
dd�d��diZd�Zejee	d��d��e
jd�����Zd�Z
d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd �Zd!�Zd"�Zd#�Zd$�Zd%�Zd&�Zd'�Zd(�Zd)�Z e
jd*���Z!eje
j"d+��d,���Z#d-�Z$d.�Z%d/�Z&d0�Z'd1�Z(d2S)3�DumbDBMTestCase�0��asPython:�bsProgramming�csthe�dsway�fsGuido�gsintended�ü�utf-8�!c�X�tjtjtd����5}|�t
|�����g��|jD]}|j|||<�|�	|��ddd��dS#1swxYwYdS�N�c)
�
contextlib�closing�dumbdbm�openr
�assertEqual�list�keys�_dict�read_helper)�self�f�keys   r�test_dumbdbm_creationz%DumbDBMTestCase.test_dumbdbm_creation%s���
�
���V�S� 9� 9�
:�
:�	 �a����T�!�&�&�(�(�^�^�R�0�0�0��z�
)�
)����C���#������Q����		 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 �	 �	 s�A%B�B#�&B#�umaskztest needs os.umask()c�.�	tjd��}tjtdd��}|���tj|��n#tj|��wxYwd}tjdkrd}ddl}tjtdz��}|�|j	|j
��|��tjtd	z��}|�|j	|j
��|��dS)
N�r!i�i��posixi�rr	r)rr/r$r%r
�close�name�statr&�S_IMODE�st_mode)r+�	old_umaskr,�
expected_moder5�sts      r�test_dumbdbm_creation_modez*DumbDBMTestCase.test_dumbdbm_creation_mode,s���	 ������I���V�S�%�0�0�A�
�G�G�I�I�I��H�Y������B�H�Y���������
�
�7�g���"�M�����
�W�V�f�_�
%�
%��������b�j�1�1�=�A�A�A�
�W�V�f�_�
%�
%��������b�j�1�1�=�A�A�A�A�As�AA�A0c���tjt��}d|d<|�|dd��|���|���dS)Nrr)r$r%r
r&r3�r+r,s  r�test_close_twicez DumbDBMTestCase.test_close_twiceBsR���L�� � ����$������4��$�'�'�'�	���	�	�	�	���	�	�	�	�	rc��|���tjtjt
d����5}dx|jd<|d<|�|��|�|�	dd��d��|�|dd��ddd��dS#1swxYwYdS)N�wsindentedr�xxx�foo)
�init_dbr"r#r$r%r
r)r*r&�
setdefaultr=s  r�test_dumbdbm_modificationz)DumbDBMTestCase.test_dumbdbm_modificationIs���������
�
���V�S� 9� 9�
:�
:�	0�a�)4�4�D�J�t��q��w����Q�������Q�\�\�&�&�9�9�6�B�B�B����Q�v�Y��/�/�/�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0����	0�	0�	0�	0�	0�	0s�A+B9�9B=�B=c�R�|���tjtjt
d����5}|�|��|�tjd��5d|d<ddd��n#1swxYwY|�tjd��5|d=ddd��n#1swxYwY|�	|�
d��|jd��|�	|�
dd��d��|�|�
d����|�
t��5|dddd��n#1swxYwYddd��dS#1swxYwYdS)N�rz'The database is opened for reading only�xrrrArB)rCr"r#r$r%r
r*�assertRaisesRegex�errorr&�getr)�assertIsNone�assertRaises�KeyErrorr=s  r�test_dumbdbm_readz!DumbDBMTestCase.test_dumbdbm_readRsx��������
�
���V�S� 9� 9�
:�
:�
	�a����Q�����'�'��
�$M�O�O�
�
���$��
�
�
�
�
�
�
�
�
�
�
����
�
�
�
��'�'��
�$M�O�O�
�
��d�G�
�
�
�
�
�
�
�
�
�
�
����
�
�
�
�
���Q�U�U�4�[�[�$�*�T�*:�;�;�;����Q�U�U�6�6�2�2�F�;�;�;����a�e�e�F�m�m�,�,�,��"�"�8�,�,�
�
��&�	�	�
�
�
�
�
�
�
�
�
�
�
����
�
�
�
�
	�
	�
	�
	�
	�
	�
	�
	�
	�
	�
	�
	����
	�
	�
	�
	�
	�
	s�6F�7B	�=F�	B
	�
F�B
	�#F�4C�8F�C	�F�C	�B#F�/	F�8F�F	�F�F	�F�F �#F c���|���tjtjt
����5}|�|��}ddd��dS#1swxYwYdS�N)rCr"r#r$r%r
�keys_helper)r+r,r(s   r�test_dumbdbm_keysz!DumbDBMTestCase.test_dumbdbm_keyscs���������
�
���V� 4� 4�
5�
5�	'���#�#�A�&�&�D�	'�	'�	'�	'�	'�	'�	'�	'�	'�	'�	'�	'����	'�	'�	'�	'�	'�	's�A#�#A'�*A'c���tjtjt����5}d|d<|�d|��ddd��dS#1swxYwYdS)N�hello�1)r"r#r$r%r
�assertInr=s  r�test_write_containsz#DumbDBMTestCase.test_write_containshs���
�
���V� 4� 4�
5�
5�	#���A�d�G��M�M�$��"�"�"�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#����	#�	#�	#�	#�	#�	#s�A�A�Ac�`�tjtjt����5}d|d<d|d<ddd��n#1swxYwYtjtjt����5}|�|dd��ddd��dS#1swxYwYdS)NrUrV�hello2)r"r#r$r%r
r&r=s  r�test_write_write_readz%DumbDBMTestCase.test_write_write_readms��
�
���V� 4� 4�
5�
5�	 ���A�d�G��A�d�G�	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 ��
���V� 4� 4�
5�
5�	1�����Q�t�W�i�0�0�0�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1����	1�	1�	1�	1�	1�	1s#�A�A�
A�9B#�#B'�*B'c�,�|���tjtjt
d����5}|�|d|jd�d����ddd��dS#1swxYwYdS)NrGrr)	rCr"r#r$r%r
r&r)�encoder=s  r�
test_str_readzDumbDBMTestCase.test_str_readus���������
�
���V�S� 9� 9�
:�
:�	P�a����Q�x�[�$�*�X�_�_�W�5M�5M�*N�O�O�O�	P�	P�	P�	P�	P�	P�	P�	P�	P�	P�	P�	P����	P�	P�	P�	P�	P�	Ps�;B	�	B
�B
c�P�|���tjtjt
����5}d|d<d|d<ddd��n#1swxYwYtjtjt
d����5}|�d|��|�|d�d��|j	d�d����|�|dd��ddd��dS#1swxYwYdS)	Nrr�a�1rGrrVr)
rCr"r#r$r%r
rWr&r]r)r=s  r�test_str_write_containsz'DumbDBMTestCase.test_str_write_containszs���������
�
���V� 4� 4�
5�
5�	���A�h�K��A�c�F�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	��
���V�S� 9� 9�
:�
:�	,�a��M�M�(�A�&�&�&����Q�x���w�7�7�8�!�Z�����(@�(@�A�
C�
C�
C����Q�t�W�d�+�+�+�		,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,����	,�	,�	,�	,�	,�	,s%�A�A�A�BD�D�"Dc���tjtjt����5}d|d<d|d<ddd��n#1swxYwYtjtdzd��5}|���}ddd��n#1swxYwYtjdkr|�	dd	��}n|�	d	d��}tjtdzd
��5}|�
|��ddd��n#1swxYwYtjt��}|�|dd��|�|dd��dS)NrUrVrZ�2r�rb�
�
s
�wb)r"r#r$r%r
�io�readr�linesep�replace�writer&)r+r,�file�datas    r�test_line_endingsz!DumbDBMTestCase.test_line_endings�s����
���V� 4� 4�
5�
5�	 ���A�d�G��A�d�G�	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 �
�W�V�f�_�d�
+�
+�	�t��9�9�;�;�D�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�
�:�����<�<��w�/�/�D�D��<�<���/�/�D�
�W�V�f�_�d�
+�
+�	�t��J�J�t����	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�
�L�� � ������4��(�+�+�+�����4��)�,�,�,�,�,s5�A�A�
A�+B�B�B�1D�D�Dc��|�|��}|jD])}|�|j|||���*dSrQ)rRr)r&)r+r,r(r-s    rr*zDumbDBMTestCase.read_helper�sS������"�"���:�	6�	6�C����T�Z��_�a��f�5�5�5�5�	6�	6rc���tjtjtd����5}|jD]}|j|||<�	ddd��dS#1swxYwYdS�N�n)r"r#r$r%r
r)�r+r,�ks   rrCzDumbDBMTestCase.init_db�s���
�
���V�S� 9� 9�
:�
:�	%�a��Z�
%�
%���z�!�}��!���
%�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%����	%�	%�	%�	%�	%�	%s�A�A�Ac��t|�����}t|j�����}|�||��|SrQ)�sortedr(r)r&)r+r,r(�dkeyss    rrRzDumbDBMTestCase.keys_helper�sK���a�f�f�h�h�����t�z���(�(�)�)������u�%�%�%��rc�B�ddl}i}td��D�]�}tjt	jt����5}td��D]�}|�d��}|���dkr||vr||=||=�:|�d��|�d��z}|||<|||<|�	|||����	ddd��n#1swxYwYtjt	jt����5}td�|���D����}t|�����}|�	||��ddd��n#1swxYwY���dS)	Nr��d�
abcdefghijklmg�������?)rrri'c3�JK�|]\}}|�d��|fV��dS)zlatin-1N)r])�.0rv�vs   r�	<genexpr>z.DumbDBMTestCase.test_random.<locals>.<genexpr>�s7����!Q�!Q�t�q�!�1�8�8�I�#6�#6��":�!Q�!Q�!Q�!Q�!Q�!Qr)�random�ranger"r#r$r%r
�choice�	randranger&rx�items)	r+r��d�dummyr,rvr��expected�gots	         r�test_randomzDumbDBMTestCase.test_random�s���
�
�
����1�X�X�	0�	0�E��#�G�L��$8�$8�9�9�
2�Q�"�3�Z�Z�
2�
2�E��
�
�o�6�6�A��}�}����,�,���6�6� !�!�� !�!���"�M�M�*<�=�=��@P�@P�QV�@W�@W�W�� ��!�� ��!���(�(��1��q�1�1�1�1�
2�
2�
2�
2�
2�
2�
2�
2�
2�
2�
2�
2����
2�
2�
2�
2��#�G�L��$8�$8�9�9�
0�Q�!�!Q�!Q�q�w�w�y�y�!Q�!Q�!Q�Q�Q���Q�W�W�Y�Y�'�'��� � ��3�/�/�/�
0�
0�
0�
0�
0�
0�
0�
0�
0�
0�
0����
0�
0�
0�
0��	0�	0s&�BC-�-C1	�4C1	�#A#F�F	�F	c���tjtd��5}d|d<ddd��n#1swxYwYtjtd��5}|�t	|�����dg��ddd��n#1swxYwY|�tj��5|���ddd��dS#1swxYwYdS)Nr!zcontext managerzdumbdbm context managerrGsdumbdbm context manager)r$r%r
r&r'r(rMrJ)r+�dbs  r�test_context_managerz$DumbDBMTestCase.test_context_manager�s���
�\�&�#�
&�
&�	>�"�,=�B�(�)�	>�	>�	>�	>�	>�	>�	>�	>�	>�	>�	>����	>�	>�	>�	>��\�&�#�
&�
&�	L�"����T�"�'�'�)�)�_�_�/I�.J�K�K�K�	L�	L�	L�	L�	L�	L�	L�	L�	L�	L�	L����	L�	L�	L�	L��
�
�w�}�
-�
-�	�	��G�G�I�I�I�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s0�-�1�1�7B�B�B�?C!�!C%�(C%c�f�tjtd��}|���t	t
j|��t	t
j|d��t	t
j|��t	t
j	|��fD]l}|�
tj��5}|d��ddd��n#1swxYwY|�t|j��d���mtjd��tjd��tjd��t fD]l}|�
tj��5}||��ddd��n#1swxYwY|�t|j��d���mdS)Nr!�b�testz"DBM object has already been closedr(�iterkeysr�)r$r%r
r3r�operator�delitem�setitem�getitem�containsrMrJr&�str�	exception�methodcaller�len)r+r,�meth�cms    r�test_check_closedz!DumbDBMTestCase.test_check_closed�s���L���%�%��	���	�	�	��X�-�q�1�1��X�-�q�#�6�6��X�-�q�1�1��X�.��2�2�4�	C�	C�D��"�"�7�=�1�1�
�R���V����
�
�
�
�
�
�
�
�
�
�
����
�
�
�
����S���.�.�A�
C�
C�
C�
C��*�6�2�2��*�:�6�6��*�7�3�3���	C�	C�D��"�"�7�=�1�1�
�R���Q����
�
�
�
�
�
�
�
�
�
�
����
�
�
�
����S���.�.�A�
C�
C�
C�
C�
	C�	Cs$�7C�C	�C	�%E=�=F	�F	c�V�tjtd��5}|jD]}|j|||<�	ddd��n#1swxYwYtjtd��5}|�|���g��ddd��dS#1swxYwYdSrs)r$r%r
r)r&r(rus   r�test_create_newzDumbDBMTestCase.test_create_new�s ��
�\�&�#�
&�
&�	%�!��Z�
%�
%���z�!�}��!���
%�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%����	%�	%�	%�	%��\�&�#�
&�
&�	+�!����Q�V�V�X�X�r�*�*�*�	+�	+�	+�	+�	+�	+�	+�	+�	+�	+�	+�	+����	+�	+�	+�	+�	+�	+s#�A�A�
A�()B�B"�%B"c��ttdzdd���5}|�d��ddd��n#1swxYwYtj��5}|�t��5tjt��5}	ddd��n#1swxYwYddd��n#1swxYwY|�|�	��d��ddd��dS#1swxYwYdS)Nrr@r)�encodingzstr(print('Hacked!')), 0
�)
r%r
rmr�captured_stdoutrM�
ValueErrorr$r&�getvalue)r+�stream�stdoutr,s    r�	test_evalzDumbDBMTestCase.test_eval�s���
�&�6�/�3��
9�
9�
9�	7�V��L�L�5�6�6�6�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7����	7�	7�	7�	7�
�
$�
&�
&�	4�&��"�"�:�.�.�
�
��\�&�)�)��Q��������������������
�
�
�
�
�
�
�
�
�
�
����
�
�
�
�
���V�_�_�.�.��3�3�3�		4�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4����	4�	4�	4�	4�	4�	4si�=�A�A�C5�6B5�B�B5�B"�"B5�%B"�&B5�)C5�5B9	�9C5�<B9	�=+C5�5C9�<C9c��dD]�}t��|�t��5tjt
|��ddd��n#1swxYwY|�tj�	t
dz����|�tj�	t
dz������dS)N�rGr@rr
)
rrM�FileNotFoundErrorr$r%r
�assertFalser�path�exists)r+�values  r�test_missing_dataz!DumbDBMTestCase.test_missing_data�s����	>�	>�E��O�O�O��"�"�#4�5�5�
,�
,���V�U�+�+�+�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,����
,�
,�
,�
,����R�W�^�^�F�V�O�<�<�=�=�=����R�W�^�^�F�V�O�<�<�=�=�=�=�	>�	>s�A�A	�A	c�.�tjtd��5}	ddd��n#1swxYwYtjtdz��dD]�}|�t��5tjt|��ddd��n#1swxYwY|�tj�	tdz����|�tj�	tdz������dS)Nrtrr�r
)
r$r%r
rrrMr�r�r�r�)r+r,r�s   r�test_missing_indexz"DumbDBMTestCase.test_missing_index�sa��
�\�&�#�
&�
&�	�!��	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�
�	�&�6�/�"�"�"��	>�	>�E��"�"�#4�5�5�
,�
,���V�U�+�+�+�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,����
,�
,�
,�
,����R�W�^�^�F�V�O�<�<�=�=�=����R�W�^�^�F�V�O�<�<�=�=�=�=�		>�	>s�)�-�-�.B�B	�B	c��dD]O}|�td��5tjt|��ddd��n#1swxYwY�PdS)N)�x�rfNz)Flag must be one of 'r', 'w', 'c', or 'n')rIr�r$r%r
)r+�flags  r�test_invalid_flagz!DumbDBMTestCase.test_invalid_flags���%�	+�	+�D��'�'�
�)@�A�A�
+�
+���V�T�*�*�*�
+�
+�
+�
+�
+�
+�
+�
+�
+�
+�
+����
+�
+�
+�
+��	+�	+s�A�A	�A	c��tj��5}tj�|d��}tj|d��5}|�t|�	����g��|j
D]}|j
|||<�	ddd��n#1swxYwYtj|dztj
��tj|dztj
��tj|tj
tjz��tj|d��5}|�t|�	����t|j
����|���ddd��n#1swxYwYddd��dS#1swxYwYdS)Nr�rtrr	rG)r�temp_dirrr��joinr$r%r&r'r(r)�chmodr5�S_IRUSR�S_IXUSRrxr3)r+�dir�fnamer,r-s     r�test_readonly_filesz#DumbDBMTestCase.test_readonly_files
s$��
�
�
!�
!�	�S��G�L�L��d�+�+�E���e�S�)�)�
-�Q�� � ��a�f�f�h�h����4�4�4��:�-�-�C�!�Z��_�A�c�F�F�-�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-����
-�
-�
-�
-�
�H�U�V�^�T�\�2�2�2��H�U�V�^�T�\�2�2�2��H�S�$�,�t�|�3�4�4�4���e�S�)�)�
�Q�� � �������!1�!1�6�$�*�3E�3E�F�F�F����	�	�	�
�
�
�
�
�
�
�
�
�
�
����
�
�
�
�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s\�6F7�
AB'�F7�'B+	�+F7�.B+	�/BF7�7AF�F7�F#	�#F7�&F#	�'F7�7F;�>F;z*requires OS support of non-ASCII encodingsc���tj}dD]%}|�tj||z���&t	j|d��5}d|d<ddd��n#1swxYwY|�tj�	|dz����|�tj�	|dz����t	j|d��5}|�
t|�����dg��|�d|v��|�
|dd��ddd��dS#1swxYwYdS)Nrr!svalueskeyr	rrG)
r�TESTFN_NONASCII�
addCleanuprr$r%�
assertTruerr�r�r&r'r()r+�filename�suffixr�s    r�test_nonascii_filenamez&DumbDBMTestCase.test_nonascii_filenames����,��.�	A�	A�F��O�O�I�,�h��.?�@�@�@�@�
�\�(�C�
(�
(�	"�B�!�B�v�J�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"����	"�	"�	"�	"��������x�&�'8�9�9�:�:�:��������x�&�'8�9�9�:�:�:�
�\�(�C�
(�
(�	3�B����T�"�'�'�)�)�_�_�v�h�7�7�7��O�O�F�b�L�)�)�)����R��Z��2�2�2�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3����	3�	3�	3�	3�	3�	3s%�
A�A �#A �&A*E�E!�$E!c��tjtjt��d�����dSr )r$r%r�FakePathr
r3�r+s r�test_open_with_pathlib_pathz+DumbDBMTestCase.test_open_with_pathlib_path+s1����Y�'��/�/��5�5�;�;�=�=�=�=�=rc��tjtjt��d�����dSr )r$r%r�fsencoder
r3r�s r�test_open_with_bytes_pathz)DumbDBMTestCase.test_open_with_bytes_path.s0����R�[��(�(�#�.�.�4�4�6�6�6�6�6rc��tjtjt	jt����d�����dSr )r$r%rr�rr�r
r3r�s r�!test_open_with_pathlib_bytes_pathz1DumbDBMTestCase.test_open_with_pathlib_bytes_path1s;����Y�'���F�(;�(;�<�<�c�B�B�H�H�J�J�J�J�Jrc�"�t��dSrQ�rr�s r�tearDownzDumbDBMTestCase.tearDown4��������rc�"�t��dSrQr�r�s r�setUpzDumbDBMTestCase.setUp7r�rN))�__name__�
__module__�__qualname__r]r)r.�unittest�
skipUnless�hasattrrr�skip_unless_working_chmodr;r>rErOrSrXr[r^rbrpr*rCrRr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��rrrrs�������
�3�
�:�
�>�
�6�
�6�
�8�
�;�
�_�_�W�
%�
%��
�E� � � ��X�����W�-�-�/F�G�G��(�B�B�)�(�H�G�B�(���0�0�0����"'�'�'�
#�#�#�
1�1�1�P�P�P�
	,�	,�	,�-�-�-�,6�6�6�
%�%�%�
���0�0�0�,���C�C�C�,+�+�+�4�4�4�>�>�>�>�>�>�+�+�+��(���)�(���X���2�E�G�G�3�3�G�G�3�>�>�>�7�7�7�K�K�K��������rr�__main__)�__doc__r"rir�rr5r��dbm.dumb�dumbr$r�r�test.supportr�	functoolsr�TESTFNr
r�TestCaserr��mainr�rr�<module>r�s��������	�	�	�	�����	�	�	�	���������������������"�"�"�"�"�"�������	�	�����^�^�^�^�^�h�'�^�^�^�B	�z����H�M�O�O�O�O�O��r