
    gM                     D    d dl mZ d dlmZ d dlZd dlmZ  G d d      Zy)    )md5)productN)GLOB_EDGE_CASES_TESTSc                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
ej                  j                  ed	   ed
         d        Zd Zd Zd Zd Zd Zy)AbstractCopyTestsc                    |}|}|j                  |       |s|j                   ||d             |j                  |      sJ  ||d      } ||d      }	|j                   ||d      |       |j	                  |      sJ |j                   ||dd      |       |j	                  |	      sJ |j                  ||	g       |j                  |      rJ |j                  |	      rJ |j                   ||d      |dz          |j                  |      sJ |j	                  |      sJ |j                   ||dd      |dz          |j	                  |	      sJ y )Ndummyfile2subfile1subdir/)mkdirtouchisdircpisfilermexists)
selffsfs_joinfs_bulk_operations_scenario_0	fs_targetsupports_empty_directoriessourcetargettarget_file2target_subfile1s
             O/var/www/openai/venv/lib/python3.12/site-packages/fsspec/tests/abstract/copy.py$test_copy_file_to_existing_directoryz6AbstractCopyTests.test_copy_file_to_existing_directory
   sQ    /
)HHWVW-.xxvw/!&*5 	gfg&/yy&&& 	gfh
3V<yy))) 	|_-.99\***99_--- 	gfg&5xxyy&&&
gfh
3Vc\Byy)))    c                     |}|}|j                  |       |j                   ||dd       ||d             |j                  |      sJ |j                   ||d            sJ |j                   ||dd            sJ y )Nr   r   znewdir/newdirr   r   r   r   r   r   r   r   r   r   r   s          r   test_copy_file_to_new_directoryz1AbstractCopyTests.test_copy_file_to_new_directory4   s     /

FHj17693M	
 xxxx1222yy:>???r!   c                     |}|}|j                  |       |s|j                   ||d             |j                  |      sJ |j                   ||dd       ||d             |j	                   ||d            sJ y )Nr	   r   r   newfile)r   r   r   r   r   )r   r   r   r   r   r   r   r   s           r   ,test_copy_file_to_file_in_existing_directoryz>AbstractCopyTests.test_copy_file_to_file_in_existing_directoryD   sy     /
)HHWVW-.xx
gfh
3WVY5OPyy3444r!   c                     |}|}|j                  |       |j                   ||dd       ||dd             |j                   ||d            sJ |j                   ||dd            sJ y )Nr   r   r#   r(   r$   r%   s          r   'test_copy_file_to_file_in_new_directoryz9AbstractCopyTests.test_copy_file_to_file_in_new_directoryY   ss     /

FHj1768Y3W	
 xx1222yy9=>>>r!   c           	         |}|}|j                  |       |s ||d      }|j                  |       |j                  |      sJ t        ddgddg      D ]  \  }	}
 ||d      }|	r|dz  }|
r|dz   n|}|j	                  ||       |j                  |d      |rg ngk(  sJ |j	                  ||d       |	r|j                   ||d            sJ |j                   ||d	            sJ |j                   ||d
            sJ |j                   ||d
d            sJ |j                   ||d            rJ |j                   ||d       ||d	       ||d
      gd       n|j                   ||d            sJ |j                   ||dd            sJ |j                   ||dd	            sJ |j                   ||dd
            sJ |j                   ||dd
d            sJ |j                   ||d      d       |j                  |d      |rg ngk(  sJ |j	                  ||dd       |	r|j                   ||d            sJ |j                   ||d	            sJ |j                   ||d
            rJ |j                   ||d            rJ |j                   ||d       ||d	      gd       n|j                   ||d            sJ |j                   ||dd            sJ |j                   ||dd	            sJ |j                   ||dd
            rJ |j                   ||d      d       |j                  |d      |rg ngk(  rJ  y )Nr	   FTr   r   detail	recursiver   subfile2	nesteddir
nestedfile   r0   maxdepth)	r   r   r   zipr   lsr   r   r   )r   r   r   r   r   r   r   r   r	   source_slashtarget_slashsts                r   )test_copy_directory_to_existing_directoryz;AbstractCopyTests.test_copy_directory_to_existing_directoryh   s    /
)FG,EHHUOxx*-udmeT]*K&L,)AS ,&A EE!QK555.0ug  
 EE!Q$E'yy!<===yy!<===xx <===yyl!KLLL99WVX%>???
3
34
 #   xx 9:::yy:!FGGGyy:!FGGGxx+ FGGGyy;!UVVVgfh/4@555.0ug  
 EE!Q$E3yy!<===yy!<===99WV[%ABBB99WVX%>???
3
3 #   xx 9:::yy:!FGGGyy:!FGGG99WVX{%KLLLgfh/4@555.0ug   +Lr!   c           	         |}|}|j                  |       t        ddgddg      D ]:  \  }}	 ||d      }
|r|
dz  }
 ||d      }|	r|dz  }|j                  |
