
    ;eP                        	 d dl Z d dlZd dlZd dlmZ d dlmZ 	 d dlmZ n# e$ r dZY nw xY wej        Z	ej
                            e	ej                  Zd Zd Zd Z G d d	          Z G d
 de j                  Z e            D ]7Zej        dd         Zde Z eeee j        fdei           e            e<   8edk    r e j                     dS dS )    N)import_helper)	os_helper)ndbmc               #      K   t           j        D ]9} 	 t          | dg          }n# t          $ r Y "w xY w|t           j        | <   |V  :d S )Nopen)fromlist)dbm_names
__import__ImportError_modules)namemods     $/usr/lib/python3.11/test/test_dbm.pydbm_iteratorr      ss      
  	TVH555CC 	 	 	H	 T				 s   %
22c                  8    t          j        t                     d S N)r   rmtreedirname     r   cleaunup_test_dirr       s    Wr   c                  T    t                       t          j        t                     d S r   )r   osmkdirr   r   r   r   setup_test_dirr   #   s$    HWr   c                       e Zd ZdddddddZd Zd	 Zd
 Zd Zd Zd Z	d Z
d Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )AnyDBMTestCases   Python:s   Programmings   thes   ways   Guidos   intended)abcdfgc                     t          j        t          d          }| j        D ]%}| j        |         ||                    d          <   &|                                 d S )Nnascii)r	   r   _fname_dictencodeclose)selfr#   ks      r   init_dbzAnyDBMTestCase.init_db1   sT    HVS!! 	1 	1A#':a=Aahhw  						r   c                     t          d |                                D                       }t          | j                                                  }|                     ||           |S )Nc              3   @   K   | ]}|                     d           V  dS )r'   N)decode).0r-   s     r   	<genexpr>z-AnyDBMTestCase.keys_helper.<locals>.<genexpr>8   s.      ::Aahhw''::::::r   )sortedkeysr)   assertEqual)r,   r#   r5   dkeyss       r   keys_helperzAnyDBMTestCase.keys_helper7   sZ    :::::::tz(())u%%%r   c                 j    |                      t          | j        j        t                               d S r   )
assertTrue
issubclassmoduleerrorOSErrorr,   s    r   
test_errorzAnyDBMTestCase.test_error=   s)    
4;#4g>>?????r   c                 f    |                      t          j        t          j        t                     d S r   )assertRaisesr	   r=   r   r(   r?   s    r   test_anydbm_not_existingz'AnyDBMTestCase.test_anydbm_not_existing@   s$    #)SXv66666r   c                 P   t          j        t          d          }|                     t	          |                                          g            | j        D ]%}| j        |         ||                    d          <   &|                     |           |	                                 d S )Nr!   r'   )
r	   r   r(   r6   listr5   r)   r*   read_helperr+   r,   r#   keys      r   test_anydbm_creationz#AnyDBMTestCase.test_anydbm_creationC   s    HVS!!affhh,,,: 	5 	5C%)Z_Acjj!!""						r   c                     t          j        t                     t          j        t          d          5 }|                     t          |          d           d d d            d S # 1 swxY w Y   d S )Nr&   r   )r   create_empty_filer(   r	   r   r6   lenr,   r#   s     r   8test_anydbm_creation_n_file_exists_with_invalid_contentszGAnyDBMTestCase.test_anydbm_creation_n_file_exists_with_invalid_contentsK   s    #F+++Xfc"" 	(aSVVQ'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s   $A%%A),A)c                 ^   |                                   t          j        t          d          }dx| j        d<   |d<   |                     |           |                     |                    dd          d           |                     |d         d           |                                 d S )Nr!   s   indentedr$      g   xxx   foo)	r.   r	   r   r(   r)   rF   r6   
setdefaultr+   rM   s     r   test_anydbm_modificationz'AnyDBMTestCase.test_anydbm_modificationQ   s    HVS!!$//
3!D'ff55v>>>6F+++						r   c                 4   |                                   t          j        t          d          }|                     |           |                     |                    d          | j        d                    |                     |                    dd          d           |                     |                    d                     | 	                    t                    5  |d          d d d            n# 1 swxY w Y   |                                 d S )Nr   ar   rQ   rR   )r.   r	   r   r(   rF   r6   getr)   assertIsNonerB   KeyErrorr+   rM   s     r   test_anydbm_readzAnyDBMTestCase.test_anydbm_read[   s   HVS!!tdjo666vv..777!%%--(((x(( 	 	fII	 	 	 	 	 	 	 	 	 	 	 	 	 	 							s   $	C99C= C=c                     |                                   t          j        t          d          }|                     |          }|                                 d S )NrV   )r.   r	   r   r(   r8   r+   )r,   r#   r5   s      r   test_anydbm_keyszAnyDBMTestCase.test_anydbm_keysg   sD    HVS!!""						r   c                 ~   t          t          j        dd           dk    r|                     d           t          j        t
          d          }|                     |                                g            d|d<   |                     |                                dg           |                     d|           |                     |d         d           |                     |	                    d          d           |                     |
                    d          d           |                                 d S )NlibraryzBerkeley DBzCBerkeley DB doesn't distinguish the empty value from the absent oner!   r   s   empty)getattrr	   _defaultmodskipTestr   r(   r6   r5   assertInrX   rS   r+   rM   s     r   test_empty_valuezAnyDBMTestCase.test_empty_valuem   s   3?It44EEMM 0 1 1 1HVS!!2&&&(H:...h"""8c***x#...h//555						r   c                     |                                   t          j        t          d          }d                    d          }|                     ||           |                                 d S )NrV   r   r'   )r.   r	   r   r(   r*   rc   r+   rG   s      r   test_anydbm_accessz!AnyDBMTestCase.test_anydbm_access{   sV    HVS!!jj!!c1						r   c                     t          j        t          j        t                    d                                           d S Nr!   )r	   r   r   fsencoder(   r+   r?   s    r   test_open_with_bytesz#AnyDBMTestCase.test_open_with_bytes   s0    V$$c**0022222r   c                     t          j        t          j        t                    d                                           d S rh   )r	   r   r   FakePathr(   r+   r?   s    r   test_open_with_pathlib_pathz*AnyDBMTestCase.test_open_with_pathlib_path   s1    #F++S117799999r   c                     t          j        t          j        t	          j        t                              d                                           d S rh   )r	   r   r   rl   r   ri   r(   r+   r?   s    r   !test_open_with_pathlib_path_bytesz0AnyDBMTestCase.test_open_with_pathlib_path_bytes   s;    #BK$7$788#>>DDFFFFFr   c                     |                      |          }| j        D ]<}|                     | j        |         ||                    d                              =d S )Nr'   )r8   r)   r6   r*   )r,   r#   r5   rH   s       r   rF   zAnyDBMTestCase.read_helper   sd    "": 	F 	FCTZ_a

70C0C.DEEEE	F 	Fr   c                 T   t          j        t          d          5 |                                                     g            ddg}|D ]
\  }}||<   |                     t                                                    t          d |D                                  |D ]7\  }}|                     |           |                     |         |           8|                     d           |                     t          fd           d d d            d S # 1 swxY w Y   d S )Nr!   )rW      b)s   12345678910s   019237410982340912840198242c              3       K   | ]	\  }}|V  
d S r   r   )r2   r-   vs      r   r3   z+AnyDBMTestCase.test_keys.<locals>.<genexpr>   s&      5H5HFQa5H5H5H5H5H5Hr   rQ   c                       d         S )NrQ   r   )r"   s   r   <lambda>z*AnyDBMTestCase.test_keys.<locals>.<lambda>   s    &	 r   )
r	   r   r(   r6   r5   r4   rc   assertNotInrB   rZ   )r,   r   r-   rt   r"   s       @r   	test_keyszAnyDBMTestCase.test_keys   st   Xfc"" 
	;aQVVXXr***OPA  1!VAFFHH--v5H5Ha5H5H5H/H/HIII * *1a###  1q))))VQ'''h(9(9(9(9:::
	; 
	; 
	; 
	; 
	; 
	; 
	; 
	; 
	; 
	; 
	; 
	; 
	; 
	; 
	; 
	; 
	; 
	;s   C4DD!$D!c                     |                      t          t          dt          j                   | j        t          _        |                      t
                     t                       d S )Nra   )
