
    ޛ7iv                        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
j                         d        Z G d d      Z e
j                  dd	      d
eeddf   fd       Z e
j                  d      d        Zy)    N)deque)	GeneratorSequencec               #   $  K   t        j                  d      } | j                  j                          | j                  j                          | j                  j                  d       	 |  | j                  j                          | j                  j                          | j                  j                  d       y# | j                  j                          | j                  j                          | j                  j                  d       w xY ww)z0
    Fixture providing a memory filesystem.
    memory N)fsspec
filesystemstoreclearpseudo_dirsappend)ms    L/home/rose/Desktop/poly/venv/lib/python3.12/site-packages/fsspec/conftest.pyr   r      s     
 	(#AGGMMOMMMM!			R  	
		R s    A%D(B< ,AD<ADDc                   8    e Zd ZdZd	dZdddedeeef   fdZ	y)
InstanceCacheInspectorzQ
    Helper class to inspect instance caches of filesystem classes in tests.
    returnNc                     t        t        j                  j                  g      }|rC|j	                         }|j                          |j                  |j                                |rByy)zU
        Clear instance caches of all currently imported filesystem classes.
        N)r   r	   specAbstractFileSystempopleftclear_instance_cacheextend__subclasses__)selfclassesclss      r   r   zInstanceCacheInspector.clear$   sP     7789//#C$$&NN3--/0     T)	omit_zeror   c                   i }t        t        j                  j                  g      }|r|j	                         }t        |j                        }t        |j                  t        t        f      r>t        |j                  t              r|j                  n|j                  d   }|s|s|||<   |j                  |j                                |r|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keys          r   gather_countsz$InstanceCacheInspector.gather_counts.   s     !7789//#C

OE #,,38&0s&CcllVW	$CHNN3--/0  
r   )r   N)
__name__
__module____qualname____doc__r   booldictr%   intr)    r   r   r   r      s,    1 26 $ $sCx. r   r   functionT)scopeautouser   c               #      K   t               } | j                          	 |  | j                          y# | j                          w xY ww)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   )ics    r   instance_cachesr7   G   s5     . 
 	!BHHJ


s   A3 AAA)r3   c              #     K   t        j                  d       t        |       }t        t        j
                  j                  |d      d      5 }|j                  ddz         ddd       t        j                  t        j                  ddd|d	d
dddg
      }	 t        j                  d       d |j                          |j                          	 t!        j"                  |        y# 1 sw Y   xY w# t$        $ r Y yw xY w# |j                          |j                          	 t!        j"                  |        w # t$        $ r Y w w xY wxY ww)z6
    Fixture providing a writable FTP filesystem.
    	pyftpdlibr&   wbs   helloi'  Nz-mz-dz-uuserz-Ppassz-w   )	localhostiI  r;   r<   )pytestimportorskipr%   openospathjoinwrite
subprocessPopensys
executabletimesleep	terminatewaitshutilrmtree	Exception)tmpdirdfPs       r   ftp_writablerU   g   s    
 $FA	bggll1e$d	+q	5 ! 
,	{D!T64QUV	A	

1//			MM&! 
,	+  			 	
		MM&! 		s~   AEC("5ED 1 EC4 'E(C1-E4	D =E?D  E!E
%D;:E
;	EE
EE

E)rB   rN   rF   rH   rJ   collectionsr   collections.abcr   r   r?   r	   fixturer   r   r7   rU   r1   r   r   <module>rY      s    	   
   /   ! ! % %P j$/#94#EF  0> j! "r   