
    dafP                        d Z 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 ej                  Z
ej                  j                  e
ej                        Zd Zd Zd Z G d	 d
      Z G d dej$                        Z e       D ]S  Zej*                  j-                  d      sJ ej*                  dd Zde Z eeeej$                  fdei       e       e<   U edk(  r ej6                          yy# e$ r dZY w xY w)z=Test script for the dbm.open function based on testdumbdbm.py    N)import_helper)	os_helper)ndbmc               #      K   t         j                  D ](  } 	 t        | dg      }|t         j                  | <   | * y # t        $ r Y 7w xY ww)Nopen)fromlist)dbm_names
__import__ImportError_modules)namemods     (/root/Python-3.12.4/Lib/test/test_dbm.pydbm_iteratorr      sT     

 	TVH5C !T	  		s%   A?A	AA
AAc                  6    t        j                  t               y N)r   rmtreedirname     r   cleaunup_test_dirr       s    Wr   c                  J    t                t        j                  t               y r   )r   osmkdirr   r   r   r   setup_test_dirr   #   s    HHW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y)AnyDBMTestCase   Python:s   Programmings   thes   ways   Guidos   intended)abcdfgc                     t        j                  t        d      }| j                  D ]#  }| j                  |   ||j	                  d      <   % |j                          y )Nnascii)r	   r   _fname_dictencodeclose)selfr$   ks      r   init_dbzAnyDBMTestCase.init_db1   sI    HHVS! 	1A#'::a=Aahhw 	1		r   c                     t        d |j                         D              }t        | j                  j                               }| j                  ||       |S )Nc              3   >   K   | ]  }|j                  d         yw)r(   N)decode).0r.   s     r   	<genexpr>z-AnyDBMTestCase.keys_helper.<locals>.<genexpr>8   s     :Aahhw':s   )sortedkeysr*   assertEqual)r-   r$   r6   dkeyss       r   keys_helperzAnyDBMTestCase.keys_helper7   sB    :::tzz()u%r   c                 j    | j                  t        | j                  j                  t                     y r   )
assertTrue
issubclassmoduleerrorOSErrorr-   s    r   
test_errorzAnyDBMTestCase.test_error=   s    
4;;#4#4g>?r   c                 j    | j                  t        j                  t        j                  t               y r   )assertRaisesr	   r>   r   r)   r@   s    r   test_anydbm_not_existingz'AnyDBMTestCase.test_anydbm_not_existing@   s    #))SXXv6r   c                 0   t        j                  t        d      }| j                  t	        |j                               g        | j                  D ]#  }| j                  |   ||j                  d      <   % | j                  |       |j                          y )Nr"   r(   )
r	   r   r)   r7   listr6   r*   r+   read_helperr,   r-   r$   keys      r   test_anydbm_creationz#AnyDBMTestCase.test_anydbm_creationC   sq    HHVS!affh,:: 	5C%)ZZ_Acjj!"	5		r   c                     t        j                  t               t        j                  t        d      5 }| j                  t        |      d       d d d        y # 1 sw Y   y xY w)Nr'   r   )r   create_empty_filer)   r	   r   r7   lenr-   r$   s     r   8test_anydbm_creation_n_file_exists_with_invalid_contentszGAnyDBMTestCase.test_anydbm_creation_n_file_exists_with_invalid_contentsK   sI    ##F+XXfc" 	(aSVQ'	( 	( 	(s   AA"c                 0   | j                          t        j                  t        d      }dx| j                  d<   |d<   | j                  |       | j                  |j                  dd      d       | j                  |d   d       |j                          y )Nr"   s   indentedr%      g   xxx   foo)	r/   r	   r   r)   r*   rG   r7   
setdefaultr,   rN   s     r   test_anydbm_modificationz'AnyDBMTestCase.test_anydbm_modificationQ   sw    HHVS!$//

3!D'ff5v>6F+		r   c                    | j                          t        j                  t        d      }| j	                  |       | j                  |j                  d      | j                  d          | j                  |j                  dd      d       | j                  |j                  d             | j                  t              5  |d    d d d        |j                          y # 1 sw Y   xY w)Nr   ar    rR   rS   )r/   r	   r   r)   rG   r7   getr*   assertIsNonerC   KeyErrorr,   rN   s     r   test_anydbm_readzAnyDBMTestCase.test_anydbm_read[   s    HHVS!tdjjo6vv.7!%%-(x( 	fI				 	s   C  C)c                     | j                          t        j                  t        d      }| j	                  |      }|j                          y )NrW   )r/   r	   r   r)   r9   r,   )r-   r$   r6   s      r   test_anydbm_keyszAnyDBMTestCase.test_anydbm_keysg   s4    HHVS!"		r   c                    t        t        j                  dd       dk(  r| j                  d       t        j                  t
        d      }| j                  |j                         g        d|d<   | j                  |j                         dg       | j                  d|       | j                  |d   d       | j                  |j                  d      d       | j                  |j                  d      d       |j                          y )NlibraryzBerkeley DBzCBerkeley DB doesn't distinguish the empty value from the absent oner"   r   s   empty)getattrr	   _defaultmodskipTestr   r)   r7   r6   assertInrY   rT   r,   rN   s     r   test_empty_valuezAnyDBMTestCase.test_empty_valuem   s    3??It4EMM 0 1HHVS!2&(H:.h"8c*x#.h/5		r   c                     | j                          t        j                  t        d      }dj	                  d      }| j                  ||       ||   dk(  sJ |j                          y )NrW   r    r(   r   )r/   r	   r   r)   r+   rd   r,   rH   s      r   test_anydbm_accessz!AnyDBMTestCase.test_anydbm_access{   sR    HHVS!jj!c1v#$#		r   c                 z    t        j                  t        j                  t              d      j                          y Nr"   )r	   r   r   fsencoder)   r,   r@   s    r   test_open_with_bytesz#AnyDBMTestCase.test_open_with_bytes   s"    V$c*002r   c                 z    t        j                  t        j                  t              d      j                          y ri   )r	   r   r   FakePathr)   r,   r@   s    r   test_open_with_pathlib_pathz*AnyDBMTestCase.test_open_with_pathlib_path   s$    ##F+S1779r   c                     t        j                  t        j                  t	        j
                  t                    d      j                          y ri   )r	   r   r   rm   r   rj   r)   r,   r@   s    r   !test_open_with_pathlib_path_bytesz0AnyDBMTestCase.test_open_with_pathlib_path_bytes   s-    ##BKK$78#>DDFr   c                     | j                  |      }| j                  D ]3  }| j                  | j                  |   ||j                  d                5 y )Nr(   )r9   r*   r7   r+   )r-   r$   r6   rI   s       r   rG   zAnyDBMTestCase.read_helper   sM    ":: 	FCTZZ_a

