o
    a&i                     @   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
g dg d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g d dejjd!e
d"fed#fgd$d%gdd&d' 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.txt)r   r   r   r   r   name)Zidsc              	   C   s~  t | |d}t }t|}|du rt|dd|dg }nt|| }t|ttd}t >}|j	d| |d}	|
 }
|
 }t|d	ksIJ |d
  d
 dksUJ |d ds^J | |d v sfJ W d   n1 spw   Y  |	|ks{J t|	 t }|j	d| |d}	|
 dksJ W d   n1 sw   Y  |	|ksJ t|	 W d   dS 1 sw   Y  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split
startswithr   )r   extr   r    local_storer   	true_pathpuplog_filefnameZlogslines r5   FC:\wamp64\www\opt\env\Lib\site-packages\pooch/tests/test_processors.pytest_decompress   s2   
"r7   c               
   C   s  t  8} t| }t|ttd}tt&}t	  |j
dtddd W d   n1 s/w   Y  W d   n1 s>w   Y  |jjd dsNJ d	|jjd vsXJ tt&}t	  |j
dtd
dd W d   n1 sww   Y  W d   n1 sw   Y  |jjd dsJ d	|jjd vsJ tt&}t	  |j
dtddd W d   n1 sw   Y  W d   n1 sw   Y  |jjd dsJ d	|jjd v sJ tt'}t	  |j
dtddd W d   n	1 sw   Y  W d   n	1 sw   Y  |jjd ds)J d	|jjd v s4J W d   dS 1 s@w   Y  dS )zGShould fail if method='auto' and no extension is given in the file namer   r   r   )r   r   Nr   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')r   r   r   r&   r'   pytestraises
ValueErrorwarningscatch_warningsr(   r	   valueargsr-   )r/   r   r1   	exceptionr5   r5   r6   test_decompress_failsE   sH   




$rA   c               	   C   s   t  `} tt| ttd}t }tt}|j	d|d W d   n1 s'w   Y  d|j
jd v s6J d|_tt}|j	d|d W d   n1 sPw   Y  |j
jr[J W d   dS 1 sfw   Y  dS )zBThe base class should be used and should fail when passed to fecthr   ztiny-data.tar.gzr   Nz'suffix'r   ztar.gz)r   r   r   r&   r'   r   r9   r:   NotImplementedErrorr(   r>   r?   suffix)r/   r1   r    r@   r5   r5   r6   test_extractprocessor_failsd   s   "rD   target_pathZsome_custom_pathZdefault_pathZcustom_pathzarchive,members	tiny-datar   )storeNrG   zstore/tiny-data.txtzstore/subdir/tiny-data.txtzstore/subdir)Zsingle_fileZarchive_allZarchive_fileZarchive_subdir_fileZarchive_subdirZarchive_multiplezprocessor_class,extensionz.zipz.tar.gzr   r   c              	   C   sD  | ||d}|du r|| |j  }t }t|}t|||| | j\}}t|ttd}	t }
|	j	|| |d}t
||ksAJ t|
| W d   n1 sPw   Y  |D ]}t| qWt }
|	j	|| |d}t
||kssJ t|
g  W d   n1 sw   Y  |D ]}t| qW d   dS 1 sw   Y  dS )zGTests the behaviour of processors for unpacking archives (Untar, Unzip))membersextract_dirNr   r   )rC   r   r   "_unpacking_expected_paths_and_logs__name__r   r&   r'   r   r(   set_check_logsr   )Zprocessor_class	extensionrE   archiverH   r    r   
true_pathsZexpected_logr1   r2   fnamesr3   r5   r5   r6   test_unpackingt   s2   

"rR   c                 C   sF   |    }t|t|ksJ t||D ]\}}||s J qdS )zC
    Assert that the lines in the log match the expected ones.
    N)r)   r*   r+   r8   r-   )r2   Zexpected_linesr4   lineZexpected_liner5   r5   r6   rM      s
   rM   c                 C   s   dg}| dkrt |d h}|d ||fS | dkrA|du rAt |d d t |d d d h}|| |d  d	 ||fS | dkrx|durxg }|D ]&}|t|d
  }t |dsc|d }|t | |d| d qMt|}||fS )zo
    Generate the appropriate expected paths and log message depending on the
    parameters for the test.
    r!   rF   r   zExtracting 'tiny-data.txt'rG   Nsubdirr"   zing contents/zExtracting '')r$   appendr   r,   endswithrL   )rO   rH   r   r   	log_linesrP   memberr0   r5   r5   r6   rJ      s*   

rJ   )__doc__pathlibr   tempfiler   r<   r9   r#   r   Z
processorsr   r   r   r	   utilsr   r   r   r   r'   r&   marknetworkZparametrizer7   rA   rD   rR   rM   rJ   r5   r5   r5   r6   <module>   sX   



