o
    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 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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ejjejde
d fed!fgd&d' Zejjejde
d fed!fgd(d) Zd*d+ Zd,d- Zejjejde
d fed!fgd.d/ Zejjejde
d fed!fgd0d1 ZdS )2z
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.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 r4   j/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/pooch/tests/test_processors.pytest_decompress   s2   
"r6   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&   pytestZraises
ValueErrorwarningscatch_warningsr'   r   valueargsr,   )r.   r   r0   	exceptionr4   r4   r5   test_decompress_failsE   sH   




$r?   target_pathZsome_custom_pathZdefault_pathZcustom_pathzarchive,members	tiny-datar   )storeNrB   store/tiny-data.txt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   )suffixr   r   "_unpacking_expected_paths_and_logs__name__r   r%   r&   r   r'   set_check_logsr   )processor_class	extensionr@   archiverE   r   r   
true_pathsZexpected_logr0   r1   fnamesr2   r4   r4   r5   test_unpackingd   s2   

"rQ   c           	      C   s   t  j}tt|ttd}| dgd}|jd| |d}t|dks$J t|d  | ddgd}|jd| |d}t|d	ksBJ t|d  t|d  |jd| |d}t|dks_J t|d  W d
   d
S 1 spw   Y  d
S )zHTest that multiple subsequent calls to a processor yield correct resultsr   rC   rE   rB   r   r	   r   rD   r   Nr   r   r   r%   r&   r'   r*   r   )	rL   rM   r.   r0   
processor1
filenames1
processor2
filenames2Z
filenames3r4   r4   r5   test_multiple_unpacking   s"   "rX   c                 C   sx   t  /}tt|ttd}| dgd}|jd| |d}t|dks$J t|d  W d   dS 1 s5w   Y  dS )	zDTest that unpack members can also be specifed both with a leading ./r   z./store/tiny-data.txtrR   rB   r   r	   r   NrS   )rL   rM   r.   r0   rT   rU   r4   r4   r5   $test_unpack_members_with_leading_dot   s   "rY   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*   r7   r,   )r1   Zexpected_linesr3   lineZexpected_liner4   r4   r5   rK      s
   rK   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    rA   r   zExtracting 'tiny-data.txt'rB   Nsubdirr!   zing contents/zExtracting '')r#   appendr   r+   endswithrJ   )rN   rE   r   r   	log_linesrO   memberr/   r4   r4   r5   rH      s*   

rH   c                 C      t  =}tt|ttd}| dgd}|jd| |d}t|dks$J |  }|jd| |d}t|dks8J W d   dS 1 sCw   Y  dS )zx
    Test that calling with valid members then without them works.
    https://github.com/fatiando/pooch/issues/364
    r   rC   rR   rB   r   r	   Nr   r   r   r%   r&   r'   r*   rL   rM   r.   r0   rT   rU   rV   rW   r4   r4   r5   &test_unpacking_members_then_no_members      
"re   c                 C   rb   )zz
    Test that calling with invalid members then without them works.
    https://github.com/fatiando/pooch/issues/364
    r   znot-a-valid-file.csvrR   rB   r   r   Nrc   rd   r4   r4   r5   ,test_unpacking_wrong_members_then_no_members  rf   rg   ) __doc__pathlibr   tempfiler   r:   r8   r"   r   Z
processorsr   r   r   utilsr
   r   r   r   r&   r%   marknetworkZparametrizer6   r?   rQ   rX   rY   rK   rH   re   rg   r4   r4   r4   r5   <module>   s   


