U
    h'                     @   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   P/var/www/html/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    ]