addCleanupsetattrr	   ra   r<   r   r   r?   s    r   setUpzAnyDBMTestCase.setUp   sJ    mS_EEE+)***r   N)__name__
__module____qualname__r)   r.   r8   r@   rC   rI   rN   rT   r[   r]   rd   rf   rj   rm   ro   rF   rx   r|   r   r   r   r   r   (   s:         E    @ @ @7 7 7  ( ( (  
 
 
      3 3 3: : :G G GF F F
; ; ;    r   r   c                   P    e Zd Zd Z ej        ed          d             Zd ZdS )WhichDBTestCasec                 f   |                      t          t          dt          j                   t	          j        t                    }t          t          j        t                    |t          j        |          g}t                      D ]'}|j
        }t                       |t          _        |                    t          d          5  d d d            n# 1 swxY w Y   |D ]0}|                     || j                            |                     1|                    t          d          5 }d|d<   |                     d|           |                     |d         d           d d d            n# 1 swxY w Y   |D ]0}|                     || j                            |                     1)d S )Nra   r!   w   1)rz   r{   r	   ra   r   ri   r(   r   rl   r   r}   r   r   r6   whichdbrc   )r,   _bytes_fnamefnamesr<   r   pathr#   s          r   test_whichdbzWhichDBTestCase.test_whichdb   s   mS_EEE{6**),V44	 2< @ @B"nn 	? 	?F ?D$COVS))///////////////// ? ?  tx'7'7'='=>>>>VS)) 0Q$dA&&&  4$///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0  ? ?  tx'7'7'='=>>>>?#	? 	?s$   CC	C	-8E11E5	8E5	zTest requires ndbm)reasonc                 d   t          t          dz   d          5  d d d            n# 1 swxY w Y   t          j        t                    }t          t	          j        t                    |t	          j        |          g}|D ]/}|                     | j                            |                     0d S )Nz.dbwb)	r   r(   r   ri   r   rl   rY   r	   r   )r,   r   r   r   s       r   test_whichdb_ndbmz!WhichDBTestCase.test_whichdb_ndbm   s     &5.$''-----------------{6**),V44	 2< @ @B 	6 	6Ddh..t445555	6 	6s   &**c                     |                      t                     t                       t          j        d          | _        d S )Nr	   )rz   r   r   r   import_fresh_moduler	   r?   s    r   r|   zWhichDBTestCase.setUp   s7    )*** 4U;;r   N)	r}   r~   r   r   unittest
skipUnlessr   r   r|   r   r   r   r   r      sa        ? ? ?2 X&:;;;6 6 <;6< < < < <r   r      	TestCase_r<   __main__)r   r	   r   test.supportr   r   r   r   TESTFNr   r   joinr(   r   r   r   r   TestCaser   r   r}   suffixtestnametypeglobalsmainr   r   r   <module>r      s   C  



 				 & & & & & & " " " " " "   DDD 
	gy/	0	0
      
z z z z z z z zz'< '< '< '< '<h' '< '< '<T <>> 0 0C\!""F#6##H$x .0AB (#0 0GGIIh
 zHMOOOOO s   " ,,