o
    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 ||sJ ||d}	||d}
|||d| ||	s4J |||dd| ||
sEJ ||	|
g ||	rSJ ||
rZJ |||d|d  ||slJ ||	ssJ |||dd|d  ||
sJ 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targettarget_file2target_subfile1 r   m/var/www/html/construction_image-detection-poc/venv/lib/python3.10/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s'J |||dds2J 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 ||sJ |||dd||d |||ds1J 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s!J |||dds,J 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}|| ||sJ tddgddgD ]b\}	}
||d}|	r5|d7 }|
r;|d n|}||| |j|dd|rMg n|gksSJ |j||dd |	r|||dsgJ |||d	sqJ |||d
s{J |||d
dsJ |||drJ |j||d||d	||d
gdd nA|||dsJ |||ddsJ |||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	sJ |||d
r"J |||dr-J |j||d||d	gdd n9|||dsHJ |||ddsTJ |||dd	s`J |||dd
rlJ |j||ddd |j|dd|rg n|gksJ q%d S )Nr   FTr	   r
   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   sx   	



	z9AbstractPutTests.test_put_directory_to_existing_directoryc              	   C   s  |}|}| | tddgddgD ]\}}	||d}
|r!|
d7 }
||d}|	r,|d7 }||
| |r>||g ks=J ntt || W d    n1 sSw   Y  |j|
|dd |||dsjJ |||ddsuJ |||ddsJ |||dd	sJ |||dd	d
sJ |	||drJ |j
||ddd |	||drJ |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   r1   r   r2   pytestraisesFileNotFoundErrorr   r   r   r   )r   r   r   r   r   r   r   r   r3   r4   r5   r6   r   r   r   #test_put_directory_to_new_directory   sD   	


z4AbstractPutTests.test_put_directory_to_new_directoryc                 C   s  |}|}| | |s||d}	||	 ||sJ dD ]0}
|
r'|d n|}|||dd| |||ds=J |||dsGJ |||drQJ |||dd	r\J |||drfJ |j||d||dgd
d |j|dd|rg n|	gksJ tddgd
dgD ]\}}|j||d|||d |||dsJ |||dsJ |||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r"J |||dr-J |j||d||dgd
d |j|dd|rGg n|	gksNJ qqd S )Nr   FTr
   r	   *r   r+   r,   r-   Tr)   Fr'   **r.   r/   )	r   r   r   r   r   r   r   r2   r1   )r   r   r   r   r   r   r   r   r   r   r4   r6   globr*   r   r   r   #test_put_glob_to_existing_directory   s|   





z4AbstractPutTests.test_put_glob_to_existing_directoryc              	   C   s  |}|}| | dD ]Y}||d}	|r|	d7 }	|||dd|	 |||ds-J |||dds8J |||ddsCJ |||ddrNJ |||ddd	rZJ |||drdJ |||ddroJ |j||dd
d |||drJ tddgd
dgD ]\}
}|j||d|
|	|d |||dsJ |||ddsJ |||ddsJ |||ddsJ |||ddd	sJ |||drJ |||ddrJ |j||dd
d |||drJ |j||d|
|	|dd |||dsJ |||dds J |||dds,J |||ddr8J |||drCJ |||ddrOJ |j||dd
d |||drdJ qqd S )Nr<   r    r
   r	   r=   r   r+   r,   r-   Tr)   r>   Fr.   r/   )r   r   r   r   r   r   r1   )r   r   r   r   r   r   r   r   r4   r6   r?   r*   r   r   r   test_put_glob_to_new_directoryL  sX   



z/AbstractPutTests.test_put_glob_to_new_directoryargnames	argvaluesc              	      s   |}|t ddgddgD ]`\}}| |r dn}|r%|d n|}|j|	|||||d |}|rF fdd|D }n fdd|D }t|t|ks[J z	|jdd	 W q tym   Y qw 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   rD   rG   r   r   rI     s    r)   )r   r   r   findsortedr   r:   )r   pathr*   r0   expectedr   r   r   local_glob_edge_cases_filesr   rH   r   new_dirr4   r6   outputprefixed_expectedr   rG   r   test_put_glob_edge_cases  s,   

z)AbstractPutTests.test_put_glob_edge_casesc                 C   s  |}|}| | |s||d}	||	 ||sJ ||d||d||ddg}
dD ]Q}|r5|d n|}||
| |||dsGJ |||dsQJ |||ds[J |j||d||d||dgdd	 |j|d
d|rxg n|	gks~J q-d S )Nr   file1r   r	   r   r<   r
   Tr)   Fr'   )r   r   r   r   r   r   r2   )r   r   r   r   r   r   r   r   r   r   source_filesr4   r6   r   r   r   ,test_put_list_of_files_to_existing_directory  s8   





z=AbstractPutTests.test_put_list_of_files_to_existing_directoryc           	      C   s   |}|}| | ||d||d||ddg}||||dd  |||ds-J |||dds8J |||ddsCJ |||ddsNJ d S )NrS   r   r	   r   r    r
   r!   )	r   r   r   r   r   r   r   r   rT   r   r   r   'test_put_list_of_files_to_new_directory  s   

z8AbstractPutTests.test_put_list_of_files_to_new_directoryc                 C   sN  ||d}||d}| | || |}	||	rJ tdD ]I}
|j||	dd ||	s2J |
dkrK|||	ds@J |||	drJJ q!|||	dsUJ |||	ds_J |||	ddsjJ q!|j|	dd ||	ryJ tdD ]'}
|j|d |	dd ||	sJ |||	dsJ |||	drJ q}d S )Nsrcfile   Tr)   r   r
   )r   r   r   ranger   r   r   r   )r   r   r   r   local_fsr   
local_pathrW   src_filer   loopr   r   r   test_put_directory_recursive  s.   



z-AbstractPutTests.test_put_directory_recursivec           	      C   s   |}|}|j ||d|dd |||dsJ |||dr#J |||dg |r8||g ks7J n||r?J |j ||d|dd |||dsTJ |||dds_J |||dsiJ d S )Nr	   Tr)   zsubfile.txtz
subdir.txtzsubdir*)r   r   r   r2   r   r   )	r   r   r   r   r   (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 ]#}
tt|
d }|||| d |	||| d q|j||	d t dD ]}
||	|
 d}|t|
ksOJ q;d S )N
   zutf-8z.txt)lpathrpath)	rZ   r   strencode	hexdigestappendr   catdecode)r   r   r   r   r    local_10_files_with_hashed_namesr   r   rT   destination_filesihashed_i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&   r7   r;   r@   rA   r8   markparametrizer   rR   rU   rV   r_   ra   rp   r   r   r   r   r   	   s&    +V5V:
*.$ r   )hashlibr   	itertoolsr   r8   fsspec.tests.abstract.commonr   r   r   r   r   r   <module>   s
    