
    S3jg              	          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%      jL                  dz        Z' e       Z( e       Z) e       Z* e       Z+ e       Z, e       Z-ddiZ.ej^                  d        Z0ejb                  jd                  d        Z3ejb                  jd                  d        Z4ejb                  jd                  d        Z5d Z6ejb                  jd                  ejb                  jo                  de) ejp                  e*ejb                  jr                        e+e-gg d      d               Z:ejb                  jd                  ejb                  jo                  de) ejp                  e*ejb                  jr                        e+e-gg d      d               Z; G d d      Z<ejb                  jd                  d        Z= G d d      Z>ejb                  jd                  d         Z?ejb                  jd                  d!        Z@ejb                  jd                  d"        ZAejb                  jd                  d#        ZBd$ ZCd% ZDd& ZEejb                  jd                  d'        ZFd( ZGd) ZHd* ZId+ ZJd, ZKd- ZLd. ZMejb                  jd                  d/        ZNd0 ZOd1 ZPejb                  jd                  d2        ZQd3 ZRd4 ZSd5 ZTejb                  jd                  ejb                  jo                  d6dd7g      d8               ZUejb                  jd                  ejb                  jo                  d ejp                  e*ejb                  jr                        e+e-gg d9      d:               ZVejb                  jd                  d;        ZWd< ZXy)=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    B/DATA/.local/lib/python3.12/site-packages/pooch/tests/test_core.pydata_dir_mirrorr&   5   s     Hh//    c                     t               5 } d}t        |z   }t               5 }t        |d|       }|j	                         }|j                         d   dk(  sJ d|v sJ t        |   |v sJ 	 ddd       |t        |       d k(  sJ t        |       t        |      t        |   k(  sJ t               5 }t        |d|       }|j	                         dk(  sJ 	 ddd       t               5 }t        |t        |   |       }|j	                         dk(  sJ 	 ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   \xY w# 1 sw Y   *xY w# 1 sw Y   yxY w)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4$D4E++E E(D1	-E4D=	9E E		EEc                     t               5 } d}t        |z   }t               5 }t        |d| |      }|j	                         }|j                         d   dk(  sJ d|v sJ t        |   |v sJ 	 ddd       |t        j                  j                        d   k(  sJ t        |       t        |      t        |   k(  sJ 	 ddd       y# 1 sw Y   \xY w# 1 sw Y   yxY w)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9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                     d} t         | z   }t        d      | z  }	 t               5 }t        |d|       }|j	                         }|j                         d   dk(  sJ t        t        d      j                               |v sJ d|v sJ t        |    |v sJ 	 ddd       t        |j                               k(  sJ t        |       t        |      t        |    k(  sJ 	 t        j                  j                  t        |            rt        j                  t        |             yy# 1 sw Y   xY w# t        j                  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   sN     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IIc+,- 2 ] 77>>#/01IIc+,- 2s%   
