
     
3jg              
       v   S r SSKrSSKrSSKJr  SSKJr  SSKrSSKJ	r	J
r
JrJrJr  SSKJrJrJr  SSKJrJr  SS	KJr  SS
KJrJr  SSKJrJrJrJrJrJrJrJ r J!r!J"r"J#r#  \$" \" \%5      RL                  S-  5      r'\" 5       r(\" 5       r)\" 5       r*\" 5       r+\" 5       r,\" 5       r-SS0r.\R^                  S 5       r0\Rb                  Rd                  S 5       r3\Rb                  Rd                  S 5       r4\Rb                  Rd                  S 5       r5S r6\Rb                  Rd                  \Rb                  Ro                  S\)\Rp                  " \*\Rb                  Rr                  S9\+\-// SQS9S 5       5       r:\Rb                  Rd                  \Rb                  Ro                  S\)\Rp                  " \*\Rb                  Rr                  S9\+\-// SQS9S 5       5       r; " S S5      r<\Rb                  Rd                  S 5       r= " S S5      r>\Rb                  Rd                  S  5       r?\Rb                  Rd                  S! 5       r@\Rb                  Rd                  S" 5       rA\Rb                  Rd                  S# 5       rBS$ rCS% rDS& rE\Rb                  Rd                  S' 5       rFS( rGS) rHS* rIS+ rJS, rKS- rLS. rM\Rb                  Rd                  S/ 5       rNS0 rOS1 rP\Rb                  Rd                  S2 5       rQS3 rRS4 rSS5 rT\Rb                  Rd                  \Rb                  Ro                  S6SS7/5      S8 5       5       rU\Rb                  Rd                  \Rb                  Ro                  S\Rp                  " \*\Rb                  Rr                  S9\+\-// S9QS9S: 5       5       rV\Rb                  Rd                  S; 5       rWS< rXg)=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                 "    [        [        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    O/home/wildlama/miniconda3/lib/python3.13/site-packages/pooch/tests/test_core.pydata_dir_mirrorr&   5   s     Hh//    c                     [        5        n Sn[        U-   n[        5        n[        USU S9nUR	                  5       nUR                  5       S   S:X  d   eSU;   d   e[        U   U;   d   e SSS5        UW[        U5      * S :X  d   e[        U5        [        U5      [        U   :X  d   e[        5        n[        USU S9nUR	                  5       S:X  d   e SSS5        [        5        n[        U[        U   U S9nUR	                  5       S:X  d   e SSS5        SSS5        g! , (       d  f       N= f! , (       d  f       Nd= f! , (       d  f       N9= f! , (       d  f       g= f)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:   >   sL    
	#		!]hSTDE$$&D::<?m3334<<<I&$...  E3y>/"344448I#6666]hSTDE$$&",,,  ]hSXi-@{SE$$&",,, % 
	 ] ] ]% 
	sT   EAD(.A
E8"D9E-)E
E(
D6	2E9
E	E

E	E
E)c            	         [        5        n Sn[        U-   n[        5        n[        USXS9nUR	                  5       nUR                  5       S   S:X  d   eSU;   d   e[        U   U;   d   e SSS5        U[        R                  R                  W5      S   :X  d   e[        U5        [        U5      [        U   :X  d   e SSS5        g! , (       d  f       Nc= f! , (       d  f       g= f)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     
	#		!]hSTUE$$&D::<?m3334<<<I&$...  BGGMM%033338I#6666 
	 ]	 
	s$   CAC.AC
C	C
C*c                  ,   Sn [         U -   n[        S5      U -  n [        5        n[        USU S9nUR	                  5       nUR                  5       S   S:X  d   e[        [        S5      R                  5       5      U;   d   eSU;   d   e[        U    U;   d   e SSS5        W[        UR                  5       5      :X  d   e[        U5        [        U5      [        U    :X  d   e [        R                  R                  [        U5      5      (       a   [        R                  " [        U5      5        gg! , (       d  f       N= f! [        R                  R                  [        U5      5      (       a   [        R                  " [        U5      5        f f = f)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   sT     I
I
C )I5.]hSTCE$$&D::<?m333x(0023t;;;3t;;;I&$...  -55788888I#666677>>#/011IIc+,- 2 ] 77>>#/011IIc+,- 2s%   
E A4D3A
E 3
E=E AFc                     [        U S[        S9n[        U S-  5      nUR                  S5      nX#:X  d   e[	        U5        g)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@    
_/?(
SC01DIIo&E==Er'   r6   )marks)httpsfigsharezenodo	dataverse)idsc                 6   [        5        n[        U5      nSU S-   0n[        US[        US9n[	        5        nUR                  S5      nUR                  5       nUR                  5       S   S:X  d   eUR                  5       S   SU S3:X  d   e S	S	S	5        [        W5        [	        5        nUR                  S5      nUR                  5       S:X  d   e S	S	S	5        S	S	S	5        g	! , (       d  f       N]= f! , (       d  f       N(= f! , (       d  f       g	= f)
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]hIIo.E$$&D::<?m333::<#4&|333	 
 	]hIIo.E$$&",,,  
	 ] ] 
	s;   -D
AC(D
.(C9D
(
C6	2D
9
D	D


Dc                    [        5        n[        U5      n[        US-  5      n[        X [        S9n[        5        nUR                  S5      nUR                  5       nUR                  5       S   S:X  d   eUR                  5       S   SU S3:X  d   e SSS5        UW:X  d   e[        U5        [        U5      [        S   :X  d   e[        5        nUR                  S5      nUR                  5       S	:X  d   e SSS5        SSS5        g! , (       d  f       N}= f! , (       d  f       N(= f! , (       d  f       g= f)
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^      s    
	K ./	h?]hIIo.E$$&D::<?m333::<#4&|333	  E!!!8O#<<<<]hIIo.E$$&",,, ! 
	 ] ]! 
	s;   2D/AD=D/(D<D/
D	D/
D,	(D//
D=c                   $    \ rS rSrSrS rS rSrg)FakeHashMatches   z8Create a fake version of hash_matches that fails n timesc                     Xl         SU l        g )Nr   )	nfailuresfailed)selfrc   s     r%   __init__FakeHashMatches.__init__   s    "r'   c                     U R                   U R                  :  a%  U =R                   S-  sl         [        US   S40 UD6$ [        U0 UD6$ )z#Fail n times before finally passingr   r   bla)rd   rc   r   )re   argskwargss      r%   r   FakeHashMatches.hash_matches   sF    ;;'KK1KQ9&99T,V,,r'   )rd   rc   N)__name__
__module____qualname____firstlineno____doc__rf   r   __static_attributes__ r'   r%   r`   r`      s    >-r'   r`   c                    [        5        nU R                  [        S[        S5      R                  5        [        U5      n[        U[        [        S9n[        R                  " [        5       n[        5        nUR                  S5        SSS5        SSS5        S[        W5      ;   d   eWR                  5       R!                  5       R#                  S5      n[%        U5      S:X  d   eUS	   R'                  S
5      (       d   eUS	   R)                  SU S35      (       d   e SSS5        g! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       g= f)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./!2D2Q2QRK (C]]:&%(		/*  ' /#e*<<<  "((*0064yA~~Aw!!-0000Aw!D6---- 
	  '& 
	s=   A#E.D?9D.D?BE.
D<8D??
E		E
Ec                   $    \ rS rSrSrS rS rSrg)	FakeSleep   z<Create a fake version of sleep that logs the specified timesc                     / U l         g )Ntimes)re   s    r%   rf   FakeSleep.__init__   s	    
r'   c                 :    U R                   R                  U5        g)z Store the time and doesn't sleepN)r   append)re   secss     r%   sleepFakeSleep.sleep   s    

$r'   r   N)rm   rn   ro   rp   rq   rf   r   rr   rs   r'   r%   r   r      s    B r'   r   c           	         [        5        nU R                  [        S[        S5      R                  5        [        5       nU R                  [        R                  SUR                  5        [        U5      n[        US-  5      nSn[        U[        [        US9n[        5        nUR                  S5      nUR                  5       R!                  5       R#                  S5      n	[%        U	5      SU-   :X  d   eU	S   R'                  S	5      (       d   eU	S   R)                  S
U S35      (       d   e[+        [-        USS5      U	SS 5       H&  u  pSU;   d   eU
S:  a  SOSnSU
 SU S3U;   a  M&   e   UR.                  / SQ:X  d   e SSS5        UW:X  d   e[1        U5        [3        U5      [        S   :X  d   e SSS5        g! , (       d  f       NC= f! , (       d  f       g= f)z?Check that retrying the download works if the hash is differentr      r   r    r*   rI   rJ   retry_if_failedrw   r   r   r+   rY   rZ   rX   NFailed to downloadsr-   zdownload again z
 more time.)r   r   ru                  	   
   r   )r   rx   r   r`   r   r   timer   r   r@   r   r.   r1   r   rK   r/   r|   r0   r2   r}   r~   zipranger   r   r   )r   r4   	fakesleepr*   r]   retriesrL   r7   r8   r9   ilineplurals                r%   test_pooch_download_retryr      s    
	D./"2E2R2RSK	DIIw	@K ./	(G
 ]hIIo.E$$&,,.44T:Dt9G+++7%%m44447##avRL1111uWa4d12h?+t333 !A2(:fXQ?4GGG @
 ??&IIII  E!!!8O#<<<<7 
	 ] 
	s+   BG$C	G1G
3G
G	G
G&c                    [        5        nU R                  [        S[        S5      R                  5        [        U5      n[        U[        [        SS9n[        R                  " [        5       n[        5        nUR                  S5        SSS5        SSS5        WR                  5       R                  5       R!                  S5      n[#        U5      S:X  d   eUS	   R%                  S
5      (       d   eUS	   R'                  SU S35      (       d   eSUS   ;   d   eSUS   ;   d   eS[)        W5      ;   d   e SSS5        g! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       g= f)zFCheck that retrying the download fails after the set amount of retriesr   ru   r   r   r    Nrw   r   r   r+   rY   rZ   r   zdownload again 1 more time.rv   )r   rx   r   r`   r   r   r   r.   r1   ry   rz   r{   r   rK   r/   r|   r0   r2   r}   r~   r@   r   s          r%   *test_pooch_download_retry_fails_eventuallyr     s9    
	D./!2D2Q2QRK (TUV]]:&%(		/*  '   "((*0064yA~~Aw!!-0000Aw!D6----#tAw...,Q777.#e*<<<! 
	  '& 
	s=   A$E'/E:EEB'E'
EE
E$	 E''
E5c                  H   [        5        n [        U 5      nS[        S-   0n[        US[        US9n[        S5       nUR                  S5      nUR                  5       S:X  d   e SSS5        [        W5        SSS5        g! , (       d  f       N"= f! , (       d  f       g= f)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  s     
	K ?!:;XDI$IIo.E$$&",,, % 	 
	 %$ 
	s"   2B(B&B
B	B
B!c                     [        5        n [        U 5      n[        US-  5      n[        USSS9 nUR	                  S5        SSS5        [        U[        [        S9n[        5        nUR                  S5      nUR                  5       nUR                  5       S   S	:X  d   eUR                  5       S
   SU S3:X  d   e SSS5        UW:X  d   e[        U5        [        U5      [        S   :X  d   e[        5        nUR                  S5      nUR                  5       S:X  d   e SSS5        SSS5        g! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       N9= f! , (       d  f       g= f)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  sC    
	K  ./	)S73sII&' 4 (C]hIIo.E$$&D::<?j000::<#4&|333	  E!!!8O#<<<<]hIIo.E$$&",,, ) 
	
 43
 ] ]) 
	sS   %E*D7%E*'AE =E*=(E&E*7
E	E*
E	E*
E'	#E**
E8c                     [        5        n [        U 5      n[        US-  5      n[        USSS9 nUR	                  S5        SSS5        [        U[        [        SS9n[        R                  " [        5         UR                  S5        SSS5        SSS5        g! , (       d  f       N_= f! , (       d  f       N(= f! , (       d  f       g= f)	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   ry   rz   r{   rK   )r4   r*   r]   r   rL   s        r%   test_pooch_update_disallowedr   ^  s    		K  ./	)S73sII&' 4 	
 ]]:&IIo& ' 
	
 43 '& 
	s:   %B=B6B=8B,
B=
B)	%B=,
B:	6B==
Cc                  N   Sn  S[         R                  U '   [        5        n[        U5      n[	        US-  5      n[        USSS9 nUR                  S5        SSS5        [        U[        [        U S	9n[        R                  " [        5         UR                  S5        SSS5        SSS5        [         R                  R                  U 5        g! , (       d  f       N~= f! , (       d  f       NG= f! , (       d  f       NP= f! [         R                  R                  U 5        f = f)
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   ry   rz   r{   rK   pop)variable_namer4   r*   r]   r   rL   s         r%   (test_pooch_update_disallowed_environmentr   r  s    0M&$+

=!![$D D?23Iiw73		*+ 8  !+	C z*		/* + "" 	

}% 87 +* "!" 	

}%sR   D %C2C6C2C! C2(D 
C	C2!
C/	+C22
D <D !D$c                  P    Sn [        U S[        S9nUR                  U S-   :X  d   eg)zJ
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
AC<<8c>)))r'   c                    [        5        n[        R                  R                  U5      n[	        U[
        [        S9n[        5        n[        R                  " [        5       nUR                  S5        SSS5        S[        WR                  5      ;   d   eUR                  5       nUR                  5       S   S:X  d   eUR                  5       S   SU S	3:X  d   e SSS5        SSS5        [	        U [
        [        S9n[        5        n[        R                  " [        5       nUR                  S5        SSS5        S[        WR                  5      ;   d   eUR                  5       nUR                  5       S   S
:X  d   eUR                  5       S   SU  S	3:X  d   e SSS5        g! , (       d  f       GN>= f! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       g= f)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   ry   rz   r{   rK   r@   valuer/   r0   )r&   r4   r*   rL   r7   r   r9   s          r%   test_pooch_corruptedr     s    
	ww{+:LM]hz*e		/* +$EKK(8888$$&D::<?m333::<#4&|333  
 _wAS
TC	(]]:&%IIo& ' C$4444  "zz|A*,,,zz|BQ&7r#:::: 
 +* ] 
	 '& 
sa   =GF>#F,5A)F>GG1'G 9A)G1,
F;6F>>
G	G
G 
G.	*G11
G?c                      [        SS[        S9n [        R                  " [        5         U R                  S5        SSS5        g! , (       d  f       g= f)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   ry   rz   r{   rK   rL   s    r%   test_pooch_file_not_in_registryr     s;    
"-DxC 
z	"		/0 
#	"	"s   A
Ac                      [        SSS9n U R                  [        R                  R	                  [
        S5      5        U R                  [        :X  d   eU R                  R                  5       [        [        5      R                  5       :X  d   eg)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     sg    
R"
%Cbggll8^<=<<8###""$X(;(;(====r'   c                      [        SSS9n U R                  [        R                  R	                  [
        S5      5        U R                  [        :X  d   eU R                  R                  5       [        [        5      R                  5       :X  d   eg)z8Loading the registry from a file and strip line commentsr-   r   zregistry_comments.txtNr   r   s    r%   !test_pooch_load_registry_commentsr     sh    
R"
%Cbggll8-DEF<<8###""$X(;(;(====r'   c                     [         R                  R                  [        S5      n [	        SSS9n[        U S5       nUR                  U5        SSS5        UR                  [        :X  d   eUR                  R                  5       [        [        5      R                  5       :X  d   e[	        SSS9n[        U SSS9 nUR                  U5        SSS5        UR                  [        :X  d   eUR                  R                  5       [        [        5      R                  5       :X  d   eg! , (       d  f       N= f! , (       d  f       Nq= f)	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    77<<.1D R"
%C	dD	S# 
<<8###""$X(;(;(==== R"
%C	dC'	*c# 
+<<8###""$X(;(;(==== 
	 
+	*s   D';D8'
D58
Ec                      [        SSS9n U R                  [        R                  R	                  [
        S5      5        U R                  [        :X  d   eU R                  SS0:X  d   eg)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     sV    
R"
%Cbggll8-FGH<<8###88)JKKKKr'   c                      [        SS0 S9n [        R                  " [        5         U R	                  [
        R                  R                  [        S5      5        SSS5        g! , (       d  f       g= f)z?Should raise an exception when a line doesn't have two elementsr-   rH   zregistry-invalid.txtN)	r   ry   rz   IOErrorr   r<   r*   r   r#   r   s    r%   %test_pooch_load_registry_invalid_liner     sF    
R"r
2C	w	"'',,x1GHI 
 		s   4A##
A1c                      [        SSS9n U R                  [        R                  R	                  [
        S5      5        SU R                  ;   d   eSU R                  ;   d   eg)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     sP    
R"
%Cbggll8-BCD!S\\111"cll222r'   c                  N   [        [        [        [        S9n U R	                  S5      (       d   e[        [        [        S-   [        S9n U R	                  S5      (       a   eSS0nUR                  [        5        [        [        [        US9n U R	                  S5      (       a   eg)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(
CCO,,,,
X,(>
RC0000*N;HOOH
X(
CC :;;;;;r'   c                    [        U S5       n[        [        UR                  SS5      SSS.S9n[	        U R
                  S9nUR                  SUS9(       d   eUR                  S	US9(       a   e S
S
S
5        g
! , (       d  f       g
= f)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/	2c[["5!c%3
 #	(=(=>
JGGG##$7J#OOOO 
3	2	2s   A$A;;
B	c                      S n [        [        [        [        S9nSn[        R
                  " [        US9   UR                  SU S9  SSS5        g! , (       d  f       g= f)z@Should raise an exception if the downloader doesn't support thisc                     g)z,A downloader that doesn't support check_onlyNrs   )r6   outputr?   s      r%   r   >test_check_availability_invalid_downloader.<locals>.downloader  s    r'   rH   z%does not support availability checks.)matchr    r   N)r   r#   r.   r1   ry   rz   NotImplementedErrorr   )r   rL   msgs      r%   *test_check_availability_invalid_downloaderr     sJ     X(
CC
1C	*#	6Z@ 
7	6	6s   A
Ac                    S n[        5        n[        U5      n[        U[        [        S9n[        5        nUR                  SUS9nUR                  5       nUR                  5       n[        U5      S:X  d   eUS   R                  5       S   S:X  d   eUS   S	:X  d   e S
S
S
5        U R                  5       R                  (       a   e[        W5        [        5        nUR                  S5      nUR                  5       S:X  d   e S
S
S
5        S
S
S
5        g
! , (       d  f       N~= f! , (       d  f       N(= f! , (       d  f       g
= f)z%Setup a downloader function for fetchc                 X    [        5       R                  S5        [        5       " XU5        g)z2Download through HTTP and warn that we're doing itdownloader executedN)r   infor   )r6   output_filerL   s      r%   download,test_fetch_with_downloader.<locals>.download#  s     /03/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
 
	K (C]hII.8IDE$$&DOO%Eu:?"?8>>#A&-77784444  $$&****]hII./E$$&",,, # 
	
 ] ]# 
	s;   )D;A)D!>D;(D*D;
D'	#D;*
D8	4D;;
E	c                     [        U [        SS0S9n[        R                  " [        5       nUR                  S5        SSS5        S[        WR                  5      ;   d   eg! , (       d  f       N*= f)z!Test an invalid hashing algorithmr    z	blah:1234rH   Nz'blah')r   r.   ry   rz   r{   rK   r@   r   )r&   rL   excs      r%   test_invalid_hash_algr  >  sZ    
w/;9WC 
z	"c		/" 
# s399~%%% 
#	"s   A""
A0c                    [        U S-  5      n[        U5        [        US5       nUR                  5       nSSS5        S Hm  n[        R
                  " U5      nUR                  W5        SU SUR                  5        30n[        U SUS9nXR                  S5      :X  d   e[        U5        Mo     g! , (       d  f       N= f)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  s    /12EE	eT	cxxz 
 S!d#uAf.>.>.@-A%BC3ChW		/2222 ! 
	s   B33
Cc                     [        [        S5      SS9u  pU S:X  d   eUS:X  d   e[        5        n[        [        U5      SS9u  pSSS5        U S:X  d   eUS:X  d   e[        5        n[        US	S
S9 nUR	                  S5        SSS5        [        [        U5      [        U5      S9u  pSSS5        U S:X  d   eUS:X  d   eg! , (       d  f       N= f! , (       d  f       NV= f! , (       d  f       NA= f)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    "+,LF Z=   		S&tCy=ST 
X:		S#sW-LL% .&tCyYs^L 
 W: 
	 .- 
	s/   C(C'4C&C'
C
C$	 C''
C5r8   zsubdir/tiny-data.txtc           	      @   [         S-   U -   n[        U    n[        5       n[        5        n[	        U5      U -  nUR                  5       (       a   e[        XX#SS9  UR                  5       (       d   e[        [        U5      5        SSS5        g! , (       d  f       g= f)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		;'%/%%''''*M!!####K() 
		s   AB
B)rQ   rR   rS   c                    [        5        n[        R                  R                  U5      n[	        X S9nUR                  5         [        UR                  5      S:X  d   eSUR                  ;   d   eSUR                  ;   d   eUR                   H  nUR                  U5        M     SSS5        g! , (       d  f       g= f)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     
	ww{+,""$ 3<< A%%%#,,...cll*** HIIh % 
		s   BB00
B>c                  j   [         n [        5        n[        R                  R	                  U5      n[        X S9nUR                  5         [        UR                  5      S:X  d   eSUR                  ;   d   eUR                   H  nUR                  U5        M     SSS5        g! , (       d  f       g= f)zg
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		ww{+,""$ 3<< A%%%2cllBBB HIIh % 
		s   B
B$$
B2c                      [        S[        S9n [        R                  " [        5       nU R                  5         SSS5        S[        WR                  5      ;   d   eg! , (       d  f       N*= f)z(Check that non-DOI URLs produce an errorr-   r   Nzonly implemented for DOIs)r   r.   ry   rz   r{   r!  r@   r   )rL   r
  s     r%   !test_wrong_load_registry_from_doir)    sP     R'
*C	z	"c""$ 
# '#cii.888 
#	"s   A
A,)Yrq   r  r<   pathlibr   tempfiler   ry   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)  rs   r'   r%   <module>r9     s    	  '  L L 8 8 ,  7    tH~$$v-. 

%'!#	46 ') W  0 0 - -2 7 7$ . .. 	[(<(<=	 	5  	-	 -( 	[(<(<=	 	5  	-	 -.- -  . .&    = =@ = =*   - -6'(&2* ; ;01>>>&LJ3 < <P$
A - -<&* ?4J"KL* M * 	\\+V[[%9%9:I|T+  
   "    (9r'   