@@ -93,6 +93,25 @@ def test_iterdir_with_plus_in_name(self, s3_with_plus_chr_name):
9393 (file ,) = files
9494 assert file == p .joinpath ("file.txt" )
9595
96+ @pytest .mark .xfail (msg = "fsspec/universal_pathlib#144" )
97+ def test_rglob_with_double_fwd_slash (self , s3_with_double_fwd_slash_files ):
98+ import boto3
99+ import botocore .exceptions
100+
101+ bucket , anon , s3so = s3_with_double_fwd_slash_files
102+
103+ conn = boto3 .resource ("s3" , ** s3so ["client_kwargs" ])
104+ # ensure there's no s3://bucket/key.txt object
105+ with pytest .raises (botocore .exceptions .ClientError , match = ".*Not Found.*" ):
106+ conn .Object (bucket , "key.txt" ).load ()
107+ # ensure there's a s3://bucket//key.txt object
108+ assert conn .Object (bucket , "/key.txt" ).get ()["Body" ].read () == b"hello world"
109+
110+ p0 = UPath (f"s3://{ bucket } //key.txt" , ** s3so )
111+ assert p0 .read_bytes () == b"hello world"
112+ p1 = UPath (f"s3://{ bucket } " , ** s3so )
113+ assert list (p1 .rglob ("*.txt" )) == [p0 ]
114+
96115
97116@pytest .fixture
98117def s3_with_plus_chr_name (s3_server ):
@@ -109,7 +128,25 @@ def s3_with_plus_chr_name(s3_server):
109128 if s3 .exists (bucket ):
110129 for dir , _ , keys in s3 .walk (bucket ):
111130 for key in keys :
112- s3 .rm (f"{ dir } /{ key } " )
131+ if key .rstrip ("/" ):
132+ s3 .rm (f"{ dir } /{ key } " )
133+
134+
135+ @pytest .fixture
136+ def s3_with_double_fwd_slash_files (s3_server ):
137+ anon , s3so = s3_server
138+ s3 = fsspec .filesystem ("s3" , anon = False , ** s3so )
139+ bucket = "double_fwd_slash_bucket"
140+ s3 .mkdir (bucket + "/" )
141+ s3 .pipe_file (f"{ bucket } //key.txt" , b"hello world" )
142+ try :
143+ yield bucket , anon , s3so
144+ finally :
145+ if s3 .exists (bucket ):
146+ for dir , _ , keys in s3 .walk (bucket ):
147+ for key in keys :
148+ if key .rstrip ("/" ):
149+ s3 .rm (f"{ dir } /{ key } " )
113150
114151
115152def test_path_with_hash_and_space ():
0 commit comments