U
    xÊ¹jÅ'  ã                   @   s†   d dl Z d dlmZ d dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ G d	d
„ d
ƒZG dd„ deƒZdS )é    N)Úmd5©ÚLocalFileSystem)ÚAbstractCopyTests)ÚAbstractGetTests)ÚAbstractOpenTests)ÚAbstractPipeTests)ÚAbstractPutTestsc                   @   s¼   e Zd ZdZejdd„ ƒZejdd„ ƒZejdd„ ƒZejdd	„ ƒZ	ejd
d„ ƒZ
ejdd„ ƒZejdd„ ƒZejdd„ ƒZejdd„ ƒZejdd„ ƒZdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚBaseAbstractFixtureszÀ
    Abstract base class containing fixtures that are used by but never need to
    be overridden in derived filesystem-specific classes to run the abstract
    tests on such filesystems.
    c                 c   s&   |   |||¡}|V  |j|dd� dS )z—
        Scenario on remote filesystem that is used for many cp/get/put tests.

        Cleans up at the end of each test it which it is used.
        T©Ú	recursiveN©Ú_bulk_operations_scenario_0Úrm©ÚselfÚfsÚfs_joinÚfs_pathÚsource© r   ú]/var/www/html/bwave/python/venv/lib/python3.8/site-packages/fsspec/tests/abstract/__init__.pyÚfs_bulk_operations_scenario_0   s    z2BaseAbstractFixtures.fs_bulk_operations_scenario_0c                 c   s&   |   |||¡}|V  |j|dd� dS )z¢
        Scenario on remote filesystem that is used for glob edge cases cp/get/put tests.

        Cleans up at the end of each test it which it is used.
        Tr   N©Ú_glob_edge_cases_filesr   r   r   r   r   Úfs_glob_edge_cases_files    s    z-BaseAbstractFixtures.fs_glob_edge_cases_filesc                 c   s&   |   |||¡}|V  |j|dd� dS )zË
        Scenario on remote filesystem that is used to check cp/get/put on directory
        and file with the same name prefixes.

        Cleans up at the end of each test it which it is used.
        Tr   N©Ú#_dir_and_file_with_same_name_prefixr   r   r   r   r   Ú%fs_dir_and_file_with_same_name_prefix+   s    z:BaseAbstractFixtures.fs_dir_and_file_with_same_name_prefixc                 c   s&   |   |||¡}|V  |j|dd� dS )zË
        Scenario on remote filesystem that is used to check cp/get/put files order
        when source and destination are lists.

        Cleans up at the end of each test it which it is used.
        Tr   N©Ú_10_files_with_hashed_namesr   r   r   r   r   Úfs_10_files_with_hashed_names7   s    z2BaseAbstractFixtures.fs_10_files_with_hashed_namesc                 c   s,   ||dƒ}|V  |  |¡r(|j|dd� dS )z—
        Return name of remote directory that does not yet exist to copy into.

        Cleans up at the end of each test it which it is used.
        ÚtargetTr   N©Úexistsr   )r   r   r   r   r"   r   r   r   Ú	fs_targetC   s    

zBaseAbstractFixtures.fs_targetc                 c   s&   |   |||¡}|V  |j|dd� dS )z–
        Scenario on local filesystem that is used for many cp/get/put tests.

        Cleans up at the end of each test it which it is used.
        Tr   Nr   ©r   Úlocal_fsÚ