70C.DE	Fr   c                    t        j                  t        d      5 | j                  j	                         g        ddg}|D ]
  \  }}||<    | j                  t        j	                               t        d |D                     |D ],  \  }}| j                  |       | j                  |   |       . | j                  d       | j                  t        fd       d d d        y # 1 sw Y   y xY w)Nr"   )rX      b)s   12345678910s   019237410982340912840198242c              3   &   K   | ]	  \  }}|  y wr   r   )r3   r.   vs      r   r4   z+AnyDBMTestCase.test_keys.<locals>.<genexpr>   s     5HFQa5Hs   rR   c                       d   S )NrR   r   )r#   s   r   <lambda>z*AnyDBMTestCase.test_keys.<locals>.<lambda>   s    &	 r   )
r	   r   r)   r7   r6   r5   rd   assertNotInrC   r[   )r-   r    r.   ru   r#   s       @r   	test_keyszAnyDBMTestCase.test_keys   s    XXfc" 
	;aQVVXr*OPA 1!VAFFH-v5Ha5H/HI *1a#  1q)* VQ'h(9:
	; 
	; 
	;s   C	C..C7c                     | j                  t        t        dt        j                         | j                  t        _        | j                  t
               t                y )Nrb   )
addCleanupsetattrr	   rb   r=   r   r   r@   s    r   setUpzAnyDBMTestCase.setUp   s6    mS__E++)*r   N)__name__
__module____qualname__r*   r/   r9   rA   rD   rJ   rO   rU   r\   r^   re   rg   rk   rn   rp   rG   ry   r}   r   r   r   r   r   (   ss     E@7(
3:GF
;r   r   c                   L    e Zd Zd Z ej
                  ed      d        Zd Zy)WhichDBTestCasec                    | j                  t        t        dt        j                         t	        j
                  t              }t        t        j                  t              |t        j                  |      g}t               D ]  }|j                  }t                |t        _        |j                  t        d      5  d d d        |D ]-  }| j                  || j                  j                  |             / |j                  t        d      5 }d|d<   | j                  d|       | j                  |d   d       d d d        |D ]-  }| j                  || j                  j                  |             /  y # 1 sw Y   xY w# 1 sw Y   JxY w)Nrb   r"   w   1)r{   r|   r	   rb   r   rj   r)   r   rm   r   r~   r   r   r7   whichdbrd   )r-   _bytes_fnamefnamesr=   r   pathr$   s          r   test_whichdbzWhichDBTestCase.test_whichdb   sD   mS__E{{6*),,V4	 2 2< @B"n 	?F ??D$COVS)// ?  txx'7'7'=>? VS) 0Q$dA&  4$/0  ?  txx'7'7'=>?#	? 0/0 0s   <E7-F7F 	F	zTest requires ndbm)reasonc                 P   t        t        dz   d      5  d d d        t        j                  t              }t        t	        j
                  t              |t	        j
                  |      g}|D ],  }| j                  | j                  j                  |             . y # 1 sw Y   xY w)Nz.dbwb)	r   r)   r   rj   r   rm   rZ   r	   r   )r-   r   r   r   s       r   test_whichdb_ndbmz!WhichDBTestCase.test_whichdb_ndbm   s     &5.$'--{{6*),,V4	 2 2< @B 	6Ddhh..t45	6	 	.-s   BB%c                 v    | j                  t               t                t        j                  d      | _        y )Nr	   )r{   r   r   r   import_fresh_moduler	   r@   s    r   r}   zWhichDBTestCase.setUp   s'    )* 44U;r   N)	r~   r   r   r   unittest
skipUnlessr   r   r}   r   r   r   r   r      s0    ?2 X&:;6 <6<r   r   zdbm.   	TestCase_r=   __main__)__doc__r   r	   r   test.supportr   r   r   r   TESTFNr   r   joinr)   r   r   r   r   TestCaser   r   r~   
startswithsuffixtestnametypeglobalsmainr   r   r   <module>r      s   C  
 	 & " 

	gy//	0

z zz'<h'' '<T > 0C<<""6***\\!"F6(#Hx .0A0AB (#0GIh	0 zHMMO [  Ds   C1 1C;:C;