a
    ijv                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZm	Z	 d dl
Z
d dlZe
 dd ZG dd dZe
jdd	d
eeddf dddZe
jdddd ZdS )    N)deque)	GeneratorSequencec               	   c   s|   t d} | j  | j  | jd z*| V  W | j  | j  | jd n"| j  | j  | jd 0 dS )z0
    Fixture providing a memory filesystem.
    Zmemory N)fsspec
filesystemstoreclearZpseudo_dirsappend)m r   M/home/ghrups/robot-bench/.venv/lib/python3.9/site-packages/fsspec/conftest.pyr      s    






r   c                   @   s<   e Zd ZdZddddZddeeeef dd	d
Z	dS )InstanceCacheInspectorzQ
    Helper class to inspect instance caches of filesystem classes in tests.
    Nreturnc                 C   s6   t tjjg}|r2| }|  ||  qdS )zU
        Clear instance caches of all currently imported filesystem classes.
        N)r   r   specAbstractFileSystempopleftZclear_instance_cacheextend__subclasses__)selfclassesclsr   r   r   r	   $   s
    zInstanceCacheInspector.clearT)	omit_zero)r   r   c                C   sx   i }t tjjg}|rt| }t|j}t|jt	t
frdt|jt
rJ|jn|jd }|s\|sd|||< ||  q|S )a  
        Gather counts of filesystem instances in the instance caches
        of all currently imported filesystem classes.

        Parameters
        ----------
        omit_zero:
            Whether to omit instance types with no cached instances.
        r   )r   r   r   r   r   len_cache
isinstanceprotocolr   strr   r   )r   r   outr   r   countkeyr   r   r   gather_counts.   s    

z$InstanceCacheInspector.gather_counts)
__name__
__module____qualname____doc__r	   booldictr   intr"   r   r   r   r   r      s   
r   functionT)scopeZautouser   c                  c   s0   t  } |   z| V  W |   n
|   0 dS )as  
    Fixture to ensure empty filesystem instance caches before and after a test.

    Used by default for all tests.
    Clears caches of all imported filesystem classes.
    Can be used to write test assertions about instance caches.

    Usage:

        def test_something(instance_caches):
            # Test code here
            fsspec.open("file://abc")
            fsspec.open("memory://foo/bar")

            # Test assertion
            assert instance_caches.gather_counts() == {"file": 1, "memory": 1}

    Returns
    -------
    instance_caches: An instance cache inspector for clearing and inspecting caches.
    N)r   r	   )Zicr   r   r   instance_cachesG   s
    r,   )r+   c                 c   s   t d t| }ttj|dd}|dd  W d   n1 sJ0    Y  t	t
jddd|d	d
dddg
}zFtd dV  W |  |  zt|  W q ty   Y q0 n4|  |  zt|  W n ty   Y n0 0 dS )z6
    Fixture providing a writable FTP filesystem.
    Z	pyftpdlibr   wbs   helloi'  Nz-mz-dz-uuserz-Ppassz-w   )	localhostiI  r.   r/   )pytestZimportorskipr   openospathjoinwrite
subprocessPopensys
executabletimesleep	terminatewaitshutilrmtree	Exception)ZtmpdirdfPr   r   r   ftp_writableg   s,    
,
rF   )r4   r@   r8   r:   r<   collectionsr   collections.abcr   r   r2   r   Zfixturer   r   r,   rF   r   r   r   r   <module>   s   
(