local_joinÚ
local_pathr   r   r   r   Ú local_bulk_operations_scenario_0O   s    z5BaseAbstractFixtures.local_bulk_operations_scenario_0c                 c   s&   |   |||¡}|V  |j|dd� dS )z¡
        Scenario on local filesystem that is used for glob edge cases cp/get/put tests.

        Cleans up at the end of each test it which it is used.
        Tr   Nr   r&   r   r   r   Úlocal_glob_edge_cases_filesZ   s    z0BaseAbstractFixtures.local_glob_edge_cases_filesc                 c   s&   |   |||¡}|V  |j|dd� dS )zÊ
        Scenario on local filesystem that is used to check cp/get/put on directory
        and file with the same name prefixes.

        Cleans up at the end of each test it which it is used.
        Tr   Nr   r&   r   r   r   Ú(local_dir_and_file_with_same_name_prefixe   s    
  ÿz=BaseAbstractFixtures.local_dir_and_file_with_same_name_prefixc                 c   s&   |   |||¡}|V  |j|dd� dS )zÊ
        Scenario on local filesystem that is used to check cp/get/put files order
        when source and destination are lists.

        Cleans up at the end of each test it which it is used.
        Tr   Nr   r&   r   r   r   Ú local_10_files_with_hashed_namesu   s    z5BaseAbstractFixtures.local_10_files_with_hashed_namesc                 c   s,   ||dƒ}|V  |  |¡r(|j|dd� dS )z–
        Return name of local directory that does not yet exist to copy into.

        Cleans up at the end of each test it which it is used.
        r"   Tr   Nr#   )r   r'   r(   r)   r"   r   r   r   Úlocal_target�   s    

z!BaseAbstractFixtures.local_targetc                 C   s�   ||dƒ}|  ||dƒ¡ |  ||dƒ¡ tdƒD ]X}||d|› �ƒ}||dƒ}| |¡ |  ||dƒ¡ |  ||dƒ¡ |  ||d	ƒ¡ q2|S )
uL  
        Scenario that is used for glob edge cases cp/get/put tests.
        Creates the following directory and file structure:

        ðŸ“� source
        â”œâ”€â”€ ðŸ“„ file1
        â”œâ”€â”€ ðŸ“„ file2
        â”œâ”€â”€ ðŸ“� subdir0
        â”‚   â”œâ”€â”€ ðŸ“„ subfile1
        â”‚   â”œâ”€â”€ ðŸ“„ subfile2
        â”‚   â””â”€â”€ ðŸ“� nesteddir
        â”‚       â””â”€â”€ ðŸ“„ nestedfile
        â””â”€â”€ ðŸ“� subdir1
            â”œâ”€â”€ ðŸ“„ subfile1
            â”œâ”€â”€ ðŸ“„ subfile2
            â””â”€â”€ ðŸ“� nesteddir
                â””â”€â”€ ðŸ“„ nestedfile
        r   Úfile1Úfile2é   ÚsubdirÚ	nesteddirÚsubfile1Úsubfile2Ú
nestedfile)ÚtouchÚrangeÚmakedirs)r   Úsome_fsÚ	some_joinÚ	some_pathr   Z
subdir_idxr2   r3   r   r   r   r   �   s    


z+BaseAbstractFixtures._glob_edge_cases_filesc                 C   s|   ||dƒ}||dƒ}||dƒ}|  |¡ | ||dƒ¡ | ||dƒ¡ | ||dƒ¡ | ||dƒ¡ | ||dƒ¡ |S )	u‚  
        Scenario that is used for many cp/get/put tests. Creates the following
        directory and file structure:

        ðŸ“� source
        â”œâ”€â”€ ðŸ“„ file1
        â”œâ”€â”€ ðŸ“„ file2
        â””â”€â”€ ðŸ“� subdir
            â”œâ”€â”€ ðŸ“„ subfile1
            â”œâ”€â”€ ðŸ“„ subfile2
            â””â”€â”€ ðŸ“� nesteddir
                â””â”€â”€ ðŸ“„ nestedfile
        r   r2   r3   r/   r0   r4   r5   r6   ©r9   r7   )r   r:   r;   r<   r   r2   r3   r   r   r   r   ®   s    



z0BaseAbstractFixtures._bulk_operations_scenario_0c                 C   sJ   ||dƒ}||dƒ}||dƒ}||dƒ}|  |¡ | |¡ | |¡ |S )u&  
        Scenario that is used to check cp/get/put on directory and file with
        the same name prefixes. Creates the following directory and file structure:

        ðŸ“� source
        â”œâ”€â”€ ðŸ“„ subdir.txt
        â””â”€â”€ ðŸ“� subdir
            â””â”€â”€ ðŸ“„ subfile.txt
        r   r2   z
