U
    xÊ¹j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 t‚||dƒ}	||dƒ}
| ||dƒ|¡ | |	¡sTt‚| ||ddƒ|¡ | |
¡svt‚| |	|
g¡ | |	¡r’t‚| |
¡r t‚| ||dƒ|d ¡ | |¡sÄt‚| |	¡sÒt‚| ||ddƒ|d ¡ | |
¡søt‚d S )NÚfile2Úsubfile1Úsubdirú/)ÚmkdirÚisdirÚAssertionErrorÚ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   úX/var/www/html/bwave/python/venv/lib/python3.8/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: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   r   r   Útest_get_file_to_new_directory3   s    


 ÿz/AbstractGetTests.test_get_file_to_new_directoryc           	      C   sD   |}|}|  |¡ | ||ddƒ||dƒ¡ | ||dƒ¡s@t‚d S )Nr
   r	   Únewfile)r   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ƒ¡sBt‚| ||ddƒ¡sXt‚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 t‚tddgddgƒD �]¤\}	}
||dƒ}|	rR|d7 }|
r^|d n|}| ||¡ | |¡g ks€t‚|j||dd� |	�r$| ||dƒ¡sªt‚| ||dƒ¡s¾t‚| ||dƒ¡sÒt‚| ||dd	ƒ¡sèt‚| ||dƒ¡rüt‚|j||dƒ||dƒ||dƒgdd� nŒ| ||dƒ¡�s:t‚| ||ddƒ¡�sRt‚| ||ddƒ¡�sjt‚| ||ddƒ¡�s‚t‚| ||ddd	ƒ¡�sœt‚|j||dƒdd� | |¡g k�sÄt‚|j||dd
d� |	�rT| ||dƒ¡�sòt‚| ||dƒ¡�st‚| ||dƒ¡�rt‚| ||dƒ¡�r4t‚|j||dƒ||dƒgdd� nr| ||dƒ¡�sjt‚| ||ddƒ¡�s‚t‚| ||ddƒ¡�sšt‚| ||ddƒ¡�r²t‚|j||dƒdd� | |¡g ks2t‚q2d S )NFTr
   r   ©Ú	recursiver	   Úsubfile2Ú	nesteddirÚ
nestedfileé   ©r'   Úmaxdepth)	r   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sxt‚|j||dd� | ||dƒ¡sœt‚| ||ddƒ¡s²t‚| ||ddƒ¡sÈt‚| ||dd	ƒ¡sÞt‚| ||dd	d
ƒ¡söt‚| ||dƒ¡�rt‚|j||dƒdd� | |¡g k�s4t‚|j||ddd� | ||dƒ¡�s\t‚| ||ddƒ¡�stt‚| ||ddƒ¡�sŒt‚| ||dd	ƒ¡�r¤t‚| ||dƒ¡�rºt‚|j||dƒdd� | ||dƒ¡r$t‚q$d S )NFTr
   r   r   r&   r	   r(   r)   r*   r+   r,   )	r   r.   r   r/   r   r   r   r   r   r0   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ƒ¡sTt‚| ||dƒ¡sht‚| ||dƒ¡r|t‚| ||ddƒ¡r’t‚| ||dƒ¡r¦t‚|j||dƒ||dƒgd	d
� | |¡g ksÖt‚tddgd	dgƒD �]l\}}|j||d|ƒ|
|d
� | ||dƒ¡�s t‚| ||dƒ¡�s6t‚| ||dƒ¡�sLt‚| ||ddƒ¡�sdt‚| ||dƒ¡�rzt‚|j||dƒ||dƒ||dƒgd	d
� | |¡g k�s´t‚|j||d|ƒ|
|dd� | ||dƒ¡�sät‚| ||dƒ¡�sút‚| ||dƒ¡�rt‚| ||dƒ¡�r&t‚|j||dƒ||dƒgd	d
� | |¡g ksèt‚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   r   r1   r3   Úglobr'   r   r   r   Ú#test_get_glob_to_existing_directoryõ   sd    


þûýú
   ÿþûz4AbstractGetTests.test_get_glob_to_existing_directoryc              	   C   sè  |}|}|  |¡ dD �]Ê}	||dƒ}
