
    ;eJ                         d dl mZ d dlmZmZ  ej        d          Zd dlZd dlZd dl	m
Z
mZmZmZ e
Z G d dej                  Zedk    r ej                     dS dS )	    )support)import_helpercpython_onlyzdbm.gnuN)TESTFNTESTFN_NONASCIIunlinkFakePathc                       e Zd Zed             Zd Zd Zed             Zd Z	d Z
d Zd Zd	 Zd
 Zd Zd Z ej        ed          d             Zd Zd Zd Zd ZdS )TestGdbmc                  v    t           j        r,	 ddlm}  t	          d|             d S # t
          $ r Y d S w xY wd S )Nr   )_GDBM_VERSIONzgdbm version: )r   verbose_gdbmr   printImportError)versions    (/usr/lib/python3.11/test/test_dbm_gnu.py
setUpClasszTestGdbm.setUpClass   sp    ? 	22:::::: 0w0011111    	2 	2s   ( 
66c                     d | _         d S Ngselfs    r   setUpzTestGdbm.setUp   s        c                 n    | j         | j                                          t          t                     d S r   )r   closer   filenamer   s    r   tearDownzTestGdbm.tearDown   s-    6FLLNNNxr   c                     t                               t          d          | _        t	          j        | t          | j                             d S Nc)gdbmopenr   r   r   check_disallow_instantiationtyper   s    r   test_disallow_instantiationz$TestGdbm.test_disallow_instantiation   s:     8S)),T4<<@@@@@r   c                     t                               t          d          | _        |                     | j                                        g            d| j        d<   d| j        d<   d| j        d<   t          | j                                                  }|                     |t          g d                     |                     d| j                   |                     d	| j                   |                     | j        d         d           | j                                        }|rG|                     ||           |	                    |           | j        
                    |          }|G|                     | j                            d	          d
           |                     | j                            d                     |                     | j                            dd          d           |                     t                    5  | j        d          d d d            n# 1 swxY w Y   |                     | j                            dd          d           |                     | j        d         d           d S )Nr#   ba01923741098234091284019824212345678910s   data   bytes)   ar.   s   12345678910r/      bs   xxxs   fooxxx)r$   r%   r   r   assertEqualkeyssetassertInfirstkeyremovenextkeygetassertIsNoneassertRaisesKeyError
setdefault)r   key_setkeys      r   test_key_methodszTestGdbm.test_key_methods$   sg   8S))+++s =}"xdfkkmm$$#&F&F&F"G"GHHHc46"""dDF###)7333foo 	&MM#w'''NN3&..%%C  	&
 	D))4000$&**V,,---FF33V<<<x(( 	 	F5MM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	**66::FCCC00000s   H33H7:H7c                     t          t                                          t          j        t          j        t          d           t                              t          d           _         j                                                              t          j         fd                                t          j        d            d S )Nrr#   c                       j         d         S )Nr+   r   r   s   r   <lambda>z0TestGdbm.test_error_conditions.<locals>.<lambda>D   s    dfSk r   c                  f    t                               t          d                                          S )Nrx)r$   r%   r   r    r   r   rD   z0TestGdbm.test_error_conditions.<locals>.<lambda>F   s     dii$.G.G.M.M.O.O r   )r   r   r;   r$   errorr%   r   r   r   s   `r   test_error_conditionszTestGdbm.test_error_conditions=   s    x$*di3???8S))$*&9&9&9&9:::$*&O&OPPPPPr   c                    t          t          j                  }|t          d          z
  }t          |          D ]@}t                              t
          |          | _        | j                                         A|t          d          z
  }|D ]H}|D ]C}t                              t
          ||z             | _        | j                                         DId S )Nfsucrwn)r4   r$   
open_flagssortedr%   r   r   r   )r   allmodesmodeflagsflags         r   
test_flagszTestGdbm.test_flagsH   s    $/""c%jj 5MM 	 	DYYx..DFFLLNNNN c&kk! 	 	D  8TD[99	 	r   c                    t                               t          d          | _        t          j                            t                    }t          |d          }d|z  | j        d<   t          j                            t                    }|                     ||           | j        d= | 	                    t          j                            t                    |           | j        
                                 t          j                            t                    }|                     ||           |                     ||           d S )Nr#   i'  x)r$   r%   r   r   ospathgetsizemaxassertGreaterr2   
reorganize
assertLessassertGreaterEqual)r   size0
value_sizesize1size2s        r   test_reorganizezTestGdbm.test_reorganizeX   s    8S))))
 &&
