a
    hQ                     @   sJ   d dl mZ d dlmZ d dlZd dlmZ d dlmZ G dd dZ	dS )    )md5)productNmake_path_posix)GLOB_EDGE_CASES_TESTSc                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
ejed ed dd Zdd Zdd Zdd Zdd Zdd ZdS ) AbstractGetTestsc                 C   s   |}|}| | ||s J ||d}	||d}
|||d| ||	sTJ |||dd| ||
svJ ||	|
g ||	rJ ||
rJ |||d|d  ||sJ ||	sJ |||dd|d  ||
sJ d S )Nfile2subfile1subdir/)mkdirisdirgetisfilermexists)selffsfs_joinfs_bulk_operations_scenario_0local_fs
local_joinlocal_targetsourcetargetZtarget_file2Ztarget_subfile1 r   G/var/www/auris/lib/python3.9/site-packages/fsspec/tests/abstract/get.py#test_get_file_to_existing_directory   s$    



z4AbstractGetTests.test_get_file_to_existing_directoryc           	      C   sh   |}|}| | |||dd||d ||s:J |||dsNJ |||ddsdJ d S )Nr
   r	   znewdir/newdirr   r   r   r   	r   r   r   r   r   r   r   r   r   r   r   r   test_get_file_to_new_directory3   s    

z/AbstractGetTests.test_get_file_to_new_directoryc           	      C   sD   |}|}| | |||dd||d |||ds@J d S )Nr
   r	   newfile)r   r   r   r    r   r   r   +test_get_file_to_file_in_existing_directoryJ   s
    

z<AbstractGetTests.test_get_file_to_file_in_existing_directoryc           	      C   s\   |}|}| | |||dd||dd |||dsBJ |||ddsXJ d S )Nr
   r	   r   r"   r   r    r   r   r   &test_get_file_to_file_in_new_directory\   s    



z7AbstractGetTests.test_get_file_to_file_in_new_directoryc                 C   s  |}|}| | ||s J tddgddgD ]\}	}
||d}|	rR|d7 }|
r^|d n|}||| ||g ksJ |j||dd |	r$|||dsJ |||dsJ |||dsJ |||dd	sJ |||drJ |j||d||d||dgdd n|||ds:J |||ddsRJ |||ddsjJ |||ddsJ |||ddd	sJ |j||ddd ||g ksJ |j||dd
d |	rT|||dsJ |||dsJ |||drJ |||dr4J |j||d||dgdd nr|||dsjJ |||ddsJ |||ddsJ |||ddrJ |j||ddd ||g ks2J q2d S )NFTr
   r   	recursiver	   subfile2	nesteddir
nestedfile   r&   maxdepth)r   r   zipr   lsr   r   r   r   r   r   r   r   r   r   r   r   Zsource_slashtarget_slashstr   r   r   (test_get_directory_to_existing_directoryr   sh    


	
z9AbstractGetTests.test_get_directory_to_existing_directoryc                 C   s  |}|}| | tddgddgD ]\}	}
||d}|	rD|d7 }||d}|
rZ|d7 }||| ||g ksxJ |j||dd |||dsJ |||ddsJ |||ddsJ |||dd	sJ |||dd	d
sJ |||drJ |j||ddd ||g ks4J |j||ddd |||ds\J |||ddstJ |||ddsJ |||dd	rJ |||drJ |j||ddd |||dr$J q$d S )NFTr
   r   r   r%   r	   r'   r(   r)   r*   r+   )r   r-   r   r.   r   r   r   r   r/   r   r   r   #test_get_directory_to_new_directory   s>    



z4AbstractGetTests.test_get_directory_to_new_directoryc                 C   s^  |}|}| | dD ]@}	|	r(|d n|}
|||dd|
 |||dsTJ |||dshJ |||dr|J |||ddrJ |||drJ |j||d||dgd	d
 ||g ksJ tddgd	dgD ]l\}}|j||d||
|d
 |||ds J |||ds6J |||dsLJ |||ddsdJ |||drzJ |j||d||d||dgd	d
 ||g ksJ |j||d||
|dd |||dsJ |||dsJ |||drJ |||dr&J |j||d||dgd	d
 ||g ksJ qqd S )NFTr   r
   *r	   r'   r(   r)   Tr%   **Fr*   r+   )r   r   r   r   r   r   r.   r-   r   r   r   r   r   r   r   r   r   r0   r2   globr&   r   r   r   #test_get_glob_to_existing_directory   s^    


z4AbstractGetTests.test_get_glob_to_existing_directoryc              	   C   s  |}|}| | dD ]}	||d}
|	r2|
d7 }
|||dd|
 |||dsZJ |||ddspJ |||ddsJ |||ddrJ |||ddd	rJ |||drJ |||ddrJ |j||dd