|	r2|
d7 }
| ||ddƒ|
¡ | ||dƒ¡sZt‚| ||ddƒ¡spt‚| ||ddƒ¡s†t‚| ||ddƒ¡rœt‚| ||ddd	ƒ¡r´t‚| ||dƒ¡rÈt‚| ||ddƒ¡rÞt‚|j||dƒd
d� | |¡g k�st‚tddgd
dgƒD �]Æ\}}|j||d|ƒ|
|d� | ||dƒ¡�sPt‚| ||ddƒ¡�sht‚| ||ddƒ¡�s€t‚| ||ddƒ¡�s˜t‚| ||ddd	ƒ¡�s²t‚| ||dƒ¡�rÈt‚| ||ddƒ¡�ràt‚|j||dƒd
d� | ||dƒ¡�r
t‚|j||d|ƒ|
|dd� | ||dƒ¡�s:t‚| ||ddƒ¡�sRt‚| ||ddƒ¡�sjt‚| ||ddƒ¡�r‚t‚| ||dƒ¡�r˜t‚| ||ddƒ¡�r°t‚|j|j|dd�d
d� | ||dƒ¡�rt‚�qqd S )Nr6   r   r   r
   r7   r	   r(   r)   r*   Tr&   r8   Fr+   r,   )Údetail)	r   r   r   r   r   r   r   r/   r.   r9   r   r   r   Útest_get_glob_to_new_directory=  s\    



ÿÿ

   ÿ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²t‚z|jˆdd	� W q tk
rØ   Y qX 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?   rB   r   r   rC   ¢  s    r&   )r   r   r   ÚfindÚsortedr   r   ÚFileNotFoundError)r   Úpathr'   r-   Úexpectedr   r   Zfs_glob_edge_cases_filesr   r   r   r   Znew_dirr1   r3   ÚoutputZprefixed_expectedr   rB   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ƒ¡sht‚| ||dƒ¡s|t‚| ||dƒ¡s�t‚|j||dƒ||dƒ||dƒgdd� | |¡g ks4t‚q4d S )	NÚfile1r   r
   r	   r6   r   Tr&   )r   r   r   r   r   r/   )r   r   r   r   r   r   r   r   r   Úsource_filesr1   r3   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ƒ¡sZt‚| ||ddƒ¡spt‚| ||ddƒ¡s†t‚| ||ddƒ¡sœt‚d S )NrK   r   r
   r	   r   r   r    )
r   r   r   r   r   r   r   r   r   rL   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:t‚tdƒD ]’}
|j||	dd� | |	¡sdt‚|
dkr–| ||	dƒ¡s€t‚| ||	dƒ¡rÔt‚qB| ||	dƒ¡sªt‚| ||	dƒ¡s¾t‚| ||	ddƒ¡sBt‚qB|j|	dd� | |	¡ròt‚tdƒD ]R}
|j|d |	dd� | |	¡�s"t‚| ||	dƒ¡�s8t‚| ||	dƒ¡rút‚qúd S )NÚsrcÚfileé   Tr&   r   r   )	r   Útouchr   r   Úranger   r   r   r   )r   r   r   Zfs_pathr   r   r   rO   Zsrc_filer   Úloopr   r   r   Útest_get_directory_recursiveî  s,    



z-AbstractGetTests.test_get_directory_recursivec           	      C   sÂ   |}|}|j ||dƒ|dd� | ||dƒ¡s2t‚| ||dƒ¡rFt‚| ||dƒg¡ | |¡g ksjt‚|j ||dƒ|dd� | ||dƒ¡s”t‚| ||ddƒ¡sªt‚| ||dƒ¡s¾t‚d S )Nr
   Tr&   zsubfile.txtz
subdir.txtzsubdir*)r   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szt
‚qzd S )Né
   zutf-8z.txt)ZrpathZlpath)rS   r   ÚstrÚencodeÚ	hexdigestÚappendr   r   ÚcatÚdecoder   )r   r   r   r   r   r   Zfs_10_files_with_hashed_namesr   r   rL   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%   r4   r5   r;   r=   ÚpytestÚmarkZparametrizer   rJ   rM   rN   rU   rV   r_   r   r   r   r   r   
   s$   (O4HAþ
*'$r   )
Úhashlibr   Ú	itertoolsr   rc   Zfsspec.implementations.localr   Zfsspec.tests.abstract.commonr   r   r   r   r   r   Ú<module>   s
   