J&s))5%(((F3K22E:::))u%%%u-----r   c                 B   t                               t          d          5 }d|d<   d d d            n# 1 swxY w Y   t                               t          d          5 }|                     t	          |                                          dg           d d d            n# 1 swxY w Y   |                     t           j                  5 }|                                 d d d            n# 1 swxY w Y   |                     t          |j	                  d           d S )Nr#   zcontext managerzgdbm context managerrB   s   gdbm context managerz#GDBM object has already been closed)
r$   r%   r   r2   listr3   r;   rH   str	exception)r   dbcms      r   test_context_managerzTestGdbm.test_context_managerm   s   YYx%% 	;):B%&	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; YYx%% 	IT"''))__/F.GHHH	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I tz** 	bGGIII	 	 	 	 	 	 	 	 	 	 	 	 	 	 	R\**>	@ 	@ 	@ 	@ 	@s0   3777B!!B%(B%C,,C03C0c                    t                               t          d          5 }d|d<   d d d            n# 1 swxY w Y   t                               t          d          5 }|                     t	          |                                          dg           |                     d|v            |                     |d         d           d d d            d S # 1 swxY w Y   d S )Nr#   s   bytes value s   bytes key rB   )r$   r%   r   r2   re   r3   
assertTruer   rh   s     r   
test_byteszTestGdbm.test_bytesy   sX   YYx%% 	8$7B !	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8YYx%% 	IT"''))__/@.ABBBOO-3444R 124GHHH	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	Is   377A*CCCc                    t                               t          d          5 }d|d<   d d d            n# 1 swxY w Y   t                               t          d          5 }|                     t	          |                                          d                                g           |                     d                                |v            |                     d|v            |                     |d                                         d                                           |                     |d         d                                           d d d            d S # 1 swxY w Y   d S )Nr#   u   Unicode value 🐍u   Unicode key 🐍rB   )r$   r%   r   r2   re   r3   encoderl   rm   s     r   test_unicodezTestGdbm.test_unicode   s   YYx%% 	F+EB'(	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	FYYx%% 	BT"''))__/G/N/N/P/P.QRRROO4;;==CDDDOO4:;;;R 8 ? ? A AB7>>@@B B BR 897>>@@B B B	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	Bs   377C7E""E&)E&c                 R   t                               t          d          5 }d|d<   d d d            n# 1 swxY w Y   t                               t          d          5 }|                     t           j                  5  |d= d d d            n# 1 swxY w Y   |                     t           j                  5  |d= d d d            n# 1 swxY w Y   |                     t           j                  5  d|d<   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr#   s   bytes values	   bytes keyrB   s   not exist keys   not exist value)r$   r%   r   r;   rH   rm   s     r   test_write_readonly_filez!TestGdbm.test_write_readonly_file   sD   YYx%% 	.-B|	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.YYx%% 	:""4:.. ) )'() ) ) ) ) ) ) ) ) ) ) ) ) ) )""4:.. % %|$% % % % % % % % % % % % % % %""4:.. : :'9#$: : : : : : : : : : : : : : :	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:s   377 D>BDB	DB	"D8C<DC	DC	"D2D8DD	DD	DD #D z*requires OS support of non-ASCII encodingsc                 X   t           }|                     t          |           t                              |d          5 }d|d<   d d d            n# 1 swxY w Y   |                     t          j                            |                     t                              |d          5 }| 	                    t          |                                          dg           |                     d|v            | 	                    |d         d           d d d            d S # 1 swxY w Y   d S )Nr#   s   values   keyrB   )r   
addCleanupr   r$   r%   rl   rW   rX   existsr2   re   r3   )r   r   rh   s      r   test_nonascii_filenamezTestGdbm.test_nonascii_filename   sw    #)))YYx%% 	"!BvJ	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"x00111YYx%% 	3T"''))__vh777OOFbL)))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*DD#&D#c                 <   d}|                      t          j                  5 }t                              |           d d d            n# 1 swxY w Y   |                     |t          |j                             |                     |j        j        |           d S )Nznonexisting-file)	r;   r$   rH   r%   r5   rf   rg   r2   r   )r   nonexisting_fileri   s      r   test_nonexisting_filezTestGdbm.test_nonexisting_file   s    -tz** 	(bII&'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(&BL(9(9:::.0@AAAAAs   A		AAc                     t                               t          t                    d                                           d S r"   )r$   r%   r	   r   r   r   s    r   test_open_with_pathlib_pathz$TestGdbm.test_open_with_pathlib_path   s0    		(8$$c**0022222r   c                     t                               t          j        t                    d                                           d S r"   )r$   r%   rW   fsencoder   r   r   s    r   test_open_with_bytes_pathz"TestGdbm.test_open_with_bytes_path   s2    		"+h''--3355555r   c                     t                               t          t          j        t
                              d                                           d S r"   )r$   r%   r	   rW   r~   r   r   r   s    r   !test_open_with_pathlib_bytes_pathz*TestGdbm.test_open_with_pathlib_bytes_path   s:    		(2;x0011377==?????r   N)__name__
__module____qualname__staticmethodr   r   r    r   r(   r@   rI   rT   rc   rj   rn   rq   rs   unittest
skipUnlessr   rw   rz   r|   r   r   rG   r   r   r   r      sg       2 2 \2    
 A A \A
1 1 12	Q 	Q 	Q   . . .*
@ 
@ 
@I I I
B 
B 
B	: 	: 	: XEG G	3 	3G G	3B B B3 3 36 6 6@ @ @ @ @r   r   __main__)testr   test.supportr   r   import_moduler$   r   rW   test.support.os_helperr   r   r   r	   r   TestCaser   r   mainrG   r   r   <module>r      s          4 4 4 4 4 4 4 4"}"9--  				 L L L L L L L L L L L L h@ h@ h@ h@ h@x  h@ h@ h@V zHMOOOOO r   