U
    5dR'                     @   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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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d0e
d1fed2fgd3d4gdd5d6 Zejjejd0e
d1fed2fgd7d8 Zejjejd0e
d1fed2fgd9d: Zd;d< Zd=d> ZdS )?z
Test the processor hooks
    )Path)TemporaryDirectoryN   )Pooch)UnzipUntarExtractorProcessor
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)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st|d
  d
 dkst|d dst| |d kstW 5 Q R X |	|kst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   DownloadingZ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 r7   ?/tmp/pip-unpacked-wheel-nxrj6sbx/pooch/tests/test_processors.pytest_decompress   s,    
r9   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sttt.}t	  |j
dtd	dd W 5 Q R X W 5 Q R X |jjd d
std|jjd kst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std|jjd kst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(   pytestraises
ValueErrorwarningscatch_warningsr)   r	   valueargsr/   r-   )r1   r   r3   	exceptionr7   r7   r8   test_decompress_failsE   s.    

(
(
(
(rC   c               
   C   s   t  } tt| ttd}t }tt}|j	d|d W 5 Q R X d|j
jd ksXtd|_tt}|j	d|d W 5 Q R X |j
jrtW 5 Q R X dS )zBThe base class should be used and should fail when passed to fecthr   ztiny-data.tar.gzr    z'suffix'r   ztar.gzN)r   r   r   r'   r(   r   r;   r<   NotImplementedErrorr)   r@   rA   r-   suffix)r1   r3   r!   rB   r7   r7   r8   test_extractprocessor_failsd   s    rF   target_pathZsome_custom_pathZdefault_pathZcustom_pathzarchive,members	tiny-datar   )storeNrI   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stt|
| W 5 Q R X |D ]}t| qt 2}
|	j	|| |d}t
||kstt|
g  W 5 Q R X |D ]}t| qW 5 Q R X dS )zGTests the behaviour of processors for unpacking archives (Untar, Unzip))membersextract_dirNr   r    )rE   r   r   "_unpacking_expected_paths_and_logs__name__r   r'   r(   r   r)   setr-   _check_logsr   )processor_class	extensionrG   archiverL   r!   r   
true_pathsZexpected_logr3   r4   fnamesr5   r7   r7   r8   test_unpackingt   s0       
rW   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stt|d  t|d  |jd| |d}t|dkstt|d  W 5 Q R X d
S )zHTest that multiple subsequent calls to a processor yield correct resultsr   rJ   rL   rI   r    r
   r   rK   r   N	r   r   r   r'   r(   r)   r,   r-   r   )	rR   rS   r1   r3   
processor1
filenames1Z
processor2Z
filenames2Z
filenames3r7   r7   r8   test_multiple_unpacking   s     r\   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.txtrX   rI   r    r
   r   NrY   )rR   rS   r1   r3   rZ   r[   r7   r7   r8   $test_unpack_members_with_leading_dot   s    r]   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-   r:   r/   )r4   Zexpected_linesr6   lineZexpected_liner7   r7   r8   rQ      s    rQ   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	rg }|D ]L}|t|d
  }t |ds|d }|t | |d| d qt|}||fS )zo
    Generate the appropriate expected paths and log message depending on the
    parameters for the test.
    r"   rH   r   zExtracting 'tiny-data.txt'rI   Nsubdirr#   zing contents/zExtracting '')r%   appendr   r.   endswithrP   )rT   rL   r   r   Z	log_linesrU   memberr2   r7   r7   r8   rN      s&    rN   ) __doc__pathlibr   tempfiler   r>   r;   r$   r   Z
processorsr   r   r   r	   utilsr   r   r   r   r(   r'   marknetworkZparametrizer9   rC   rF   rW   r\   r]   rQ   rN   r7   r7   r7   r8   <module>   s   

  
	