D3 A0D'AD3 'D0,D3 3A	E<c                     t        | dt              }t        | dz        }|j                  d      }||k(  sJ t	        |       y)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      sB    
_/?(
SC0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 }|j                  d      }|j                         }|j                         d   dk(  sJ |j                         d   d| dk(  sJ 	 d	d	d	       t               t	               5 }|j                  d      }|j                         dk(  sJ 	 d	d	d	       d	d	d	       y	# 1 sw Y   WxY w# 1 sw Y   xY w# 1 sw Y   y	xY w)
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;   0D AC(D /'C4D (C1	-D 4C=	9D  D	c                 `   t               5 }t        |      }t        |dz        }t        || t              }t               5 }|j                  d      }|j                         }|j                         d   dk(  sJ |j                         d   d| dk(  sJ 	 ddd       |k(  sJ t        |       t        |      t        d   k(  sJ t               5 }|j                  d      }|j                         d	k(  sJ 	 ddd       ddd       y# 1 sw Y   uxY w# 1 sw Y   xY w# 1 sw Y   yxY w)
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<   6D$AD;D$'D;D$D	D$D!	D$$D-c                       e Zd ZdZd Zd Zy)FakeHashMatchesz8Create a fake version of hash_matches that fails n timesc                      || _         d| _        y )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   sF    ;;'KK1KQ9&99T,V,,r'   N)__name__
__module____qualname____doc__re   r    r'   r%   r`   r`      s    >-r'   r`   c                    t               5 }| j                  t        dt        d      j                         t        |      }t        |t        t              }t        j                  t              5 }t               5 }|j                  d       ddd       ddd       dt              v sJ j                         j!                         j#                  d      }t%        |      dk(  sJ |d	   j'                  d
      sJ |d	   j)                  d| d      sJ 	 ddd       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   yxY w)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Aw!D6--- 
	  '& 
	s=   A%D;0D/;D#D/BD;#D,(D//D8	4D;;Ec                       e Zd ZdZd Zd Zy)	FakeSleepz<Create a fake version of sleep that logs the specified timesc                     g | _         y )N)times)rd   s    r%   re   zFakeSleep.__init__   s	    
r'   c                 :    | j                   j                  |       y)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      s    B r'   r   c           	         t               5 }| j                  t        dt        d      j                         t               }| j                  t        j                  d|j                         t        |      }t        |dz        }d}t        |t        t        |      }t               5 }|j                  d      }|j                         j!                         j#                  d      }	t%        |	      d|z   k(  sJ |	d   j'                  d	      sJ |	d   j)                  d
| d      sJ t+        t-        |dd      |	dd       D ]!  \  }
}d|v sJ |
dkD  rdnd}d|
 d| d|v r!J  |j.                  g dk(  sJ 	 ddd       |k(  sJ t1        |       t3        |      t        d   k(  sJ 	 ddd       y# 1 sw Y   <xY w# 1 sw Y   yxY w)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./"2E2R2RSK	DIIw	@K ./	(G
 ]hIIo.E$$&,,.44T:Dt9G+++7%%m4447##avRL111uWa4d12h?4+t333 !A2(:fXQ?4GGG @
 ??&IIII  E!!!8O#<<<<7 
	 ] 
	s+   BG'B<F6$F6;1G6F?	;GGc                    t               5 }| j                  t        dt        d      j                         t        |      }t        |t        t        d      }t        j                  t              5 }t               5 }|j                  d       ddd       ddd       j                         j                         j!                  d      }t#        |      dk(  sJ |d	   j%                  d
      sJ |d	   j'                  d| d      sJ d|d   v sJ d|d   v sJ dt)              v sJ 	 ddd       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   yxY w)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     s3    
	D./!2D2Q2QRK (TUV]]:&%(		/*  '   "((*0064yA~~Aw!!-000Aw!D6---#tAw...,Q777.#e*<<<! 
	  '& 
	s=   A&E1E<D6EBE6D?;EE	EEc                  8   t               5 } t        |       }dt        dz   i}t        |dt        |      }t        d      5 }|j                  d      }|j                         dk(  sJ 	 ddd       t               ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)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#   5B 'B(BB		BBc                     t               5 } t        |       }t        |dz        }t        |dd      5 }|j	                  d       ddd       t        |t        t              }t               5 }|j                  d      }|j                         }|j                         d   d	k(  sJ |j                         d
   d| dk(  sJ 	 ddd       |k(  sJ t        |       t        |      t        d   k(  sJ t               5 }|j                  d      }|j                         dk(  sJ 	 ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   *xY w# 1 sw Y   yxY w)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D8(E-AE;E?'E'E8E	=EE		EE	EE%c                     t               5 } t        |       }t        |dz        }t        |dd      5 }|j	                  d       ddd       t        |t        t        d      }t        j                  t              5  |j                  d       ddd       ddd       y# 1 sw Y   \xY w# 1 sw Y   xY w# 1 sw Y   yxY w)	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3sII&' 4 	
 ]]:&IIo& ' 
	
 43 '& 
	s:   (B8B 8B8=B,B8 B)	%B8,B5	1B88Cc                  :   d} 	 dt         j                  | <   t               5 }t        |      }t	        |dz        }t        |dd      5 }|j                  d       ddd       t        |t        t        | 	      }t        j                  t              5  |j                  d       ddd       ddd       t         j                  j                  |        y# 1 sw Y   {xY w# 1 sw Y   =xY w# 1 sw Y   AxY w# t         j                  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3Iiw73		*+ 8  !+	C z*		/* + "" 	

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

}%sR   C9 (C-	C8C-C!%C--C9 C	C-!C*	&C--C62C9 9!Dc                  T    d} t        | dt              }|j                  | dz   k(  sJ y)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
AC<<8c>)))r'   c                    t               5 }t        j                  j                  |      }t	        |t
        t              }t               5 }t        j                  t              5 }|j                  d       ddd       dt        j                        v sJ |j                         }|j                         d   dk(  sJ |j                         d   d| d	k(  sJ 	 ddd       ddd       t	        | t
        t              }t               5 }t        j                  t              5 }|j                  d       ddd       dt        j                        v sJ |j                         }|j                         d   d
k(  sJ |j                         d   d|  d	k(  sJ 	 ddd       y# 1 sw Y   3xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   yxY w)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     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#:::: 
 +* ] 
	 '& 
sb   A GF5%F(7A%F5GG'G9A%G(F2-F55F>	:GG
G	GG"c                      t        ddt              } t        j                  t              5  | j                  d       ddd       y# 1 sw Y   yxY w)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	"		/0 
#	"	"s   AAc                  "   t        dd      } | j                  t        j                  j	                  t
        d             | j                  t        k(  sJ | j                  j                         t        t              j                         k(  sJ y)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                  "   t        dd      } | j                  t        j                  j	                  t
        d             | j                  t        k(  sJ | j                  j                         t        t              j                         k(  sJ y)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                     t         j                  j                  t        d      } t	        dd      }t        | d      5 }|j                  |       ddd       |j                  t        k(  sJ |j                  j                         t        t              j                         k(  sJ t	        dd      }t        | dd      5 }|j                  |       ddd       |j                  t        k(  sJ |j                  j                         t        t              j                         k(  sJ y# 1 sw Y   xY w# 1 sw Y   exY w)	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                      t        dd      } | j                  t        j                  j	                  t
        d             | j                  t        k(  sJ | j                  ddik(  sJ y)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                      t        ddi       } t        j                  t              5  | j	                  t
        j                  j                  t        d             ddd       y# 1 sw Y   yxY w)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     sF    
R"r
2C	w	"'',,x1GHI 
 		s   4A%%A.c                      t        dd      } | j                  t        j                  j	                  t
        d             d| j                  v sJ d| j                  v sJ y)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                  B   t        t        t        t              } | j	                  d      sJ t        t        t        dz   t              } | j	                  d      rJ ddi}|j                  t               t        t        t        |      } | j	                  d      rJ y)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*N;HOOH
X(
CC :;;;;r'   c                    t        | d      5 }t        t        |j                  dd      ddd      }t	        | j
                        }|j                  d|      sJ |j                  d	|      rJ 	 d
d
d
       y
# 1 sw Y   y
xY w)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                      d } t        t        t        t              }d}t	        j
                  t        |      5  |j                  d|        ddd       y# 1 sw Y   yxY w)z@Should raise an exception if the downloader doesn't support thisc                      y)z,A downloader that doesn't support check_onlyNrn   )r6   outputr?   s      r%   r   z>test_check_availability_invalid_downloader.<locals>.downloader  s    r'   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     sJ     X(
CC
1C	*#	6Z@ 
7	6	6s   AA!c                 t   d }t               5 }t        |      }t        |t        t              }t               5 }|j                  d|      }|j                         }|j                         }t        |      dk(  sJ |d   j                         d   dk(  sJ |d   d	k(  sJ 	 d
d
d
       | j                         j                  rJ t               t               5 }|j                  d      }|j                         dk(  sJ 	 d
d
d
       d
d
d
       y
# 1 sw Y   sxY w# 1 sw Y   xY w# 1 sw Y   y
xY w)z%Setup a downloader function for fetchc                 Z    t               j                  d        t               | ||       y)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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
 
	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$9D.'D"D.D	D."D+	'D..D7c                     t        | t        ddi      }t        j                  t              5 }|j                  d       ddd       dt        j                        v sJ y# 1 sw Y   #xY w)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   >  sZ    
w/;9WC 
z	"c		/" 
# s399~%%% 
#	"s   A""A+c                 ~   t        | dz        }t        |       t        |d      5 }|j                         }ddd       dD ]n  }t	        j
                  |      }|j                         d| d|j                          i}t        | d|      }||j                  d      k(  sJ t        |       p y# 1 sw Y   }xY w)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B<c                     t        t        d      d      \  } }| dk(  sJ |dk(  sJ t               5 }t        t        |      d      \  } }ddd       | dk(  sJ |dk(  sJ t               5 }t        |d	d
      5 }|j	                  d       ddd       t        t        |      t        |            \  } }ddd       | dk(  sJ |dk(  sJ y# 1 sw Y   xY w# 1 sw Y   NxY w# 1 sw Y   0xY w)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=   		S&tCy=ST 
X:		S#sW-LL% .&tCyYs^L 
 W: 
	 .- 
	s/   C,C&;C*C&CC#	C&&C/r8   zsubdir/tiny-data.txtc                 ,   t         dz   | z   }t        |    }t               }t               5 }t	        |      | z  }|j                         rJ t        ||||d       |j                         sJ t        t        |             ddd       y# 1 sw Y   yxY w)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!!###K() 
		s   AB

B)rQ   rR   rS   c                 t   t               5 }t        j                  j                  |      }t	        ||       }|j                          t        |j                        dk(  sJ d|j                  v sJ d|j                  v sJ |j                  D ]  }|j                  |        	 ddd       y# 1 sw Y   yxY w)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B..B7c                  `   t         } t               5 }t        j                  j	                  |      }t        ||       }|j                          t        |j                        dk(  sJ d|j                  v sJ |j                  D ]  }|j                  |        	 ddd       y# 1 sw Y   yxY w)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		ww{+,""$ 3<< A%%%2cllBBB HIIh % 
		s   B	B$$B-c                      t        dt              } t        j                  t              5 }| j                          ddd       dt        j                        v sJ y# 1 sw Y   #xY w)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    sP     R'
*C	z	"c""$ 
# '#cii.888 
#	"s   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 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\\+V[[%9%9:I|T+  
   "    (9r'   