
     
3j                        S r SSKrSSKJr  SSKJr  SSKr SSKr\" \R                  R                  SSS9S   5      rSS	KJr  SS
KJrJrJr  SSKJrJr  \" \" \5      R0                  S-  S-  5      rSrSrSSSS.rSSSSSS.r\R=                  5       r\RA                  \5        \RB                  S 5       r"S r#S r$S r%\RL                  RO                  S\(" \RS                  5       5      \(" \RU                  5       5      S9S 5       r+\RL                  RO                  S\(" \RS                  5       5      \(" \RU                  5       5      S9S  5       r,\RL                  RO                  S\(" \RS                  5       5      \(" \RU                  5       5      S9S! 5       r-S" r.\RL                  RO                  S\(" \RS                  5       5      \(" \RU                  5       5      S9S# 5       r/g! \ a    SrSr GNf = f)$z3
Test the hash calculation and checking functions.
    N)Path)NamedTemporaryFile.   )maxsplit   )Pooch)make_registry	file_hashhash_matches)check_tiny_datamirror_directorydatastorezOtiny-data.txt baee0894dba14b12085eacb204284b97e362f4f3e5a5807693cc90ef415c1b2d
zsubdir/tiny-data.txt baee0894dba14b12085eacb204284b97e362f4f3e5a5807693cc90ef415c1b2d
tiny-data.txt baee0894dba14b12085eacb204284b97e362f4f3e5a5807693cc90ef415c1b2d
(c03148994acd89317915ea2f2d080d6dd127aa09@baee0894dba14b12085eacb204284b97e362f4f3e5a5807693cc90ef415c1b2d 70e2afd3fd7e336ae478b1e740a5f08e)sha1sha256md5f843815fe57948fa98d6f1a2 0267d220db258fffb0c567c0ecd1b689811e3f2a12aec53f)xxh64xxh32xxh128xxh3_128xxh3_64c                 "    [        [        U 5      $ )z
Mirror the test data folder on a temporary directory. Needed to avoid
permission errors when pooch is installed on a non-writable path.
)r   DATA_DIR)tmp_paths    Q/home/wildlama/miniconda3/lib/python3.13/site-packages/pooch/tests/test_hashes.pydata_dir_mirrorr$   :   s     Hh//    c                 ,   [        SS9nUR                  5          [        XR                  SS9  [	        UR                  SS9 nUR                  5       nSSS5        W[        :X  d   e[        U S0 S9nUR                  UR                  5        [        U S	-  5      nUR                  S	5      nXV:X  d   e[        U5        [        R                  " UR                  5        g! , (       d  f       N= f! [        R                  " UR                  5        f = f)
zGCheck that the registry builder creates the right file names and hashesFdelete	recursiveutf-8encodingNsome bogus URLpathbase_urlregistrytiny-data.txt)r   closer
   nameopenreadREGISTRYr	   load_registrystrfetchr   osremove)r$   outfilefoutr2   puptruefnames          r#   test_make_registryrC   C   s     .GMMO o||uE',,1Tyy{H 28###3CbQ',,'?_45		/*}}
		',, 21 			',,s$   (C1 C A+C1  
C.*C1 1"Dc                    [        SS9nUR                  5          [        XR                  SS9  [	        UR                  SS9 nUR                  5       nSSS5        W[        :X  d   e[        U S0 S	9nUR                  UR                  5        [        U S
-  5      UR                  S
5      :X  d   e[        UR                  S
5      5        [        U S-  S
-  5      nXTR                  S5      :X  d   e[        UR                  S5      5        [        R                  " UR                  5        g! , (       d  f       N= f! [        R                  " UR                  5        f = f)z7Check that the registry builder works in recursive modeFr'   Tr)   r+   r,   Nr.   r/   r3   subdirzsubdir/tiny-data.txt)r   r4   r
   r5   r6   r7   REGISTRY_RECURSIVEr	   r9   r:   r;   r   r<   r=   )r$   r>   r?   r2   r@   rA   s         r#   test_make_registry_recursiverG   X   s    .GMMO o||tD',,1Tyy{H 2----3CbQ',,'?_45?9SSSS		/23?X-?@yy!78888		"89:
		',, 21 			',,s$   (D> D-B8D> -
D;7D> >"E c                      [         R                  " [        5       n [        SSS9  SSS5        S[	        W R
                  5      ;   d   eg! , (       d  f       N*= f)z!Test an invalid hashing algorithm	somethingblah)rB   algNz'blah')pytestraises
ValueErrorr   r:   value)excs    r#    test_file_hash_invalid_algorithmrQ   n   s>    	z	"c0 
#s399~%%% 
#	"s   A


Azalg,expected_hash)idsc                 8   U R                  S5      (       aC  [        c  [        R                  " S5        U S;  a   [        S:  a  [        R                  " S5        [
        R                  R                  [        S5      n[        U5        [        X 5      nX1:X  d   eg)z2Test the hash calculation using hashlib and xxhashxxhNrequires xxhashr   r   r   requires xxhash > 2.0r3   )
startswithxxhashrL   skipXXHASH_MAJOR_VERSIONr<   r0   joinr!   r   r   )rK   expected_hashrB   returned_hashs       r#   test_file_hashr_   u   su     ~~e>KK)*((-AA-EKK/0GGLL?3EEe)M)))r%   c                 t   U R                  S5      (       aC  [        c  [        R                  " S5        U S;  a   [        S:  a  [        R                  " S5        [
        R                  R                  [        S5      n[        U5        U  SU 3n[        X#5      (       d   eU  S	3n[        X#5      (       a   eg)
z*Make sure the hash checking function worksrT   NrU   rV   r   rW   r3   ::blablablabla)rX   rY   rL   rZ   r[   r<   r0   r\   r!   r   r   )rK   r]   rB   
known_hashs       r#   test_hash_matchesrd      s     ~~e>KK)*((-AA-EKK/0GGLL?3EE5-)J****5&JE.....r%   c                    [         R                  R                  [        S5      n[	        U5        U  SU 3n[        X#SS9(       d   eU  S3n[        R                  " [        5       n[        X$SSS9  SSS5        S[        WR                  5      ;   d   e[        R                  " [        5       n[        X$SSS9  SSS5        U[        UR                  5      ;   d   eg! , (       d  f       Ns= f! , (       d  f       N;= f)	zBMake sure the hash checking function raises an exception if strictr3   ra   Tstrictrb   	Neverlandrg   sourceN)r<   r0   r\   r!   r   r   rL   rM   rN   r:   rO   )rK   r]   rB   rc   bad_hasherrors         r#   test_hash_matches_strictrm      s     GGLL?3EE5-)J$777m$H	z	"eUT+F 
##ekk****	z	"eUT$? 
#C$$$$ 
#	" 
#	"s   'C 0C1 
C.1
C?c                      [         R                  R                  [        S5      n [	        U SS9(       d   e[	        SSS9(       d   e[	        U SSS9(       d   eg)zHThe hash checking function should always returns True if known_hash=Noner3   N)rc    )rB   rc   T)rc   rg   )r<   r0   r\   r!   r   )rB   s    r#   test_hash_matches_nonerp      sH    GGLL?3E$///bT222$t<<<r%   c                 h   [         R                  R                  [        S5      n[	        U5        U  SUR                  5        3n[        X#SS9(       d   e[        R                  " [        5       n[        X#SS SSS9  SSS5        S[        WR                  5      ;   d   eg! , (       d  f       N*= f)	z:Hash matching should be independent of upper or lower caser3   ra   Trf   Nrh   ri   )r<   r0   r\   r!   r   upperr   rL   rM   rN   r:   rO   )rK   r]   rB   rc   rl   s        r#   test_hash_matches_uppercasert      s     GGLL?3EE5---/01J$777	z	"eUsODM 
##ekk**** 
#	"s   0B##
B1)0__doc__r<   pathlibr   tempfiler   rL   rY   intVERSIONsplitr[   ImportErrorcorer	   hashesr
   r   r   utilsr   r   r:   __file__parentr!   r8   rF   TINY_DATA_HASHES_HASHLIBTINY_DATA_HASHES_XXHcopyTINY_DATA_HASHESupdatefixturer$   rC   rG   rQ   markparametrizelistitemskeysr_   rd   rm   rp   rt    r%   r#   <module>r      sZ   
  ' v~~33C!3DQGH
  
 5tH~$$v-78V 	W 
 7P-   02!  ,002    , - 0 0 * ,& 				!"""$%  

*

* 				!"""$%  
/
/" 	!	'	'	)*%**,-  
%
%"= 	!	'	'	)*%**,-  

+

+[  Fs   'G+ +
G98G9