
    Pig              	          d Z ddlZddlZddlmZ ddlmZ ddlZddlm	Z	m
Z
mZmZmZ ddlmZmZmZ ddlmZmZ dd	lmZ dd
lmZmZ ddlmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#  e$ ee%          j&        dz            Z' e            Z( e            Z) e            Z* e            Z+ e            Z, e            Z-ddiZ.ej/        d             Z0ej1        j2        d             Z3ej1        j2        d             Z4ej1        j2        d             Z5d Z6ej1        j2        ej1        7                    de) ej8        e*ej1        j9                  e+e-gg d          d                         Z:ej1        j2        ej1        7                    de) ej8        e*ej1        j9                  e+e-gg d          d                         Z; G d d          Z<ej1        j2        d             Z= G d d          Z>ej1        j2        d              Z?ej1        j2        d!             Z@ej1        j2        d"             ZAej1        j2        d#             ZBd$ ZCd% ZDd& ZEej1        j2        d'             ZFd( ZGd) ZHd* ZId+ ZJd, ZKd- ZLd. ZMej1        j2        d/             ZNd0 ZOd1 ZPej1        j2        d2             ZQd3 ZRd4 ZSd5 ZTej1        j2        ej1        7                    d6dd7g          d8                         ZUej1        j2        ej1        7                    d ej8        e*ej1        j9                  e+e-gg d9          d:                         ZVej1        j2        d;             ZWd< ZXdS )=z+
Test the core class and factory function.
    N)Path)TemporaryDirectory   )createPoochretrievedownload_actionstream_download)
get_loggertemporary_fileos_cache)	file_hashhash_matches)core)HTTPDownloaderFTPDownloader   )pooch_test_urldata_over_ftppooch_test_figshare_urlpooch_test_zenodo_url pooch_test_zenodo_with_slash_urlpooch_test_dataverse_urlpooch_test_registrycheck_tiny_datacheck_large_datacapture_logmirror_directorydatatiny-data.txt@098h0894dba14b12085eacb204284b97e362f4f3e5a5807693cc90ef415c1b2dc                 ,    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    i/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/pooch/tests/test_core.pydata_dir_mirrorr&   5   s     Hh///    c                  p   t                      5 } d}t          |z   }t                      5 }t          |d|           }|                                }|                                d         dk    sJ d|v sJ t          |         |v sJ 	 ddd           n# 1 swxY w Y   ||t          |           d         k    sJ t          |           t          |          t          |         k    sJ t                      5 }t          |d|           }|                                dk    sJ 	 ddd           n# 1 swxY w Y   t                      5 }t          |t          |         |           }|                                dk    sJ 	 ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )z'Try downloading some data with retriever    N)
known_hashpathr   DownloadingSHA256 hash of downloaded file: )
r   BASEURLr   r   getvaluesplitREGISTRYlenr   r   local_store	data_fileurllog_filefnamelogss         r%   test_retriever:   >   s    
		 -#		!]] 	/hSTDDDE$$&&D::<<?m33334<<<<I&$.....	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ E3y>>/"3"3444448I#66666]] 	-hSTDDDE$$&&",,,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- ]] 	-hSXi-@{SSSE$$&&",,,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-%- - - - - - - - - - - - - - - - - -s~   F+AB	F+B	F+B	AF+;-D5)F+5D9	9F+<D9	=F+8FF+F	F+F	F++F/2F/c                  ,   t                      5 } d}t          |z   }t                      5 }t          |d| |          }|                                }|                                d         dk    sJ d|v sJ t          |         |v sJ 	 ddd           n# 1 swxY w Y   |t          j                            |          d         k    sJ t          |           t          |          t          |         k    sJ 	 ddd           dS # 1 swxY w Y   dS )zATry downloading some data with retrieve and setting the file namer    N)r)   r*   r8   r   r+   r,   r   )r   r.   r   r   r/   r0   r1   osr*   r   r   r3   s         r%   test_retrieve_fnamer=   X   s    
		 7#		!]] 	/hST9UUUE$$&&D::<<?m33334<<<<I&$.....	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ BGMM%00333338I#6666667 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7s6   D	AB
