
    xKg]+                        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               Zej(                  j*                  d        Zej(                  j*                  ej(                  j-                  dddgddg      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      ej(                  j-                  de
dfedfgd d!g      d"                             Zej(                  j*                  ej(                  j-                  de
dfedfg      d#               Zej(                  j*                  ej(                  j-                  de
dfedfg      d$               Zd% Zd& Zej(                  j*                  ej(                  j-                  de
dfedfg      d'               Zej(                  j*                  ej(                  j-                  de
dfedfg      d(               Zy))z
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           	         t        | |      }t               5 }t        |      }|!t        |dj	                  d|dg      z        }nt        ||z        }t        |t        t              }t               5 }|j                  d|z   |      }	|j                         }
|
j                         }t        |      d	k(  sJ |d
   j                         d
   dk(  sJ |d   j                  d      sJ | |d   v sJ 	 ddd       	|k(  sJ t        |	       t               5 }|j                  d|z   |      }	|j                         dk(  sJ 	 ddd       |	|k(  sJ t        |	       ddd       y# 1 sw Y   uxY w# 1 sw Y   0xY w# 1 sw Y   yxY w)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liness               _/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/pooch/tests/test_processors.pytest_decompressr:      s    &t4I		K <D388_c8,L#MMNID4K(I(C]hII.4	IJE$$&DOO%Eu:?"?8>>#A&-7779''888U2Y&&&  	!!!]hII.4	IJE$$&",,,  	!!!1 
	 ] ]) 
	s=   AF5BE+7$F,E7F+E4	0F7F 	<FFc            	      j   t               5 } t        |       }t        |t        t              }t        j                  t              5 }t        j                         5  |j                  dt        d             ddd       ddd       j                  j                  d   j                  d      sJ d	|j                  j                  d   vsJ t        j                  t              5 }t        j                         5  |j                  dt        d
             ddd       ddd       |j                  j                  d   j                  d      sJ d	|j                  j                  d   vsJ t        j                  t              5 }t        j                         5  |j                  dt        d             ddd       ddd       |j                  j                  d   j                  d      sJ d	|j                  j                  d   v sJ t        j                  t              5 }t        j                         5  |j                  dt        d             ddd       ddd       |j                  j                  d   j                  d      sJ d	|j                  j                  d   v sJ 	 ddd       y# 1 sw Y   LxY w# 1 sw Y   QxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   :xY w# 1 sw Y   ?xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   yxY w)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argsr0   )r2   r   r4   	exceptions       r9   test_decompress_failsrF   E   sm    
	K (C]]:&)((*		/Zv5N	O + ' ##A&112VWWW")//*>*>q*AAAA]]:&)((*		/Zu5M	N + ' ##A&112TUUU")//*>*>q*AAAA]]:&)((*		/Zu5M	N + ' ##A&112TUUU"ioo&:&:1&====]]:&)((*		+61J	K + ' ##A&112VWWW"ioo&:&:1&====3 
	
 +* '& +* '& +* '& +* '&+ 
	s   ;L)KK9KA(L))K*>KK*$A(L)L!K7?LA(L)/LL"L*AL)KKK	L)K'"K**K4	/L)7L<LL		L)LLL&	"L))L2target_pathsome_custom_pathdefault_pathcustom_pathzarchive,members	tiny-datar   )storeNrL   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                     | ||      }|||z   |j                   z   }t               5 }t        |      }t        ||||z  | j                        \  }}t        |t        t              }	t               5 }
|	j                  ||z   |      }t        |      |k(  sJ t        |
|       ddd       D ]  }t        |        t               5 }
|	j                  ||z   |      }t        |      |k(  sJ t        |
g        ddd       |D ]  }t        |        	 ddd       y# 1 sw Y   |xY w# 1 sw Y   1xY w# 1 sw Y   yxY w)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	extensionrG   archiverV   r"   r   
true_pathsexpected_logr4   r5   fnamesr6   s                r9   test_unpackingrc   d   s8   <  [II	)I,<,<<		Dz#EWd[0/2J2J$
 
L (C]hYYw2iYHFv;*,,,,/  EE"  ]hYYw2iYHFv;*,,,"%  EE" ' 
	 ] ] 
	s<   A
