U
    9%eR'                     @   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)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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 r6   Z/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/pooch/tests/test_processors.pytest_decompress   s,    
r8   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,   )r0   r   r2   	exceptionr6   r6   r7   test_decompress_failsE   s.    

(
(
(
(rB   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?   r@   r,   suffix)r0   r2   r    rA   r6   r6   r7   test_extractprocessor_failsd   s    rE   target_pathZsome_custom_pathZdefault_pathZcustom_pathzarchive,members	tiny-datar   )storeNrH   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   )rD   r   r   "_unpacking_expected_paths_and_logs__name__r   r&   r'   r   r(   setr,   _check_logsr   )processor_class	extensionrF   archiverK   r    r   
true_pathsZexpected_logr2   r3   fnamesr4   r6   r6   r7   test_unpackingt   s0       
rV   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   rI   rK   rH   r   r
   r   rJ   r   N	r   r   r   r&   r'   r(   r+   r,   r   )	rQ   rR   r0   r2   
processor1
filenames1Z
processor2Z
filenames2Z
filenames3r6   r6   r7   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.txtrW   rH   r   r
   r   NrX   )rQ   rR   r0   r2   rY   rZ   r6   r6   r7   $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,   r9   r.   )r3   Zexpected_linesr5   lineZexpected_liner6   r6   r7   rP      s    rP   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!   rG   r   zExtracting 'tiny-data.txt'rH   Nsubdirr"   zing contents/zExtracting '')r$   appendr   r-   endswithrO   )rS   rK   r   r   	log_linesrT   memberr1   r6   r6   r7   rM      s&    rM   ) __doc__pathlibr   tempfiler   r=   r:   r#   r   Z
processorsr   r   r   r	   utilsr   r   r   r   r'   r&   marknetworkZparametrizer8   rB   rE   rV   r[   r\   rP   rM   r6   r6   r6   r7   <module>   s   

  
	