D	B	D	B	AD		DDc                     d} t           | z   }t          d          | z  }	 t                      5 }t          |d|           }|                                }|                                d         dk    sJ t          t          d                                                    |v sJ d|v sJ t          |          |v sJ 	 ddd           n# 1 swxY w Y   |t          |                                          k    sJ t          |           t          |          t          |          k    sJ 	 t          j                            t          |                    r#t          j        t          |                     dS dS # t          j                            t          |                    r"t          j        t          |                     w w xY w)zETry downloading some data with retrieve to the default cache locationr    poochN)r)   r8   r   r+   zSHA256 hash of downloaded file)r.   r   r   r   r/   r0   strresolver1   r   r   r<   r*   existsremove)r5   r6   expected_locationr7   r8   r9   s         r%   test_retrieve_default_pathrE   k   s     I
I
C ))I5.]] 	/hSTCCCE$$&&D::<<?m3333x((002233t;;;;3t;;;;I&$.....	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ -55778888888I#6666667>>#/0011 	.Ic+,,-----	. 	.27>>#/0011 	.Ic+,,----	.s1   E> BC?E> CE> CAE> >AGc                     t          | dt                    }t          | dz            }|                    d          }||k    sJ t	          |           dS )zASetup a pooch that already has the local data and test the fetch.some bogus URLr*   base_urlregistryr    N)r   r1   r@   fetchr   )r&   puptruer8   s       r%   test_pooch_localrN      s[    
_/?(
S
S
SC011DIIo&&E5====Er'   r6   )marks)httpsfigsharezenodo	dataverse)idsc                    t                      5 }t          |          }d| dz   i}t          |dt          |          }t	                      5 }|                    d          }|                                }|                                d         dk    sJ |                                d         d| dk    sJ 	 d	d	d	           n# 1 swxY w Y   t          |           t	                      5 }|                    d          }|                                dk    sJ 	 d	d	d	           n# 1 swxY w Y   d	d	d	           d	S # 1 swxY w Y   d	S )
z:Have pooch download the file from URL that is not base_urlr    r-   r*   rI   rJ   urlsr   r+   ''.N)	r   r   r   r1   r   rK   r/   r0   r   )r6   r4   r*   rW   rL   r7   r8   r9   s           r%   test_pooch_custom_urlr[      s    
		 -K  !67XDIII]] 	4hIIo..E$$&&D::<<?m3333::<<#|4|||33333		4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4
 	]] 	-hIIo..E$$&&",,,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-- - - - - - - - - - - - - - - - - -sZ   =EA.C;EC	EC	 E/0D, E,D0	0E3D0	4EEEc                    t                      5 }t          |          }t          |dz            }t          || t                    }t                      5 }|                    d          }|                                }|                                d         dk    sJ |                                d         d| dk    sJ 	 ddd           n# 1 swxY w Y   ||k    sJ t          |           t          |          t          d         k    sJ t                      5 }|                    d          }|                                d	k    sJ 	 ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )
z:Setup a pooch that has no local data and needs to downloadr    rH   r   r+   rX   rY   rZ   Nr-   )r   r   r@   r   r1   r   rK   r/   r0   r   r   )r6   r4   r*   	true_pathrL   r7   r8   r9   s           r%   test_pooch_downloadr^      s4    
		 -K  .//	h???]] 	4hIIo..E$$&&D::<<?m3333::<<#|4|||33333		4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 E!!!!8O#<<<<<]] 	-hIIo..E$$&&",,,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-!- - - - - - - - - - - - - - - - - -s\   AE6A.CE6C	E6C	AE6!0EE6E"	"E6%E"	&E66E:=E:c                       e Zd ZdZd Zd ZdS )FakeHashMatchesz8Create a fake version of hash_matches that fails n timesc                 "    || _         d| _        d S )Nr   )	nfailuresfailed)selfrb   s     r%   __init__zFakeHashMatches.__init__   s    "r'   c                     | j         | j        k     r$| xj         dz  c_         t          |d         dfi |S t          |i |S )z#Fail n times before finally passingr   r   bla)rc   rb   r   )rd   argskwargss      r%   r   zFakeHashMatches.hash_matches   sP    ;''KK1KKQ99&999T,V,,,r'   N)__name__
