
    -Ph                        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	        
                    dd          d                   Zn# e$ r dZdZY nw xY wdd	lmZ dd
lmZmZmZ ddlmZmZ  e ee          j        dz  dz            ZdZdZddddZddddddZe                                Ze                     e           ej!        d             Z"d Z#d Z$d Z%ej&        '                    d e(e)                                           e(e*                                                    d             Z+ej&        '                    d e(e)                                           e(e*                                                    d              Z,ej&        '                    d e(e)                                           e(e*                                                    d!             Z-d" Z.ej&        '                    d e(e)                                           e(e*                                                    d#             Z/dS )$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    W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pooch/tests/test_hashes.pydata_dir_mirrorr$   :   s     Hh///    c                 ^   t          d          }|                                 	 t          | |j        d           t	          |j        d          5 }|                                }ddd           n# 1 swxY w Y   |t          k    sJ t          | di           }|                    |j                   t          | d	z            }|
                    d	          }||k    sJ t          |           t          j        |j                   dS # 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   sY    ...GMMOOO ow|uEEEE',111 	#Tyy{{H	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#8####3CbQQQ','''?_455		/**u}}}}
	',	',s0   -D A4(D 4A88D ;A8<A:D D,c                     t          d          }|                                 	 t          | |j        d           t	          |j        d          5 }|                                }ddd           n# 1 swxY w Y   |t          k    sJ t          | di 	          }|                    |j                   t          | d
z            |
                    d
          k    sJ t          |
                    d
                     t          | dz  d
z            }||
                    d          k    sJ t          |
                    d                     t          j        |j                   dS # 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MMOOO ow|tDDDD',111 	#Tyy{{H	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#-----3CbQQQ','''?_455?9S9SSSSS		/22333?X-?@@syy!7888888		"899:::
	',	',s0   -E2 A4(E2 4A88E2 ;A8<CE2 2Fc                      t          j        t                    5 } t          dd           ddd           n# 1 swxY w Y   dt	          | j                  v sJ dS )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	"	" 1c00001 1 1 1 1 1 1 1 1 1 1 1 1 1 1s39~~%%%%%%s   8<<zalg,expected_hash)idsc                 D   |                      d          r>t          t          j        d           | dvrt          dk     rt          j        d           t
          j                            t          d          }t          |           t          ||           }||k    sJ dS )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   s     ~~e 1>K)***(((-AA-E-EK/000GLL?33EEeS))MM))))))r%   c                 t   |                      d          r>t          t          j        d           | dvrt          dk     rt          j        d           t
          j                            t          d          }t          |           |  d| }t          ||          sJ |  d	}t          ||          rJ dS )
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 1>K)***(((-AA-E-EK/000GLL?33EE))-))Jz*****&&&JE:.......r%   c                    t           j                            t          d          }t	          |           |  d| }t          ||d          sJ |  d}t          j        t                    5 }t          ||dd           ddd           n# 1 swxY w Y   dt          |j
                  v sJ t          j        t                    5 }t          ||dd           ddd           n# 1 swxY w Y   |t          |j
                  v sJ dS )	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    GLL?33EE))-))Jz$777777$$$H	z	"	" GeUHT+FFFFG G G G G G G G G G G G G G G#ek******	z	"	" @eUHT$????@ @ @ @ @ @ @ @ @ @ @ @ @ @ @C$$$$$$$$s$   .BBB
C**C.1C.c                      t           j                            t          d          } t	          | d          sJ t	          dd          sJ t	          | dd          sJ dS )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      sj    GLL?33E$//////bT222222$t<<<<<<<<r%   c                    t           j                            t          d          }t	          |           |  d|                                 }t          ||d          sJ t          j        t                    5 }t          ||dd         dd           ddd           n# 1 swxY w Y   dt          |j                  v sJ dS )	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    GLL?33EE11---//11Jz$777777	z	"	" NeUJssODMMMMN N N N N N N N N N N N N N N#ek********s   ;B##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      s    
			       ' ' ' ' ' ' MMM3v~33C!3DDQGHH   F               
 5 4 4 4 4 4 4 43ttH~~$v-788V 	W 
 7P-    02!   ,0022    , - - - 0 0 0     *     ,& & & D				!	!""""$$%%   

* 
* 

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

+ 
+ 

+ 
+ 
+s   /A 	AA