|       |r|j                  |      g k(  s5J t	        j
                  t              5  |j                  |       d d d        |j                  |
|d       |j                   ||d            sJ |j                   ||dd            sJ |j                   ||dd            sJ |j                   ||dd	            sJ |j                   ||dd	d
            sJ |j                   ||d            rJ |j                   ||d      d       |j                   ||d            rJ |j                  |
|dd       |j                   ||d            sJ |j                   ||dd            sJ |j                   ||dd            sJ |j                   ||dd	            rJ |j                   ||d            rJ |j                   ||d      d       |j                   ||d            s;J  y # 1 sw Y   xY w)NFTr   r   r#   r/   r   r1   r2   r3   r4   r5   )r   r7   r   r8   pytestraisesFileNotFoundErrorr   r   r   r   )r   r   r   r   r   r   r   r   r9   r:   r;   r<   s               r   $test_copy_directory_to_new_directoryz6AbstractCopyTests.test_copy_directory_to_new_directory   se    /
*-udmeT]*K&L,)AS)AS EE!QK)uuV}***]]#45EE&M 6 EE!Q$E'88GFH566699WVXzBCCC99WVXzBCCC88GFHkBCCC99WVX{LQRRRyy!:;;;EE'&(+tE<yy!:;;; EE!Q$E388GFH566699WVXzBCCC99WVXzBCCCyy;!GHHHyy!:;;;EE'&(+tE<yy!:;;;K +L 65s   I%%I/	c           
         |}|}|j                  |       |s ||d      }|j                  |       |j                  |      sJ dD ]  }	|	r|dz   n|}
|j                   ||dd      |
       |j	                   ||d            sJ |j	                   ||d            sJ |j                   ||d            rJ |j                   ||dd	            rJ |j                   ||d            rJ |j                   ||d       ||d      gd
       |j                  |d      |rg ngk(  sJ t        ddgd
dg      D ]  \  }}|j                   ||d|      |
|       |j	                   ||d            sJ |j	                   ||d            sJ |j                   ||d            sJ |j	                   ||dd	            sJ |j                   ||d            rJ |j                   ||d       ||d       ||d      gd
       |j                  |d      |rg ngk(  sJ |j                   ||d|      |
|d       |j	                   ||d            sJ |j	                   ||d            sJ |j                   ||d            rJ |j                   ||d            rJ |j                   ||d       ||d      gd
       |j                  |d      |rg ngk(  rJ   y )Nr	   FTr   r   *r   r1   r2   r3   Tr/   Fr-   **r4   r5   )	r   r   r   r   r   r   r   r8   r7   )r   r   r   r   r   r   r   r   r	   r:   r<   globr0   s                r   $test_copy_glob_to_existing_directoryz6AbstractCopyTests.test_copy_glob_to_existing_directory   sQ    /
)FG,EHHUOxx)L ,&A EE'&(C0!499WVZ899999WVZ8999xx <===yyl!KLLLyy!:;;;EEFJ/FJ/    555.0ug  
 $'T{T5M#Bigfh5qINyy!<===yy!<===xx <===yyl!KLLL99WVX%>???
3
34
 #   uuVEu24B5'  
 FHd3Q)VW   yy!<===yy!<===99WV[%ABBB99WVX%>???
3
3 #   uuVEu24B5'  I $C/ *r!   c           
         |}|}|j                  |       dD ]4  } ||d      }|r|dz  }|j                   ||dd      |       |j                   ||d            sJ |j                   ||dd            sJ |j                   ||dd            sJ |j	                   ||dd            rJ |j	                   ||ddd	            rJ |j	                   ||d            rJ |j	                   ||dd            rJ |j                   ||d      d
       |j	                   ||d            rJ t        ddgd
dg      D ]  \  }	}
|j                   ||d|	      ||
       |j                   ||d            sJ |j                   ||dd            sJ |j                   ||dd            sJ |j                   ||dd            sJ |j                   ||ddd	            sJ |j	                   ||d            rJ |j	                   ||dd            rJ |j                   ||d      d
       |j	                   ||d            rJ |j                   ||d|	      ||
d       |j                   ||d            sJ |j                   ||dd            sJ |j                   ||dd            sJ |j	                   ||dd            rJ |j	                   ||d            rJ |j	                   ||dd            rJ |j                   ||d      d
       |j	                   ||d            sJ  7 y )NrD   r#   r   r   rE   r   r1   r2   r3   Tr/   rF   Fr4   r5   )r   r   r   r   r   r   r7   )r   r   r   r   r   r   r   r:   r<   rG   r0   s              r   test_copy_glob_to_new_directoryz1AbstractCopyTests.test_copy_glob_to_new_directoryE  s\    /
)L)AS EE'&(C0!488GFH566699WVXzBCCC99WVXzBCCCyy;!GHHHyy;!UVVVyy!:;;;yy8!DEEEEE'&(+tE<yy!:;;; $'T{T5M#Bigfh5qINxx 9:::yy:!FGGGyy:!FGGGxx+ FGGGyy;!UVVV99WVX%>???99WVXx%HIIIgfh/4@99WVX%>??? FHd3Q)VW   xx 9:::yy:!FGGGyy:!FGGG99WVX{%KLLL99WVX%>???99WVXx%HIIIgfh/4@99WVX%>???3 $C' *r!   argnames	argvaluesc
                    |}