D933D!&$D9
3D-=D9!D*	&D9-D6	2D99Ec                    t               5 }t        t        |      t        t              } | dg      }|j                  d|z   |      }t        |      dk(  sJ t        |d           | ddg      }|j                  d|z   |      }t        |      d	k(  sJ t        |d          t        |d          |j                  d|z   |      }t        |      dk(  sJ t        |d          d
d
d
       y
# 1 sw Y   y
xY w)zHTest that multiple subsequent calls to a processor yield correct resultsr   rM   rV   rL   r!   r
   r   rN   r   Nr   r   r   r)   r*   r+   r.   r   )	r]   r^   r2   r4   
processor1
filenames1
processor2
filenames2
filenames3s	            r9   test_multiple_unpackingrl      s     
	k*WxP %.C-DE
YYw2jYI
:!###
1& %*,HI

 YYw2jYI
:!###
1&
1& YYw2jYI
:!###
1&- 
		s   CC33C<c                     t               5 }t        t        |      t        t              } | dg      }|j                  d|z   |      }t        |      dk(  sJ t        |d          ddd       y# 1 sw Y   yxY w)	zDTest that unpack members can also be specifed both with a leading ./r   z./store/tiny-data.txtre   rL   r!   r
   r   Nrf   )r]   r^   r2   r4   rg   rh   s         r9   $test_unpack_members_with_leading_dotrn      sp     
	k*WxP %.E-FG
YYw2jYI
:!###
1& 
		s   AA22A;c                     | j                         j                         }t        |      t        |      k(  sJ t        ||      D ]  \  }}|j	                  |      rJ  y)zC
    Assert that the lines in the log match the expected ones.
    N)r,   r-   r.   r=   r0   )r5   expected_linesr8   lineexpected_lines        r9   r\   r\      sZ     **,Eu:^,,,,"5.9m}---  :    c                    dg}| dk(  r$t        |dz        h}|j                  d       ||fS | dk(  rD|Bt        |dz  dz        t        |dz  dz  dz        h}|j                  | |d    d       ||fS | dk(  r~||g }|D ]j  }|t        |j                  d	       z  }t        |      j	                  d      s|dz  }|j                  t        |             |j                  d
| d       l t        |      }|fS )zo
    Generate the appropriate expected paths and log message depending on the
    parameters for the test.
    r#   rK   r   zExtracting 'tiny-data.txt'rL   subdirr$   zing contents/zExtracting '')r'   appendr   r/   endswithr[   )r_   rV   r   r   	log_linesr`   memberr3   s           r9   rY   rY      s:   
 I+$012
56  y   
G	w01w)O;<

 	D6$r(<89 y   
G	 3
FtV\\#%677Iy>**?;%7	c)n-|F8156  _
y  rs   c                 <   t               5 }t        t        |      t        t              } | dg      }|j                  d|z   |      }t        |      dk(  sJ  |        }|j                  d|z   |      }t        |      dkD  sJ 	 ddd       y# 1 sw Y   yxY w)zx
    Test that calling with valid members then without them works.
    https://github.com/fatiando/pooch/issues/364
    r   rM   re   rL   r!   r
   Nr   r   r   r)   r*   r+   r.   r]   r^   r2   r4   rg   rh   ri   rj   s           r9   &test_unpacking_members_then_no_membersr      s     
	k*WxP %.C-DE
YYw2jYI
:!### %&
YYw2jYI
:""" 
		   A=BBc                 <   t               5 }t        t        |      t        t              } | dg      }|j                  d|z   |      }t        |      dk(  sJ  |        }|j                  d|z   |      }t        |      dkD  sJ 	 ddd       y# 1 sw Y   yxY w)zz
    Test that calling with invalid members then without them works.
    https://github.com/fatiando/pooch/issues/364
    r   znot-a-valid-file.csvre   rL   r!   r   Nr}   r~   s           r9   ,test_unpacking_wrong_members_then_no_membersr     s     
	k*WxP %.D-EF
YYw2jYI
:!### %&
YYw2jYI
:""" 
		r   ) __doc__pathlibr   tempfiler   rA   r>   r&   r   
processorsr   r   r	   utilsr   r   r   r   r*   r)   marknetworkparametrizer:   rF   rc   rl   rn   r\   rY   r   r    rs   r9   <module>r      s    '    1 1 T T  

  	4   < > >< D,-NM3R   	'(	()*	/01	>"#	(.9:	  & V_ui()	'  
#' 8#8 V_ui()'	 
'8 V_ui()
'	 

'.!6 V_ui()#	 
#& V_ui()#	 
#rs   