a
    hR                     @   s>   d dl mZ d dlmZ d dlZd dlmZ G dd dZdS )    )md5)productN)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 ) AbstractPutTestsc                 C   s  |}|}| | |s&|||d ||s4J ||d}	||d}
|||d| ||	shJ |||dd| ||
sJ ||	|
g ||	rJ ||
rJ |||d|d  ||sJ ||	sJ |||dd|d  ||
sJ d S )Ndummyfile2subfile1subdir/)mkdirtouchisdirputisfilermexists)selffsfs_join	fs_target
local_join local_bulk_operations_scenario_0supports_empty_directoriessourcetargetZtarget_file2Ztarget_subfile1 r   G/var/www/auris/lib/python3.9/site-packages/fsspec/tests/abstract/put.py#test_put_file_to_existing_directory
   s(    



z4AbstractPutTests.test_put_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   test_put_file_to_new_directory5   s    
z/AbstractPutTests.test_put_file_to_new_directoryc           	      C   sf   |}|}| | |s&|||d ||s4J |||dd||d |||dsbJ d S )Nr   r	   r   newfile)r   r   r   r   r   )	r   r   r   r   r   r   r   r   r   r   r   r   +test_put_file_to_file_in_existing_directoryE   s    

z<AbstractPutTests.test_put_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_put_file_to_file_in_new_directory[   s    


z7AbstractPutTests.test_put_file_to_file_in_new_directoryc                 C   s(  |}|}| | |s*||d}|| ||s8J tddgddgD ]\}	}
||d}|	rj|d7 }|
rv|d n|}||| |j|dd|rg n|gksJ |j||dd |	rN|||dsJ |||d	sJ |||d
sJ |||d
dsJ |||dr&J |j||d||d	||d
gdd n|||dsdJ |||dds|J |||dd	sJ |||dd
sJ |||dd
dsJ |j||ddd |j|dd|rg n|gksJ |j||ddd |	r|||ds,J |||d	sBJ |||d
rXJ |||drnJ |j||d||d	gdd nr|||dsJ |||ddsJ |||dd	sJ |||dd
rJ |j||ddd |j|dd|rg n|gksJJ qJd S )Nr   FTr	   r
   Zdetail	recursiver   subfile2	nesteddir
nestedfile   r'   maxdepth)	r   r   r   zipr   lsr   r   r   )r   r   r   r   r   r   r   r   r   source_slashtarget_slashstr   r   r   (test_put_directory_to_existing_directoryk   sv    	



	
z9AbstractPutTests.test_put_directory_to_existing_directoryc              	   C   s*  |}|}| | tddgddgD ]\}}	||d}
|rD|
d7 }
||d}|	rZ|d7 }||
| |r~||g ksJ n4tt || W d    n1 s0    Y  |j|
|dd |||dsJ |||ddsJ |||ddsJ |||dd	sJ |||dd	d
s6J |	||drLJ |j
||ddd |	||drvJ |j|
|ddd |||dsJ |||ddsJ |||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/   pytestZraisesFileNotFoundErrorr   r   r   r   )r   r   r   r   r   r   r   r   r0   r1   r2   r3   r   r   r   #test_put_directory_to_new_directory   s@    	


(z4AbstractPutTests.test_put_directory_to_new_directoryc                 C   s  |}|}| | |s*||d}	||	 ||s8J dD ]t}
|
rN|d n|}|||dd| |||dszJ |||dsJ |||drJ |||dd	rJ |||drJ |j||d||dgd
d |j|dd|rg n|	gksJ tddgd
dgD ]\}}|j||d|||d |||dsVJ |||dslJ |||dsJ |||dd	sJ |||drJ |j||d||d||dgd
d |j|dd|rg n|	gksJ |j||d|||dd |||ds*J |||ds@J |||drVJ |||drlJ |j||d||dgd
d |j|dd|rg n|	gksJ qq<d S )Nr   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   r   r   r   r1   r3   globr'   r   r   r   #test_put_glob_to_existing_directory   sx    







z4AbstractPutTests.test_put_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 |||drJ tddgd
dgD ]\}
}|j||d|
|	|d |||dsRJ |||ddsjJ |||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sTJ |||ddslJ |||ddrJ |||drJ |||ddrJ |j||dd
d |||drJ qqd S )Nr8   r   r
   r	   r9   r   r(   r)   r*   Tr&   r:   Fr+   r,   )r   r   r   r   r   r   r.   )r   r   r   r   r   r   r   r   r1   r3   r;   r'   r   r   r   test_put_glob_to_new_directoryL  sT    



z/AbstractPutTests.test_put_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 | ]} d |qS )r   r   .0pr   fs_sanitize_pathr   r   r   
<listcomp>  s   z=AbstractPutTests.test_put_glob_edge_cases.<locals>.<listcomp>c                    s   g | ]} |qS r   r   r?   rB   r   r   rD     s   r&   )r   r   r   findsortedr   r6   )r   pathr'   r-   expectedr   r   r   Zlocal_glob_edge_cases_filesr   rC   r   Znew_dirr1   r3   outputZprefixed_expectedr   rB   r   test_put_glob_edge_cases  s(    

z)AbstractPutTests.test_put_glob_edge_casesc                 C   s  |}|}| | |s*||d}	||	 ||s8J ||d||d||ddg}
dD ]}|rj|d n|}||
| |||dsJ |||dsJ |||dsJ |j||d||d||dgdd	 |j|d
d|rg n|	gksZJ qZd S )Nr   file1r   r	   r   r8   r
   Tr&   Fr%   )r   r   r   r   r   r   r/   )r   r   r   r   r   r   r   r   r   r   source_filesr1   r3   r   r   r   ,test_put_list_of_files_to_existing_directory  s6    




z=AbstractPutTests.test_put_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 )NrK   r   r	   r   r   r
   r   )	r   r   r   r   r   r   r   r   rL   r   r   r   'test_put_list_of_files_to_new_directory  s    

z8AbstractPutTests.test_put_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   r   r   ranger   r   r   r   )r   r   r   r   Zlocal_fsr   
local_pathrO   Zsrc_filer   Zloopr   r   r   test_put_directory_recursive  s,    



z-AbstractPutTests.test_put_directory_recursivec           	      C   s   |}|}|j ||d|dd |||ds2J |||drFJ |||dg |rp||g ks~J n||r~J |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(local_dir_and_file_with_same_name_prefixr   r   r   r   r   r   6test_put_directory_without_files_with_same_name_prefix  s    
zGAbstractPutTests.test_put_directory_without_files_with_same_name_prefixc                 C   s   |}|}g }g }	t dD ]F}
tt|
d }|||| d |	||| d q|j||	d t dD ](}
||	|
 d}|t|
ksvJ qvd S )N
   zutf-8z.txt)ZlpathZrpath)	rR   r   strencode	hexdigestappendr   catdecode)r   r   r   r   r   Z local_10_files_with_hashed_namesr   r   rL   Zdestination_filesiZhashed_iZfile_contentr   r   r   -test_copy_with_source_and_destination_as_list;  s    z>AbstractPutTests.test_copy_with_source_and_destination_as_listN)__name__
__module____qualname__r   r!   r#   r$   r4   r7   r<   r=   r5   markZparametrizer   rJ   rM   rN   rT   rU   r^   r   r   r   r   r   	   s$   +V5V:
*.$ r   )hashlibr   	itertoolsr   r5   Zfsspec.tests.abstract.commonr   r   r   r   r   r   <module>   s   