|}t        ddgddg      D ]  \  }}|j                  |       |r	 ||d      n|}|r|dz   n|}|j                   ||
|      |||       |j                  |      }|r|D cg c]  } |	 ||d|             }}n|D cg c]  } |	 |||             }}t	        |      t	        |      k(  sJ 	 |j                  |d        y c c}w c c}w # t        $ r Y w xY w)NTFr#   r   r5   r/   )r   r   copyfindsortedr   rA   )r   pathr0   r6   expectedr   r   fs_glob_edge_cases_filesr   fs_sanitize_pathr   r   new_dirr:   r<   outputpprefixed_expecteds                     r   test_copy_glob_edge_casesz+AbstractCopyTests.test_copy_glob_edge_cases|  s&   " *%,dE]T5M%J!G\HHV-4)&A'CQAGGGFD)1	HGUWWV_FLT%LTq$WVXq%ABH " %
 CK%BJQ$WVQ%78( " % &>V,=%>>>>f-) &K%% % s   5CC C%%	C10C1c           	      2   |}|}|j                  |       |s ||d      }|j                  |       |j                  |      sJ  ||d       ||d       ||dd      g}	dD ]  }
|
r|dz   n|}|j                  |	|       |j	                   ||d            sJ |j	                   ||d            sJ |j	                   ||d            sJ |j                   ||d       ||d       ||d      gd	       |j                  |d
      |rg ngk(  rJ  y )Nr	   file1r
   r   r   rD   r   Tr/   Fr-   )r   r   r   r   r   r   r8   )r   r   r   r   r   r   r   r   r	   source_filesr:   r<   s               r   -test_copy_list_of_files_to_existing_directoryz?AbstractCopyTests.test_copy_list_of_files_to_existing_directory  sD    /
)FG,EHHUOxx FG$FG$FHj1
 *L ,&AEE,"99WVW566699WVW566699WVZ8999EEFG,FG,FJ/
    555.0ug  ! *r!   c                 r   |}|}|j                  |        ||d       ||d       ||dd      g}|j                  | ||d      dz          |j                   ||d            sJ |j                   ||dd            sJ |j                   ||dd            sJ |j                   ||dd            sJ y )Nr[   r
   r   r   r#   r   r$   )r   r   r   r   r   r   r   r\   s           r   (test_copy_list_of_files_to_new_directoryz:AbstractCopyTests.test_copy_list_of_files_to_new_directory  s     /
 FG$FG$FHj1
 	lGFH5;<xx1222yy7;<<<yy7;<<<yy:>???r!   c                    |}|}|j                  |      rJ |j                   ||d       ||d      g|       |j                  |      sJ |j                   ||d            sJ |j                   ||d            sJ y )Nr[   r
   )r   r   r   r   r%   s          r   !test_copy_two_files_new_directoryz3AbstractCopyTests.test_copy_two_files_new_directory  s    
 /99V$$$
wvw')ABFKxxyy1222yy1222r!   c                    |}|}|j                   ||d      |d       |j                   ||d            sJ |j                   ||d            rJ |j                   ||d      g       |r|j                  |      g k(  sJ |j	                  |      rJ |j                   ||d      |d       |j                   ||d            sJ |j                   ||dd            sJ |j                   ||d            sJ y )Nr   Tr/   zsubfile.txtz
subdir.txtzsubdir*)r   r   r   r8   r   r   )r   r   r   r   %fs_dir_and_file_with_same_name_prefixr   r   r   s           r   7test_copy_directory_without_files_with_same_name_prefixzIAbstractCopyTests.test_copy_directory_without_files_with_same_name_prefix  s    7 	gfh'4@yy788899WV\:;;;
wv}-./%55=B&&&yy((( 	gfi(&DAxx1222yy=ABBByy6777r!   c                    |}|}g }g }t        d      D ]i  }	t        t        |	      j                  d            j	                         }
|j                   |||
 d             |j                   |||
 d             k |j                  ||       t        d      D ]5  }	|j                  ||	         j                  d      }|t        |	      k(  r5J  y )N
   zutf-8z.txt)path1path2)	ranger   strencode	hexdigestappendrN   catdecode)r   r   r   r   fs_10_files_with_hashed_namesr   r   r\   destination_filesihashed_ifile_contents               r   -test_copy_with_source_and_destination_as_listz?AbstractCopyTests.test_copy_with_source_and_destination_as_list  s     / rA3q6==12<<>H8*D0A BC$$WVz5F%GH  	l*;<rA66"3A"67>>wGL3q6))) r!   N)__name__
__module____qualname__r    r&   r)   r+   r=   rB   rH   rJ   r?   markparametrizer   rY   r]   r_   ra   rd   ru    r!   r   r   r   	   s    (*T@ 5*?Tl3<jPd5@n [[j)k*'	'R+Z@*38>*r!   r   )hashlibr   	itertoolsr   r?   fsspec.tests.abstract.commonr   r   r{   r!   r   <module>r      s       >d* d*r!   