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)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   DownloadingDecompressing )r   r   r   strjoinr   BASEURLREGISTRYr   fetchgetvalue
splitlineslensplit
startswithr   )r   extr   r    local_storer   	true_pathpuplog_filefnamelogslines r7   Y/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/pooch/tests/test_processors.pytest_decompress   s2   
"r9   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/Untar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.   )r0   r   r2   	exceptionr7   r7   r8   test_decompress_failsE   sH   




$rD   target_pathsome_custom_pathdefault_pathcustom_pathzarchive,members	tiny-datar   )storeNrJ   store/tiny-data.txtstore/subdir/tiny-data.txtzstore/subdir)single_filearchive_allarchive_filearchive_subdir_filearchive_subdir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	extensionrE   archiverS   r    r   
true_pathsexpected_logr2   r3   fnamesr4   r7   r7   r8   test_unpackingd   s2   

"r`   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   rK   rS   rJ   r   r	   r   rL   r   Nr   r   r   r'   r(   r)   r,   r   )	rZ   r[   r0   r2   
processor1
filenames1
processor2
filenames2
filenames3r7   r7   r8   test_multiple_unpacking   s"   "rh   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.txtra   rJ   r   r	   r   Nrb   )rZ   r[   r0   r2   rc   rd   r7   r7   r8   $test_unpack_members_with_leading_dot   s   "ri   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,   r;   r.   )r3   expected_linesr6   lineexpected_liner7   r7   r8   rY      s
   rY   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!   rI   r   zExtracting 'tiny-data.txt'rJ   Nsubdirr"   zing contents/zExtracting '')r%   appendr   r-   endswithrX   )r\   rS   r   r   	log_linesr]   memberr1   r7   r7   r8   rV      s*   

rV   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   rK   ra   rJ   r   r	   Nr   r   r   r'   r(   r)   r,   rZ   r[   r0   r2   rc   rd   re   rf   r7   r7   r8   &test_unpacking_members_then_no_members      
"rw   c                 C   rt   )zz
    Test that calling with invalid members then without them works.
    https://github.com/fatiando/pooch/issues/364
    r   znot-a-valid-file.csvra   rJ   r   r   Nru   rv   r7   r7   r8   ,test_unpacking_wrong_members_then_no_members  rx   ry   ) __doc__pathlibr   tempfiler   r?   r<   r$   r   
processorsr   r   r   utilsr
   r   r   r   r(   r'   marknetworkparametrizer9   rD   r`   rh   ri   rY   rV   rw   ry   r7   r7   r7   r8   <module>   s   


