
    xKg                        d Z ddlZddlmZ ddlmZ ddlZ	 ddlZ eej                  j                  dd      d         Zdd	lmZ dd
lmZmZmZ ddlmZmZ  e ee      j0                  dz  dz        ZdZdZddddZddddddZej=                         ZejA                  e       ejB                  d        Z"d Z#d Z$d Z%ejL                  jO                  d e(ejS                                e(ejU                                     d        Z+ejL                  jO                  d e(ejS                                e(ejU                                     d         Z,ejL                  jO                  d e(ejS                                e(ejU                                     d!        Z-d" Z.ejL                  jO                  d e(ejS                                e(ejU                                     d#        Z/y# e$ r dZdZY w xY w)$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                 "    t        t        |       S )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    [/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/pooch/tests/test_hashes.pydata_dir_mirrorr$   :   s     Hh//    c                 6   t        d      }|j                          	 t        | |j                  d       t	        |j                  d      5 }|j                         }ddd       t        k(  sJ t        | di       }|j                  |j                         t        | d	z        }|j                  d	      }||k(  sJ t        |       t        j                  |j                         y# 1 sw Y   xY w# t        j                  |j                         w xY w)
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 ow||uE',,1Tyy{H 28###3CbQ',,'?_45		/*u}}
		',, 21 			',,s$   /C7 C+A-C7 +C40C7 7!Dc                    t        d      }|j                          	 t        | |j                  d       t	        |j                  d      5 }|j                         }ddd       t        k(  sJ t        | di 	      }|j                  |j                         t        | d
z        |j                  d
      k(  sJ t        |j                  d
             t        | dz  d
z        }||j                  d      k(  sJ t        |j                  d             t        j                  |j                         y# 1 sw Y   xY w# t        j                  |j                         w xY w)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 ow||tD',,1Tyy{H 2----3CbQ',,'?_45?9SSSS		/23?X-?@syy!78888		"89:
		',, 21 			',,s$   /E D7B9E 7E <E !E$c                      t        j                  t              5 } t        dd       ddd       dt	         j
                        v sJ y# 1 sw Y   #xY w)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                 $   | j                  d      r=t        t        j                  d       | dvrt        dk  rt        j                  d       t
        j                  j                  t        d      }t        |       t        ||       }||k(  sJ y)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   sv     ~~e>KK)*((-AA-EKK/0GGLL?3EEeS)MM)))r%   c                 N   | j                  d      r=t        t        j                  d       | dvrt        dk  rt        j                  d       t
        j                  j                  t        d      }t        |       |  d| }t        ||      sJ |  d	}t        ||      rJ y)
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z***5&JE:....r%   c                    t         j                  j                  t        d      }t	        |       |  d| }t        ||d      sJ |  d}t        j                  t              5 }t        ||dd       ddd       dt        j                        v sJ t        j                  t              5 }t        ||dd       ddd       |t        |j                        v sJ y# 1 sw Y   mxY w# 1 sw Y   /xY w)	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z$777m$H	z	"eUHT+F 
##ekk****	z	"eUHT$? 
#C$$$$ 
#	" 
#	"s   %C!/C-!C*-C6c                      t         j                  j                  t        d      } t	        | d      sJ t	        dd      sJ t	        | dd      sJ y)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                 ^   t         j                  j                  t        d      }t	        |       |  d|j                          }t        ||d      sJ t        j                  t              5 }t        ||dd dd       ddd       dt        j                        v sJ y# 1 sw Y   #xY w)	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z$777	z	"eUJsODM 
##ekk**** 
#	"s   .B##B,)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: :	HH