U
    `»{j]+  ã                   @   s  d Z ddlmZ ddlmZ ddlZddlZddlmZ ddl	m
Z
mZmZ dd	lmZmZmZmZ eƒ Zeƒ Zejjejjd
ddddddgddddddgd�dd„ ƒƒZejjdd„ ƒZejjejjdddgddgd�ejjd d!d"gfd#d$d%gfd$d&gfd$d'gfd$d%d'gfgd(d)d*d+d,d-gd�ejjd.e
d/fed0fgd1d2gd�d3d4„ ƒƒƒƒZejjej d.e
d/fed0fg¡d5d6„ ƒƒZejjej d.e
d/fed0fg¡d7d8„ ƒƒZd9d:„ Zd;d<„ Zejjej d.e
d/fed0fg¡d=d>„ ƒƒZejjej d.e
d/fed0fg¡d?d@„ ƒƒZdS )Az
Test the processor hooks
é    )ÚPath)ÚTemporaryDirectoryNé   )ÚPooch)ÚUnzipÚUntarÚ
Decompressé   )Úpooch_test_urlÚpooch_test_registryÚcheck_tiny_dataÚcapture_logzmethod,ext,name)ÚautoÚxzN)Úlzmar   N)r   r   N)Úbzip2Úbz2N)ÚgzipÚgzN)r   r   zdifferent-name.txtr   r   r   r   r   Úname)Zidsc              
   C   sF  t | |d�}tƒ ��(}t|ƒ}|dkr@t|d d|dg¡ ƒ}nt|| ƒ}t|ttd�}tƒ �r}|j	d| |d�}	| 
¡ }
|
 ¡ }t|ƒd	ks”t‚|d
  ¡ d
 dks¬t‚|d  d¡s¾t‚| |d ksÎt‚W 5 Q R X |	|ksät‚t|	ƒ tƒ �*}|j	d| |d�}	| 
¡ dk�st‚W 5 Q R X |	|k�s0t‚t|	ƒ W 5 Q R X dS )z=Check that decompression after download works for all formats)Úmethodr   NÚ.útiny-data.txtÚdecomp©ÚpathÚbase_urlÚregistryztiny-data.txt.©Ú	processorr   r   ÚDownloadingéÿÿÿÿZDecompressingÚ )r   r   r   ÚstrÚjoinr   ÚBASEURLÚREGISTRYr   ÚfetchÚgetvalueÚ
splitlinesÚlenÚAssertionErrorÚsplitÚ
startswithr   )r   Úextr   r   Úlocal_storer   Ú	true_pathÚpupÚlog_fileÚfnameZlogsÚlines© r5   úZ/var/www/html/bwave/python/venv/lib/python3.8/site-packages/pooch/tests/test_processors.pyÚtest_decompress   s,    
r7   c                  C   sÖ  t ƒ ��Ä} t| ƒ}t|ttd�}t t¡�.}t 	¡ � |j
dtdd�d� W 5 Q R X W 5 Q R X |jjd  d¡stt‚d|jjd ksˆt‚t t¡�.}t 	¡ � |j
dtd	d�d� W 5 Q R X W 5 Q R X |jjd  d
¡sÜt‚d|jjd ksðt‚t t¡�.}t 	¡ � |j
dtdd�d� W 5 Q R X W 5 Q R X |jjd  d¡�sFt‚d|jjd k�s\t‚t t¡�.}t 	¡ � |j
dtdd�d� W 5 Q R X W 5 Q R X |jjd  d¡�s²t‚d|jjd k�sÈt‚W 5 Q R X dS )zGShould fail if method='auto' and no extension is given in the file namer   r   r   )r   r   r   z"Unrecognized file extension '.txt'zpooch.Unzip/UntarZblaz Invalid compression method 'bla'Úzipz Invalid compression method 'zip'z	store.zipz"Unrecognized file extension '.zip'N)r   r   r   r%   r&   ÚpytestZraisesÚ
ValueErrorÚwarningsÚcatch_warningsr'   r   ÚvalueÚargsr-   r+   )r/   r   r1   Ú	exceptionr5   r5   r6   Útest_decompress_failsE   s.    

(
(
(
(r@   Útarget_pathZsome_custom_pathZdefault_pathZcustom_pathzarchive,membersú	tiny-datar   )ÚstoreNrC   ústore/tiny-data.txtústore/subdir/tiny-data.txtzstore/subdirZsingle_fileZarchive_allZarchive_fileZarchive_subdir_fileZarchive_subdirZarchive_multiplezprocessor_class,extensionz.zipz.tar.gzr   r   c              
   C   s  | ||d�}|dkr"|| |j  }tƒ �Ô}t|ƒ}t|||| | jƒ\}}t|ttd�}	tƒ �2}
|	j	|| |d�}t
|ƒ|ks‚t‚t|
|ƒ W 5 Q R X |D ]}t|ƒ qštƒ �2}
|	j	|| |d�}t
|ƒ|ksÒt‚t|
g ƒ W 5 Q R X |D ]}t|ƒ qêW 5 Q R X dS )zGTests the behaviour of processors for unpacking archives (Untar, Unzip))ÚmembersÚextract_dirNr   r   )Úsuffixr   r   Ú"_unpacking_expected_paths_and_logsÚ__name__r   r%   r&   r   r'   Úsetr+   Ú_check_logsr   )Úprocessor_classÚ	extensionrA   ÚarchiverF   r   r   Ú
true_pathsZexpected_logr1   r2   Úfnamesr3   r5   r5   r6   Útest_unpackingd   s0       ÿ
rR   c           	   	   C   sØ   t ƒ �È}tt|ƒttd�}| dgd�}|jd| |d�}t|ƒdksHt‚t|d ƒ | ddgd�}|jd| |d�}t|ƒd	ks„t‚t|d ƒ t|d ƒ |jd| |d�}t|ƒdks¾t‚t|d ƒ W 5 Q R X d
S )zHTest that multiple subsequent calls to a processor yield correct resultsr   rD   ©rF   rC   r   r	   r   rE   r   N©	r   r   r   r%   r&   r'   r*   r+   r   )	rM   rN   r/   r1   Ú
processor1Ú
filenames1Ú
processor2Ú
filenames2Z
filenames3r5   r5   r6   Útest_multiple_unpackingœ   s     ÿrY   c              	   C   sb   t ƒ �R}tt|ƒttd�}| dgd�}|jd| |d�}t|ƒdksHt‚t|d ƒ W 5 Q R X dS )	zDTest that unpack members can also be specifed both with a leading ./r   z./store/tiny-data.txtrS   rC   r   r	   r   NrT   )rM   rN   r/   r1   rU   rV   r5   r5   r6   Ú$test_unpack_members_with_leading_dot½   s    rZ   c                 C   sF   |   ¡  ¡ }t|ƒt|ƒks t‚t||ƒD ]\}}| |¡s*t‚q*dS )zC
    Assert that the lines in the log match the expected ones.
    N)r(   r)   r*   r+   r8   r-   )r2   Zexpected_linesr4   ÚlineZexpected_liner5   r5   r6   rL   Ï   s    rL   c                 C   sì   dg}| dkr(t |d ƒh}| d¡ n¼| dkrv|dkrvt |d d ƒt |d d d ƒh}| |› |d › d	�¡ nn| dkrä|dk	räg }|D ]L}|t| d
¡Ž  }t |ƒ d¡sº|d }| t |ƒ¡ | d|› d�¡ qŽt|ƒ}||fS )zo
    Generate the appropriate expected paths and log message depending on the
    parameters for the test.
    r    rB   r   zExtracting 'tiny-data.txt'rC   NÚsubdirr!   zing contentsú/zExtracting 'ú')r#   Úappendr   r,   ÚendswithrK   )rO   rF   r   r   Z	log_linesrP   Úmemberr0   r5   r5   r6   rI   Ù   s&    þrI   c              	   C   s~   t ƒ �n}tt|ƒttd�}| dgd�}|jd| |d�}t|ƒdksHt‚| ƒ }|jd| |d�}t|ƒdkspt‚W 5 Q R X dS )zx
    Test that calling with valid members then without them works.
    https://github.com/fatiando/pooch/issues/364
    r   rD   rS   rC   r   r	   N©r   r   r   r%   r&   r'   r*   r+   ©rM   rN   r/   r1   rU   rV   rW   rX   r5   r5   r6   Ú&test_unpacking_members_then_no_membersô   s    
rd   c              	   C   s~   t ƒ �n}tt|ƒttd�}| dgd�}|jd| |d�}t|ƒdksHt‚| ƒ }|jd| |d�}t|ƒdkspt‚W 5 Q R X dS )zz
    Test that calling with invalid members then without them works.
    https://github.com/fatiando/pooch/issues/364
    r   znot-a-valid-file.csvrS   rC   r   r   Nrb   rc   r5   r5   r6   Ú,test_unpacking_wrong_members_then_no_members  s    
re   ) Ú__doc__Úpathlibr   Útempfiler   r;   r9   r"   r   Z
processorsr   r   r   Úutilsr
   r   r   r   r&   r%   ÚmarkÚnetworkZparametrizer7   r@   rR   rY   rZ   rL   rI   rd   re   r5   r5   r5   r6   Ú<module>   sž   úö
  ÿ
ú	úöýþþ
þþ