d ||g ksJ tddgd
dgD ]\}}|j||d||
|d |||dsPJ |||ddshJ |||ddsJ |||ddsJ |||ddd	sJ |||drJ |||ddrJ |j||dd
d |||dr
J |j||d||
|dd |||ds:J |||ddsRJ |||ddsjJ |||ddrJ |||drJ |||ddrJ |j|j|ddd
d |||drJ qqd S )Nr5   r   r   r
   r6   r	   r'   r(   r)   Tr%   r7   Fr*   r+   )Zdetail)r   r   r   r   r   r   r.   r-   r8   r   r   r   test_get_glob_to_new_directory=  sV    




z/AbstractGetTests.test_get_glob_to_new_directoryargnamesZ	argvaluesc              	      s   |}|
t ddgddgD ]\}}| |r: dn}|rJ|d n|}|j||||||d |}|r fdd|D }n fdd|D }t|t|ksJ z|jdd	 W q ty   Y q0 qd S )
NTFr   r   r+   c                    s   g | ]}t  d |qS )r   r   .0pr   r   r   r   
<listcomp>  s   z=AbstractGetTests.test_get_glob_edge_cases.<locals>.<listcomp>c                    s   g | ]}t  |qS r   r   r=   r@   r   r   rA     s   r%   )r   r   r   findsortedr   FileNotFoundError)r   pathr&   r,   expectedr   r   Zfs_glob_edge_cases_filesr   r   r   r   Znew_dirr0   r2   outputZprefixed_expectedr   r@   r   test_get_glob_edge_cases~  s(    

z)AbstractGetTests.test_get_glob_edge_casesc                 C   s   |}|}| | ||d||d||ddg}	dD ]}
|
rD|d n|}||	| |||dshJ |||ds|J |||dsJ |j||d||d||dgdd ||g ks4J q4d S )	Nfile1r   r
   r	   r5   r   Tr%   )r   r   r   r   r.   )r   r   r   r   r   r   r   r   r   source_filesr0   r2   r   r   r   ,test_get_list_of_files_to_existing_directory  s*    


z=AbstractGetTests.test_get_list_of_files_to_existing_directoryc           
      C   s   |}|}| | ||d||d||ddg}	||	||dd  |||dsZJ |||ddspJ |||ddsJ |||ddsJ d S )NrI   r   r
   r	   r   r   r   )
r   r   r   r   r   r   r   r   r   rJ   r   r   r   'test_get_list_of_files_to_new_directory  s    


z8AbstractGetTests.test_get_list_of_files_to_new_directoryc                 C   sR  ||d}||d}| | || |}	||	r:J tdD ]}
|j||	dd ||	sdJ |
dkr|||	dsJ |||	drJ qB|||	dsJ |||	dsJ |||	ddsBJ qB|j|	dd ||	rJ tdD ]R}
|j|d |	dd ||	s"J |||	ds8J |||	drJ qd S )Nsrcfile   Tr%   r   r   )r   touchr   ranger   r   r   r   )r   r   r   Zfs_pathr   r   r   rM   Zsrc_filer   Zloopr   r   r   test_get_directory_recursive  s,    



z-AbstractGetTests.test_get_directory_recursivec           	      C   s   |}|}|j ||d|dd |||ds2J |||drFJ |||dg ||g ksjJ |j ||d|dd |||dsJ |||ddsJ |||dsJ d S )Nr
   Tr%   zsubfile.txtz
subdir.txtzsubdir*)r   r   r   r.   r   )	r   r   r   r   r   r   Z%fs_dir_and_file_with_same_name_prefixr   r   r   r   r   6test_get_directory_without_files_with_same_name_prefix  s    
zGAbstractGetTests.test_get_directory_without_files_with_same_name_prefixc                 C   s   |}|}g }	g }
t dD ]J}tt|d }|	||| d |
t||| d q|j|	|
d t dD ](}||
| 	d}|t|kszJ qzd S )N
   zutf-8z.txt)ZrpathZlpath)
rQ   r   strencode	hexdigestappendr   r   catdecode)r   r   r   r   r   r   Zfs_10_files_with_hashed_namesr   r   rJ   Zdestination_filesiZhashed_iZfile_contentr   r   r   ,test_get_with_source_and_destination_as_list/  s    
z=AbstractGetTests.test_get_with_source_and_destination_as_listN)__name__
__module____qualname__r   r!   r#   r$   r3   r4   r:   r;   pytestmarkZparametrizer   rH   rK   rL   rR   rS   r\   r   r   r   r   r   
   s$   (O4HA
*'$r   )
hashlibr   	itertoolsr   r`   Zfsspec.implementations.localr   Zfsspec.tests.abstract.commonr   r   r   r   r   r   <module>   s
   