U
    hM                     @   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 ) AbstractCopyTestsc           
      C   s  |}|}| | |s&|||d ||s4t||d}||d}	|||d| ||sht|||dd| ||	st|||	g ||rt||	rt|||d|d  ||st||st|||dd|d  ||	std S )Ndummyfile2subfile1subdir/)mkdirtouchisdirAssertionErrorcpisfilermexists)
selffsfs_joinfs_bulk_operations_scenario_0	fs_targetsupports_empty_directoriessourcetargetZtarget_file2Ztarget_subfile1 r   L/var/www/html/venv/lib/python3.8/site-packages/fsspec/tests/abstract/copy.py$test_copy_file_to_existing_directory
   s(    	


z6AbstractCopyTests.test_copy_file_to_existing_directoryc                 C   sh   |}|}| | |||dd||d ||s:t|||dsNt|||ddsdtd S )Nr	   r   znewdir/newdirr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   test_copy_file_to_new_directory4   s    

 z1AbstractCopyTests.test_copy_file_to_new_directoryc                 C   sf   |}|}| | |s&|||d ||s4t|||dd||d |||dsbtd S )Nr   r	   r   newfile)r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   ,test_copy_file_to_file_in_existing_directoryD   s    	
z>AbstractCopyTests.test_copy_file_to_file_in_existing_directoryc                 C   s\   |}|}| | |||dd||dd |||dsBt|||ddsXtd S )Nr	   r   r   r"   r   r    r   r   r   'test_copy_file_to_file_in_new_directoryY   s    

 
z9AbstractCopyTests.test_copy_file_to_file_in_new_directoryc                 C   s(  |}|}| | |s*||d}|| ||s8ttddgddgD ]\}	}
||d}|	rj|d7 }|
rv|d n|}||| |j|dd|rg n|gkst|j||dd |	rN|||dst|||d	st|||d
st|||d
dst|||dr&t|j	||d||d	||d
gdd n|||dsdt|||dds|t|||dd	st|||dd
st|||dd
dst|j	||ddd |j|dd|rg n|gkst|j||ddd |	r|||ds,t|||d	sBt|||d
rXt|||drnt|j	||d||d	gdd nr|||dst|||ddst|||dd	st|||dd
rt|j	||ddd |j|dd|rg n|gksJtqJd S )Nr   FTr	   r
   detail	recursiver   subfile2	nesteddir