subdir.txtzsubfile.txtr=   )r   r:   r;   r<   r   r2   ÚfileZsubfiler   r   r   r   Ç   s    







z8BaseAbstractFixtures._dir_and_file_with_same_name_prefixc                 C   sV   ||dƒ}t dƒD ]>}tt|ƒ d¡ƒ ¡ }|||› d�ƒ}|j||›  ¡ d� q|S )uê   
        Scenario that is used to check cp/get/put files order when source and
        destination are lists. Creates the following directory and file structure:

        ðŸ“� source
        â””â”€â”€ ðŸ“„ {hashed([0-9])}.txt
        r   é
   zutf-8z.txt)ÚpathÚvalue)r8   r   ÚstrÚencodeÚ	hexdigestÚpipe)r   r:   r;   r<   r   ÚiZhashed_ir@   r   r   r   r    Ú   s    
z0BaseAbstractFixtures._10_files_with_hashed_namesN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚpytestÚfixturer   r   r   r!   r%   r*   r+   r,   r-   r.   r   r   r   r    r   r   r   r   r
      s2   













!r
   c                   @   s†   e Zd ZdZejdd„ ƒZejdd„ ƒZejdd„ ƒZejdd	�d
d„ ƒZ	ejdd„ ƒZ
ejdd„ ƒZejdd„ ƒZejdd„ ƒZdS )ÚAbstractFixturesa}  
    Abstract base class containing fixtures that may be overridden in derived
    filesystem-specific classes to run the abstract tests on such filesystems.

    For any particular filesystem some of these fixtures must be overridden,
    such as ``fs`` and ``fs_path``, and others may be overridden if the
    default functions here are not appropriate, such as ``fs_join``.
    c                 C   s   t dƒ‚d S ©Nz3This function must be overridden in derived classes©ÚNotImplementedError©r   r   r   r   r   ô   s    zAbstractFixtures.fsc                 C   s   t jjS )zâ
        Return a function that joins its arguments together into a path.

        Most fsspec implementations join paths in a platform-dependent way,
        but some will override this to always use a forward slash.
        ©Úosr@   ÚjoinrQ   r   r   r   r   ø   s    zAbstractFixtures.fs_joinc                 C   s   t dƒ‚d S rN   rO   rQ   r   r   r   r     s    zAbstractFixtures.fs_pathÚclass)Úscopec                 C   s
   t dd�S )NT)Z
auto_mkdirr   rQ   r   r   r   r'     s    zAbstractFixtures.local_fsc                 C   s   t jjS )zs
        Return a function that joins its arguments together into a path, on
        the local filesystem.
        rR   rQ   r   r   r   r(     s    zAbstractFixtures.local_joinc                 C   s   |S ©Nr   )r   Ztmpdirr   r   r   r)     s    zAbstractFixtures.local_pathc                 C   s   dS )zP
        Return whether this implementation supports empty directories.
        Tr   rQ   r   r   r   Úsupports_empty_directories  s    z+AbstractFixtures.supports_empty_directoriesc                 C   s   dd„ S )Nc                 S   s   | S rW   r   )Úxr   r   r   Ú<lambda>!  ó    z3AbstractFixtures.fs_sanitize_path.<locals>.<lambda>r   rQ   r   r   r   Úfs_sanitize_path  s    z!AbstractFixtures.fs_sanitize_pathN)rG   rH   rI   rJ   rK   rL   r   r   r   r'   r(   r)   rX   r\   r   r   r   r   rM   ê   s"   	

	





rM   )rS   Úhashlibr   rK   Zfsspec.implementations.localr   Zfsspec.tests.abstract.copyr   Zfsspec.tests.abstract.getr   Zfsspec.tests.abstract.openr   Zfsspec.tests.abstract.piper   Zfsspec.tests.abstract.putr	   r
   rM   r   r   r   r   Ú<module>   s    ]