__module____qualname____doc__re   r    r'   r%   r`   r`      s8        >>  - - - - -r'   r`   c                    t                      5 }|                     t          dt          d          j                   t          |          }t          |t          t                    }t          j
        t                    5 }t                      5 }|                    d           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   dt          |          v sJ |                                                                                    d          }t%          |          dk    sJ |d	                             d
          sJ |d	                             d| d          sJ 	 ddd           dS # 1 swxY w Y   dS )z2Check that retrying the download is off by defaultr      rH   r    Ndoes not match the known hash
r   r   r+   rY   rZ   )r   setattrr   r`   r   r   r   r.   r1   pytestraises
ValueErrorr   rK   r@   r/   stripr0   r2   
startswithendswithmonkeypatchr4   r*   rL   errorr7   r9   s          r%   (test_pooch_download_retry_off_by_defaultr}      s#    
		 .D./!2D2D2QRRRK  (CCC]:&& 	+% +(		/***+ + + + + + + + + + + + + + +	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ /#e**<<<<  ""((**00664yyA~~~~Aw!!-00000AwD------. . . . . . . . . . . . . . . . . .s[   A3FC
B3'C
3B77C
:B7;C
>F
C	FC	B"FF	Fc                       e Zd ZdZd Zd ZdS )	FakeSleepz<Create a fake version of sleep that logs the specified timesc                     g | _         d S )N)times)rd   s    r%   re   zFakeSleep.__init__   s    


r'   c                 :    | j                             |           dS )z Store the time and doesn't sleepN)r   append)rd   secss     r%   sleepzFakeSleep.sleep   s    
$r'   N)rj   rk   rl   rm   re   r   rn   r'   r%   r   r      s8        BB           r'   r   c           	      P   t                      5 }|                     t          dt          d          j                   t                      }|                     t          j        d|j                   t          |          }t          |dz            }d}t          |t          t          |          }t                      5 }|                    d          }|                                                                                    d          }	t%          |	          d|z   k    sJ |	d                             d	          sJ |	d                             d
| d          sJ t+          t-          |dd          |	dd                   D ]"\  }
}d|v sJ |
dk    rdnd}d|
 d| d|v sJ #|j        g dk    sJ 	 ddd           n# 1 swxY w Y   ||k    sJ t1          |           t3          |          t          d         k    sJ 	 ddd           dS # 1 swxY w Y   dS )z?Check that retrying the download works if the hash is differentr      r   r    r*   rI   rJ   retry_if_failedrr   r   r   r+   rY   rZ   rX   NFailed to downloadsr-   zdownload again z
 more time.)r   r   rp                  	   
   r   )r   rs   r   r`   r   r   timer   r   r@   r   r.   r1   r   rK   r/   rw   r0   r2   rx   ry   zipranger   r   r   )r{   r4   	fakesleepr*   r]   retriesrL   r7   r8   r9   ilineplurals                r%   test_pooch_download_retryr      s    
		 =D./"2E2E2RSSSKK	DIw	@@@K  .//	(G
 
 
 ]] 	JhIIo..E$$&&,,..44T::Dt99G++++7%%m444447##LLLL11111uWa44d122h?? H H4+t3333 !A2???f???4GGGGG?&I&I&IIIIII	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J E!!!!8O#<<<<<<7= = = = = = = = = = = = = = = = = =s7   B1H C>G?HG	HG	:HH"Hc                 P   t                      5 }|                     t          dt          d          j                   t          |          }t          |t          t          d          }t          j
        t                    5 }t                      5 }|                    d           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |                                                                                    d          }t#          |          dk    sJ |d	                             d
          sJ |d	                             d| d          sJ d|d         v sJ d|d         v sJ dt)          |          v sJ 	 ddd           dS # 1 swxY w Y   dS )zFCheck that retrying the download fails after the set amount of retriesr   rp   r   r   r    Nrr   r   r   r+   rY   rZ   r   zdownload again 1 more time.rq   )r   rs   r   r`   r   r   r   r.   r1   rt   ru   rv   r   rK   r/   rw   r0   r2   rx   ry   r@   rz   s          r%   *test_pooch_download_retry_fails_eventuallyr     sP    
		 =D./!2D2D2QRRRK  (TUVVV]:&& 	+% +(		/***+ + + + + + + + + + + + + + +	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+   ""((**00664yyA~~~~Aw!!-00000AwD-----#tAw....,Q7777.#e**<<<<<!= = = = = = = = = = = = = = = = = =s[   A4FCB4(C4B88C;B8<C?FC	FC	B:FF"Fc                     t                      5 } t          |           }dt          dz   i}t          |dt          |          }t          d          5 }|                    d          }|                                dk    sJ 	 ddd           n# 1 swxY w Y   t          |           ddd           dS # 1 swxY w Y   dS )zHSetup a pooch and check that no logging happens when the level is raisedr    r-   rV   CRITICALN)	r   r   r.   r   r1   r   rK   r/   r   )r4   r*   rW   rL   r7   r8   s         r%   test_pooch_logging_levelr   3  sD    
		 	K  ?!:;XDIII$$ 	-IIo..E$$&&",,,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s6   AB60BB6B	B6B	B66B:=B:c                     t                      5 } t          |           }t          |dz            }t          |dd          5 }|                    d           ddd           n# 1 swxY w Y   t          |t          t                    }t                      5 }|	                    d          }|
                                }|                                d         d	k    sJ |                                d
         d| dk    sJ 	 ddd           n# 1 swxY w Y   ||k    sJ t          |           t          |          t          d         k    sJ t                      5 }|	                    d          }|
                                dk    sJ 	 ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )zFSetup a pooch that already has the local data but the file is outdatedr    wutf-8encodingdifferent dataNrH   r   UpdatingrX   rY   rZ   r-   )r   r   r@   openwriter   r.   r1   r   rK   r/   r0   r   r   )r4   r*   r]   finrL   r7   r8   r9   s           r%   test_pooch_updater   B  s    
		 -K   .//	)S7333 	(sII&'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( (CCC]] 	4hIIo..E$$&&D::<<?j0000::<<#|4|||33333		4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 E!!!!8O#<<<<<]] 	-hIIo..E$$&&",,,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-)- - - - - - - - - - - - - - - - - -s   4F:A%F:%A)	)F:,A)	--F:A.D	F:D	F:D	AF:%0F"F:"F&	&F:)F&	*F::F>F>c                     t                      5 } t          |           }t          |dz            }t          |dd          5 }|                    d           ddd           n# 1 swxY w Y   t          |t          t          d          }t          j	        t                    5  |                    d           ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )	z$Test that disallowing updates works.r    r   r   r   r   NFr*   rI   rJ   allow_updates)r   r   r@   r   r   r   r.   r1   rt   ru   rv   rK   )r4   r*   r]   r   rL   s        r%   test_pooch_update_disallowedr   ^  s   			 'K   .//	)S7333 	(sII&'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	
 
 
 ]:&& 	' 	'IIo&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 'sY   4C A%C %A)	)C ,A)	-9C &C<C C	C C	C  C$'C$c                     d} 	 dt           j        | <   t                      5 }t          |          }t	          |dz            }t          |dd          5 }|                    d           ddd           n# 1 swxY w Y   t          |t          t          | 	          }t          j        t                    5  |                    d           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   t           j                            |            dS # t           j                            |            w xY w)
zDTest that disallowing updates works through an environment variable.MYPROJECT_DISALLOW_UPDATESFalser    r   r   r   r   Nr   )r<   environr   r   r@   r   r   r   r.   r1   rt   ru   rv   rK   pop)variable_namer4   r*   r]   r   rL   s         r%   (test_pooch_update_disallowed_environmentr   r  s   0M&$+
=!!! 	+[$$D D?233Iiw777 ,3		*+++, , , , , , , , , , , , , , ,  !+	  C z** + +		/***+ + + + + + + + + + + + + + +	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+" 	
}%%%%%
}%%%%sv   D 4C1A7+C17A;	;C1>A;	?9C18CC1C	C1!C	"C1%D 1C55D 8C59D !D>c                  X    d} t          | dt                    }|j        | dz   k    sJ dS )zR
    Test if pooch.create appends a trailing slash to the base url if missing
    zhttps://mybase.urlN)rI   rJ   r*   /)r   r#   rI   )rI   rL   s     r%   ,test_pooch_create_base_url_no_trailing_slashr     s:     $H
(T
A
A
AC<8c>))))))r'   c                 v   t                      5 }t          j                            |          }t	          |t
          t                    }t                      5 }t          j	        t                    5 }|                    d           ddd           n# 1 swxY w Y   dt          |j                  v sJ |                                }|                                d         dk    sJ |                                d         d| d	k    sJ 	 ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   t	          | t
          t                    }t                      5 }t          j	        t                    5 }|                    d           ddd           n# 1 swxY w Y   dt          |j                  v sJ |                                }|                                d         d
k    sJ |                                d         d|  d	k    sJ 	 ddd           dS # 1 swxY w Y   dS )z>Raise an exception if the file hash doesn't match the registryrH   r    Nz(tiny-data.txt)r   r+   rX   rY   rZ   r   )r   r<   r*   abspathr   r.   REGISTRY_CORRUPTEDr   rt   ru   rv   rK   r@   valuer/   r0   )r&   r4   r*   rL   r7   r|   r9   s          r%   test_pooch_corruptedr     s8    
		 	4w{++:LMMM]] 	4hz** +e		/***+ + + + + + + + + + + + + + +$EK(8(88888$$&&D::<<?m3333::<<#|4|||33333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 _wAS
T
T
TC	 ;(]:&& 	'%IIo&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' C$4$44444  ""zz||A*,,,,zz||B#:#:#:#::::::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;s   A
D4D3B	DBDBA3DD4D!	!D4$D!	%D44D8;D8)H.F%H.%F)	)H.,F)	-A3H..H25H2c                      t          ddt                    } t          j        t                    5  |                     d           ddd           dS # 1 swxY w Y   dS )z=Should raise an exception if the file is not in the registry.zit shouldn't matterzthis shouldn't eitherrH   zthis-file-does-not-exit.csvN)r   r1   rt   ru   rv   rK   rL   s    r%   test_pooch_file_not_in_registryr     s    
"-Dx  C 
z	"	" 1 1		/0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1s   AAAc                  B   t          dd          } |                     t          j                            t
          d                     | j        t          k    sJ | j        	                                t          t                    	                                k    sJ dS )z,Loading the registry from a file should workr-   r*   rI   registry.txtNr   load_registryr<   r*   joinr#   rJ   r1   registry_filessortlistr   s    r%   test_pooch_load_registryr     s    
R"
%
%
%Cbgll8^<<===<8####""$$X(;(;(=(=======r'   c                  B   t          dd          } |                     t          j                            t
          d                     | j        t          k    sJ | j        	                                t          t                    	                                k    sJ dS )z8Loading the registry from a file and strip line commentsr-   r   zregistry_comments.txtNr   r   s    r%   !test_pooch_load_registry_commentsr     s    
R"
%
%
%Cbgll8-DEEFFF<8####""$$X(;(;(=(=======r'   c                     t           j                            t          d          } t	          dd          }t          | d          5 }|                    |           ddd           n# 1 swxY w Y   |j        t          k    sJ |j	        
                                t          t                    
                                k    sJ t	          dd          }t          | dd          5 }|                    |           ddd           n# 1 swxY w Y   |j        t          k    sJ |j	        
                                t          t                    
                                k    sJ dS )	z'Loading the registry from a file objectr   r-   r   rbNrr   r   )r<   r*   r   r#   r   r   r   rJ   r1   r   r   r   )r*   rL   r   s      r%    test_pooch_load_registry_fileobjr     s   7<<.11D R"
%
%
%C	dD		 S#              <8####""$$X(;(;(=(===== R"
%
%
%C	dC'	*	*	* c#              <8####""$$X(;(;(=(=======s$   A))A-0A-,DDDc                      t          dd          } |                     t          j                            t
          d                     | j        t          k    sJ | j        ddik    sJ dS )z8Load the registry from a file with a custom URL insertedr-   r   zregistry-custom-url.txtr    zhttps://some-site/tiny-data.txtN)	r   r   r<   r*   r   r#   rJ   r1   rW   r   s    r%   #test_pooch_load_registry_custom_urlr     sk    
R"
%
%
%Cbgll8-FGGHHH<8####8)JKKKKKKKr'   c                      t          ddi           } t          j        t                    5  |                     t
          j                            t          d                     ddd           dS # 1 swxY w Y   dS )z?Should raise an exception when a line doesn't have two elementsr-   rH   zregistry-invalid.txtN)	r   rt   ru   IOErrorr   r<   r*   r   r#   r   s    r%   %test_pooch_load_registry_invalid_liner     s    
R"r
2
2
2C	w		 J J"',,x1GHHIIIJ J J J J J J J J J J J J J J J J Js   9A22A69A6c                      t          dd          } |                     t          j                            t
          d                     d| j        v sJ d| j        v sJ dS )zCShould check that spaces in filenames are allowed in registry filesr-   r   zregistry-spaces.txtzfile with spaces.txtzother with spaces.txtN)r   r   r<   r*   r   r#   rJ   r   s    r%   $test_pooch_load_registry_with_spacesr     se    
R"
%
%
%Cbgll8-BCCDDD!S\1111"cl222222r'   c                     t          t          t          t                    } |                     d          sJ t          t          t          dz   t                    } |                     d          rJ ddi}|                    t                     t          t          t          |          } |                     d          rJ dS )FShould correctly check availability of existing and non existing filesrH   r    z
wrong-url/znot-a-real-data-file.txtnotarealhashN)r   r#   r.   r1   is_availableupdate)rL   rJ   s     r%   test_check_availabilityr     s     X(
C
C
CCO,,,,,
X,(>
R
R
RC00000*N;HOOH
X(
C
C
CC :;;;;;;;r'   c                 D   t          | d          5 }t          t          |                    dd          ddd          }t	          | j                  }|                    d|          sJ |                    d	|          rJ 	 d
d
d
           d
S # 1 swxY w Y   d
S )r   r    r-   @baee0894dba14b12085eacb204284b97e362f4f3e5a5807693cc90ef415c1b2djdjdjdjdflld)r    doesnot_exist.ziprH   )port
downloaderr   N)r   r   r#   replacer   server_portr   )	ftpserverr6   rL   r   s       r%   test_check_availability_on_ftpr      s   	y/	2	2 Pc[["55!c%3 
 
 
 #	(=>>>
JGGGGG##$7J#OOOOOOP P P P P P P P P P P P P P P P P Ps   A6BBBc                      d } t          t          t          t                    }d}t	          j        t          |          5  |                    d|            ddd           dS # 1 swxY w Y   dS )z@Should raise an exception if the downloader doesn't support thisc                     dS )z,A downloader that doesn't support check_onlyNrn   )r6   outputr?   s      r%   r   z>test_check_availability_invalid_downloader.<locals>.downloader  s    tr'   rH   z%does not support availability checks.)matchr    r   N)r   r#   r.   r1   rt   ru   NotImplementedErrorr   )r   rL   msgs      r%   *test_check_availability_invalid_downloaderr     s       X(
C
C
CC
1C	*#	6	6	6 A AZ@@@A A A A A A A A A A A A A A A A A As   A''A+.A+c                    d }t                      5 }t          |          }t          |t          t                    }t                      5 }|                    d|          }|                                }|                                }t          |          dk    sJ |d         
                                d         dk    sJ |d         d	k    sJ 	 d
d
d
           n# 1 swxY w Y   |                                 j        rJ t          |           t                      5 }|                    d          }|                                dk    sJ 	 d
d
d
           n# 1 swxY w Y   d
d
d
           d
S # 1 swxY w Y   d
S )z%Setup a downloader function for fetchc                 z    t                                          d            t                      | ||           dS )z2Download through HTTP and warn that we're doing itdownloader executedN)r   infor   )r6   output_filerL   s      r%   downloadz,test_fetch_with_downloader.<locals>.download#  s;    /000k3/////r'   rH   zlarge-data.txtr   r   r   r+   r   r   Nr-   )r   r   r   r.   r1   r   rK   r/   
splitlinesr2   r0   
readouterrerrr   )	capsysr   r4   r*   rL   r7   r8   r9   liness	            r%   test_fetch_with_downloaderr     s<   0 0 0
 
		 -K  (CCC]] 	5hII.8IDDE$$&&DOO%%Eu::????8>>##A&-77778444444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 $$&&****]] 	-hII.//E$$&&",,,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-#- - - - - - - - - - - - - - - - - -sZ   :E:B	C"E:"C&	&E:)C&	*;E:%0E"E:"E&	&E:)E&	*E::E>E>c                     t          | t          ddi          }t          j        t                    5 }|                    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 algorithmr    z	blah:1234rH   Nz'blah')r   r.   rt   ru   rv   rK   r@   r   )r&   rL   excs      r%   test_invalid_hash_algr   >  s    
w/;9W  C 
z	"	" #c		/"""# # # # # # # # # # # # # # # s39~~%%%%%%s   AAAc                    t          | dz            }t          |           t          |d          5 }|                                }ddd           n# 1 swxY w Y   dD ]}t	          j        |          }|                    |           d| d|                                 i}t          | d|          }||	                    d          k    sJ t          |           dS )z2Test different hashing algorithms using local datar    r   N)sha512md5:rG   rH   )
r@   r   r   readhashlibnewr   	hexdigestr   rK   )r&   r8   r   r   alghasherrJ   rL   s           r%   #test_alternative_hashing_algorithmsr  I  s2   /122EE	eT		 cxxzz                 S!!d#%B%Bf.>.>.@.@%B%BC3ChWWW		/222222 s   AAAc                  \   t          t          d          d          \  } }| dk    sJ |dk    sJ t                      5 }t          t          |          d          \  } }ddd           n# 1 swxY w Y   | dk    sJ |dk    sJ t                      5 }t          |d	d
          5 }|                    d           ddd           n# 1 swxY w Y   t          t          |          t          |                    \  } }ddd           n# 1 swxY w Y   | dk    sJ |dk    sJ dS )z>Test that the right action is performed based on file existingzthis_file_does_not_exist.txtN)r)   r   r+   znot the correct hashr   r   r   r   r   z	some datarK   Fetching)r	   r   r   r   r   r   )actionverbtmpr   s       r%   test_download_actionr  X  s,   "+,,  LFD Z=    			 US&tCyy=STTTU U U U U U U U U U U U U U UX:			 MS#sW--- 	&LL%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&&tCyyYs^^LLLM M M M M M M M M M M M M M M W:sH    "A..A25A2D*C DC	DC	1DDDr8   zsubdir/tiny-data.txtc                    t           dz   | z   }t          |          }t                      }t                      5 }t	          |          | z  }|                                rJ t          ||||d           |                                sJ t          t          |                     ddd           dS # 1 swxY w Y   dS )z9Check that downloading a file over HTTP works as expectedzstore/N)r?   )	r.   r1   r   r   r   rB   r
   r   r@   )r8   r6   r)   r   r4   destinations         r%   test_stream_downloadr  m  s   
 H
u
$C%J!!J			 *;''%/%%'''''[*jMMMM!!#####K(()))* * * * * * * * * * * * * * * * * *s   A/B33B7:B7)rQ   rR   rS   c                 |   t                      5 }t          j                            |          }t	          ||           }|                                 t          |j                  dk    sJ d|j        v sJ d|j        v sJ |j        D ]}|                    |           	 ddd           dS # 1 swxY w Y   dS )z;Check that the registry is correctly populated from the APIr   r   r    z	store.zipN)	r   r<   r*   r   r   load_registry_from_doir2   rJ   rK   r6   r4   r*   rL   filenames        r%   test_load_registry_from_doir  }  s    
		  w{++,,,""$$$ 3<  A%%%%#,....cl****  	  	 HIIh	                                    s   BB11B58B5c                  t   t           } t                      5 }t          j                            |          }t          ||           }|                                 t          |j                  dk    sJ d|j        v sJ |j        D ]}|	                    |           	 ddd           dS # 1 swxY w Y   dS )zs
    Check that the registry is correctly populated from the Zenodo API when
    the filename contains a slash
    r   r   z!santisoler/pooch-test-data-v1.zipN)
ZENODOURL_W_SLASHr   r<   r*   r   r   r  r2   rJ   rK   r  s        r%   -test_load_registry_from_doi_zenodo_with_slashr    s
    C			  w{++,,,""$$$ 3<  A%%%%2clBBBB  	  	 HIIh	                                    s   B	B--B14B1c                      t          dt                    } t          j        t                    5 }|                                  ddd           n# 1 swxY w Y   dt          |j                  v sJ dS )z(Check that non-DOI URLs produce an errorr-   r   Nzonly implemented for DOIs)r   r.   rt   ru   rv   r  r@   r   )rL   r   s     r%   !test_wrong_load_registry_from_doir    s     R'
*
*
*C	z	"	" %c""$$$% % % % % % % % % % % % % % % '#ci..888888s   AAA)Yrm   r  r<   pathlibr   tempfiler   rt   r   r   r   r   r	   r
   utilsr   r   r   hashesr   r   r-   downloadersr   r   r   r   r   r   r   r   r   r   r   r   r   r@   __file__parentr#   r1   r.   FIGSHAREURL	ZENODOURLr  DATAVERSEURLr   fixturer&   marknetworkr:   r=   rE   rN   parametrizeparamrQ   r[   r^   r`   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  rn   r'   r%   <module>r.     s     				       ' ' ' ' ' '  L L L L L L L L L L L L L L 8 8 8 8 8 8 8 8 8 8 , , , , , , , ,       7 7 7 7 7 7 7 7                          3ttH~~$v-..  
.

%%''!!##	4466 '')) W  0 0 0 - - -2 7 7 7$ . . ..   	[(<===	 	544  	 	- -	 	 -( 	[(<===	 	544  	 	- -	 	 -.- - - - - - - -  . . .&                = = =@ = = =*    - - -6' ' '(& & &2* * * ; ; ;01 1 1> > >> > >> > >&L L LJ J J3 3 3 < < <P P P$
A 
A 
A - - -<& & &    * ?4J"KLL* * ML * 	V\+V[%9:::I|T+++   
      "      (9 9 9 9 9r'   