a
    yn„f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¡ | |	¡r’J ‚| |
¡r J ‚| ||dƒ|d ¡ | |¡sÄJ ‚| |	¡sÒJ ‚| ||ddƒ|d ¡ | |
¡søJ ‚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   ú\/home/yuhw/wc/wire-cell-python/wcpy/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s€J ‚|j||dd� |	�r$| ||dƒ¡sªJ ‚| ||dƒ¡s¾J ‚| ||dƒ¡sÒJ ‚| ||dd	ƒ¡sèJ ‚| ||dƒ¡rüJ ‚|j||dƒ||dƒ||dƒgdd� nŒ| ||dƒ¡�s:J ‚| ||ddƒ¡�sRJ ‚| ||ddƒ¡�sjJ ‚| ||ddƒ¡�s‚J ‚| ||ddd	ƒ¡�sœJ ‚|j||dƒdd� | |¡g k�sÄJ ‚|j||dd
d� |	�rT| ||dƒ¡�sòJ ‚| ||dƒ¡�sJ ‚| ||dƒ¡�rJ ‚| ||dƒ¡�r4J ‚|j||dƒ||dƒgdd� nr| ||dƒ¡�sjJ ‚| ||ddƒ¡�s‚J ‚| ||ddƒ¡�sšJ ‚| ||ddƒ¡�r²J ‚|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ƒ¡sœJ ‚| ||ddƒ¡s²J ‚| ||ddƒ¡sÈJ ‚| ||dd	ƒ¡sÞJ ‚| ||dd	d
ƒ¡söJ ‚| ||dƒ¡�rJ ‚|j||dƒdd� | |¡g k�s4J ‚|j||ddd� | ||dƒ¡�s\J ‚| ||ddƒ¡�stJ ‚| ||ddƒ¡�sŒJ ‚| ||dd	ƒ¡�r¤J ‚| ||dƒ¡�rºJ ‚|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ƒ¡r’J ‚| ||dƒ¡r¦J ‚|j||dƒ||dƒgd	d
� | |¡g ksÖJ ‚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�s´J ‚|j||d|ƒ|
|dd� | ||dƒ¡�säJ ‚| ||dƒ¡�súJ ‚| ||dƒ¡�rJ ‚| ||dƒ¡�r&J ‚|j||dƒ||dƒgd	d
� | |¡g ksèJ ‚qèq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ƒ¡s†J ‚| ||ddƒ¡rœJ ‚| ||ddd	ƒ¡r´J ‚| ||dƒ¡rÈJ ‚| ||ddƒ¡rÞJ ‚|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ƒ¡�s€J ‚| ||ddƒ¡�s˜J ‚| ||ddd	ƒ¡�s²J ‚| ||dƒ¡�rÈJ ‚| ||ddƒ¡�ràJ ‚|j||dƒd
d� | ||dƒ¡�r
J ‚|j||d|ƒ|
|dd� | ||dƒ¡�s:J ‚| ||ddƒ¡�sRJ ‚| ||ddƒ¡�sjJ ‚| ||ddƒ¡�r‚J ‚| ||dƒ¡�r˜J ‚| ||ddƒ¡�r°J ‚|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+   )Ú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s²J ‚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>   rA   r   r   rB   ¢  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   rA   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ƒ¡s�J ‚|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ƒ¡s†J ‚| ||ddƒ¡sœJ ‚d S )NrJ   r   r
   r	   r   r   r   )
r   r   r   r   r   r   r   r   r   rK   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ƒ¡s€J ‚| ||	dƒ¡rÔJ ‚qB| ||	dƒ¡sªJ ‚| ||	dƒ¡s¾J ‚| ||	ddƒ¡sBJ ‚qB|j|	dd� | |	¡ròJ ‚tdƒD ]R}
|j|d |	dd� | |	¡�s"J ‚| ||	dƒ¡�s8J ‚| ||	dƒ¡rúJ ‚qúd S )NÚsrcÚfileé   Tr%   r   r   )r   Útouchr   Úranger   r   r   r   )r   r   r   Zfs_pathr   r   r   rN   Zsrc_filer   Ú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ƒ¡s”J ‚| ||ddƒ¡sªJ ‚| ||dƒ¡s¾J ‚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)
rR   r   ÚstrÚencodeÚ	hexdigestÚappendr   r   ÚcatÚdecode)r   r   r   r   r   r   Zfs_10_files_with_hashed_namesr   r   rK   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   rI   rL   rM   rT   rU   r^   r   r   r   r   r   
   s$   (O4HAþ
*'$r   )
Úhashlibr   Ú	itertoolsr   rb   Zfsspec.implementations.localr   Zfsspec.tests.abstract.commonr   r   r   r   r   r   Ú<module>   s
   