nestedfile   r(   maxdepth)
r   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_copy_directory_to_existing_directoryh   sv    	



	
z;AbstractCopyTests.test_copy_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stn tt || W 5 Q R X |j|
|dd |||dst|	||ddst|	||ddst|||dd	st|	||dd	d
s t|
||dr6t|j||ddd |
||dr`t|j|
|ddd |||dst|	||ddst|	||ddst|
||dd	rt|
||drt|j||ddd |
||dr$tq$d S )NFTr	   r
   r   r'   r   r)   r*   r+   r,   r-   )r   r/   r   r0   r   pytestZraisesFileNotFoundErrorr   r   r   r   )r   r   r   r   r   r   r   r   r1   r2   r3   r4   r   r   r   $test_copy_directory_to_new_directory   s@    	


z6AbstractCopyTests.test_copy_directory_to_new_directoryc                 C   s  |}|}| | |s*||d}|| ||s8tdD ]t}	|	rN|d n|}
|||dd|
 |||dszt|||dst|||drt|||dd	rt|||drt|j||d||dgd
d |j|dd|rg n|gkstt	ddgd
dgD ]\}}|j||d||
|d |||dsVt|||dslt|||dst|||dd	st|||drt|j||d||d||dgd
d |j|dd|rg n|gkst|j||d||
|dd |||ds*t|||ds@t|||drVt|||drlt|j||d||dgd
d |j|dd|rg n|gkstqq<d S )Nr   FTr
   r	   *r   r)   r*   r+   Tr'   Fr%   **r,   r-   )
r   r   r   r   r   r   r   r   r0   r/   )r   r   r   r   r   r   r   r   r   r2   r4   globr(   r   r   r   $test_copy_glob_to_existing_directory   sx    	






   z6AbstractCopyTests.test_copy_glob_to_existing_directoryc              	   C   s  |}|}| | dD ]}||d}|r2|d7 }|||dd| |||dsZt|||ddspt|||ddst|||ddrt|||ddd	rt|||drt|||ddrt|j||dd
d |||drttddgd
dgD ]\}	}
|j||d|	||
d |||dsRt|||ddsjt|||ddst|||ddst|||ddd	st|||drt|||ddrt|j||dd
d |||drt|j||d|	||
dd |||ds<t|||ddsTt|||ddslt|||ddrt|||drt|||ddrt|j||dd
d |||drtqqd S )Nr9   r   r
   r	   r:   r   r)   r*   r+   Tr'   r;   Fr,   r-   )r   r   r   r   r   r   r   r/   )r   r   r   r   r   r   r   r2   r4   r<   r(   r   r   r   test_copy_glob_to_new_directoryE  sT    



   z1AbstractCopyTests.test_copy_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stz|jdd	 W q tk
r   Y qX 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?AbstractCopyTests.test_copy_glob_edge_cases.<locals>.<listcomp>c                    s   g | ]} |qS r   r   r@   rC   r   r   rE     s    r'   )r   r   copyfindsortedr   r   r7   )r   pathr(   r.   expectedr   r   Zfs_glob_edge_cases_filesr   rD   r   Znew_dirr2   r4   outputZprefixed_expectedr   rC   r   test_copy_glob_edge_cases|  s(    

z+AbstractCopyTests.test_copy_glob_edge_casesc                 C   s  |}|}| | |s*||d}|| ||s8t||d||d||ddg}	dD ]}
|
rj|d n|}||	| |||dst|||dst|||dst|j||d||d||dgdd	 |j|d
d|rg n|gksZtqZd S )Nr   file1r   r	   r   r9   r
   Tr'   Fr%   )r   r   r   r   r   r   r   r0   )r   r   r   r   r   r   r   r   r   source_filesr2   r4   r   r   r   -test_copy_list_of_files_to_existing_directory  s6    	



z?AbstractCopyTests.test_copy_list_of_files_to_existing_directoryc                 C   s   |}|}| | ||d||d||ddg}||||dd  |||dsZt|||ddspt|||ddst|||ddstd S )NrM   r   r	   r   r   r
   r   )r   r   r   r   r   r   r   rN   r   r   r   (test_copy_list_of_files_to_new_directory  s    

z:AbstractCopyTests.test_copy_list_of_files_to_new_directoryc                 C   sl   |}|}| |rt|||d||dg| ||s@t|||dsTt|||dshtd S )NrM   r   )r   r   r   r   r   r    r   r   r   !test_copy_two_files_new_directory  s    z3AbstractCopyTests.test_copy_two_files_new_directoryc                 C   s   |}|}|j ||d|dd |||ds2t|||drFt|||dg |rp||g ks~tn||r~t|j ||d|dd |||dst|||ddst|||dstd S )Nr	   Tr'   zsubfile.txtz
subdir.txtzsubdir*)r   r   r   r   r0   r   r   )r   r   r   r   Z%fs_dir_and_file_with_same_name_prefixr   r   r   r   r   r   7test_copy_directory_without_files_with_same_name_prefix  s    	zIAbstractCopyTests.test_copy_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svt	qvd S )N
   zutf-8z.txt)Zpath1Zpath2)
ranger   strencode	hexdigestappendrF   catdecoder   )r   r   r   r   Zfs_10_files_with_hashed_namesr   r   rN   Zdestination_filesiZhashed_iZfile_contentr   r   r   -test_copy_with_source_and_destination_as_list  s    z?AbstractCopyTests.test_copy_with_source_and_destination_as_listN)__name__
__module____qualname__r   r!   r#   r$   r5   r8   r=   r>   r6   markZparametrizer   rL   rO   rP   rQ   rR   r\   r   r   r   r   r   	   s$   *V5R7
)-r   )hashlibr   	itertoolsr   r6   Zfsspec.tests.abstract.commonr   r   r   r   r   r   <module>   s   