29
29
ROOT_PREFIX = f"tf-io-root-{ int (time .time ())} /"
30
30
31
31
# This is the number of attributes each filesystem should return in `*_fs`.
32
- NUM_ATR_FS = 7
32
+ NUM_ATR_FS = 6
33
33
34
34
S3_URI = "s3"
35
35
AZ_URI = "az"
@@ -127,7 +127,7 @@ def mkdirs(path):
127
127
path += "/"
128
128
write (path , b"" )
129
129
130
- yield S3_URI , path_to , read , write , mkdirs , posixpath .join , (client , bucket_name )
130
+ yield path_to , read , write , mkdirs , posixpath .join , (client , bucket_name )
131
131
monkeypatch .undo ()
132
132
133
133
@@ -182,7 +182,7 @@ def mkdirs(path):
182
182
if path [- 1 ] == "/" :
183
183
write (path , b"" )
184
184
185
- yield AZ_URI , path_to , read , write , mkdirs , posixpath .join , (
185
+ yield path_to , read , write , mkdirs , posixpath .join , (
186
186
client ,
187
187
container_name ,
188
188
account ,
@@ -196,13 +196,13 @@ def az_dsn_fs(az_fs):
196
196
yield [None ] * NUM_ATR_FS
197
197
return
198
198
199
- uri , _ , read , write , mkdirs , join , fs_internal = az_fs
199
+ _ , read , write , mkdirs , join , fs_internal = az_fs
200
200
_ , container_name , account = fs_internal
201
201
202
202
def path_to_dsn (* args ):
203
203
return f"{ AZ_URI } ://{ account } .blob.core.windows.net/{ container_name } /{ posixpath .join (ROOT_PREFIX , * args )} "
204
204
205
- yield uri , path_to_dsn , read , write , mkdirs , join , fs_internal
205
+ yield path_to_dsn , read , write , mkdirs , join , fs_internal
206
206
207
207
208
208
@pytest .fixture (scope = "module" )
@@ -223,10 +223,9 @@ def write(*_):
223
223
def mkdirs (_ ):
224
224
pass
225
225
226
- yield HTTPS_URI , path_to , read , write , mkdirs , posixpath .join , None
226
+ yield path_to , read , write , mkdirs , posixpath .join , None
227
227
228
228
229
- # TODO(vnvo2409): some tests with `gcs` are falling.
230
229
@pytest .fixture (scope = "module" )
231
230
def gcs_fs ():
232
231
if should_skip (GCS_URI ):
@@ -275,29 +274,41 @@ def mkdirs(path):
275
274
path += "/"
276
275
write (path , b"" )
277
276
278
- yield GCS_URI , path_to , read , write , mkdirs , posixpath .join , None
277
+ yield path_to , read , write , mkdirs , posixpath .join , None
279
278
monkeypatch .undo ()
280
279
281
280
282
281
@pytest .fixture
283
282
def fs (request , s3_fs , az_fs , az_dsn_fs , https_fs , gcs_fs ):
284
- uri , path_to , read , write , mkdirs , join , internal = [None ] * NUM_ATR_FS
285
- should_skip (request .param , check_only = False )
283
+ path_to , read , write , mkdirs , join , internal = [None ] * NUM_ATR_FS
284
+ test_fs_uri = request .param
285
+ real_uri = test_fs_uri
286
+ should_skip (test_fs_uri , check_only = False )
287
+
288
+ if test_fs_uri == S3_URI :
289
+ path_to , read , write , mkdirs , join , internal = s3_fs
290
+ elif test_fs_uri == AZ_URI :
291
+ path_to , read , write , mkdirs , join , internal = az_fs
292
+ elif test_fs_uri == AZ_DSN_URI :
293
+ real_uri = AZ_URI
294
+ path_to , read , write , mkdirs , join , internal = az_dsn_fs
295
+ elif test_fs_uri == HTTPS_URI :
296
+ path_to , read , write , mkdirs , join , internal = https_fs
297
+ elif test_fs_uri == GCS_URI :
298
+ path_to , read , write , mkdirs , join , internal = gcs_fs
299
+
300
+ path_to_rand = None
301
+ test_patchs = request .getfixturevalue ("patchs" )
302
+ if (test_fs_uri , test_patchs ) in fs .path_to_rand_cache :
303
+ path_to_rand = fs .path_to_rand_cache [(test_fs_uri , test_patchs )]
304
+ else :
305
+ path_to_rand = functools .partial (path_to , str (random .getrandbits (32 )))
306
+ mkdirs (path_to_rand ("" ))
307
+ fs .path_to_rand_cache [(test_fs_uri , test_patchs )] = path_to_rand
308
+ yield real_uri , path_to_rand , read , write , mkdirs , join , internal
286
309
287
- if request .param == S3_URI :
288
- uri , path_to , read , write , mkdirs , join , internal = s3_fs
289
- elif request .param == AZ_URI :
290
- uri , path_to , read , write , mkdirs , join , internal = az_fs
291
- elif request .param == AZ_DSN_URI :
292
- uri , path_to , read , write , mkdirs , join , internal = az_dsn_fs
293
- elif request .param == HTTPS_URI :
294
- uri , path_to , read , write , mkdirs , join , internal = https_fs
295
- elif request .param == GCS_URI :
296
- uri , path_to , read , write , mkdirs , join , internal = gcs_fs
297
310
298
- path_to_rand = functools .partial (path_to , str (random .getrandbits (32 )))
299
- mkdirs (path_to_rand ("" ))
300
- yield uri , path_to_rand , read , write , mkdirs , join , internal
311
+ fs .path_to_rand_cache = {}
301
312
302
313
303
314
@pytest .mark .parametrize (
@@ -328,7 +339,9 @@ def test_io_read_file(fs, patchs, monkeypatch):
328
339
329
340
330
341
@pytest .mark .parametrize (
331
- "fs, patchs" , [(S3_URI , None ), (AZ_URI , None ), (AZ_DSN_URI , None )], indirect = ["fs" ]
342
+ "fs, patchs" ,
343
+ [(S3_URI , None ), (AZ_URI , None ), (AZ_DSN_URI , None ), (GCS_URI , None )],
344
+ indirect = ["fs" ],
332
345
)
333
346
def test_io_write_file (fs , patchs , monkeypatch ):
334
347
_ , path_to , read , _ , _ , _ , _ = fs
@@ -459,7 +472,7 @@ def test_dataset_from_remote_filename(fs, patchs, monkeypatch):
459
472
460
473
461
474
@pytest .mark .parametrize (
462
- "fs, patchs" , [(S3_URI , None ), (AZ_URI , None )], indirect = ["fs" ]
475
+ "fs, patchs" , [(S3_URI , None ), (AZ_URI , None ), ( GCS_URI , None ) ], indirect = ["fs" ]
463
476
)
464
477
def test_gfile_GFile_writable (fs , patchs , monkeypatch ):
465
478
uri , path_to , read , _ , _ , _ , _ = fs
@@ -488,7 +501,7 @@ def test_gfile_GFile_writable(fs, patchs, monkeypatch):
488
501
489
502
490
503
@pytest .mark .parametrize (
491
- "fs, patchs" , [(S3_URI , None ), (AZ_URI , None )], indirect = ["fs" ]
504
+ "fs, patchs" , [(S3_URI , None ), (AZ_URI , None ), ( GCS_URI , None ) ], indirect = ["fs" ]
492
505
)
493
506
def test_gfile_isdir (fs , patchs , monkeypatch ):
494
507
_ , path_to , _ , write , mkdirs , join , _ = fs
@@ -506,10 +519,10 @@ def test_gfile_isdir(fs, patchs, monkeypatch):
506
519
507
520
508
521
@pytest .mark .parametrize (
509
- "fs, patchs" , [(S3_URI , None ), (AZ_URI , None )], indirect = ["fs" ]
522
+ "fs, patchs" , [(S3_URI , None ), (AZ_URI , None ), ( GCS_URI , None ) ], indirect = ["fs" ]
510
523
)
511
524
def test_gfile_listdir (fs , patchs , monkeypatch ):
512
- _ , path_to , _ , write , mkdirs , join , _ = fs
525
+ uri , path_to , _ , write , mkdirs , join , _ = fs
513
526
mock_patchs (monkeypatch , patchs )
514
527
515
528
root_path = "test_gfile_listdir"
@@ -519,6 +532,10 @@ def test_gfile_listdir(fs, patchs, monkeypatch):
519
532
num_childs = 5
520
533
childrens = [None ] * num_childs
521
534
childrens [0 ] = join (dname , "subdir" )
535
+ # TODO(vnvo2409): `gs` filesystem requires `/` at the end of directory's path.
536
+ # Consider if we could change the behavior for matching the other filesystems.
537
+ if uri == GCS_URI :
538
+ childrens [0 ] += "/"
522
539
mkdirs (childrens [0 ])
523
540
524
541
body = b"123456789"
@@ -532,7 +549,7 @@ def test_gfile_listdir(fs, patchs, monkeypatch):
532
549
533
550
534
551
@pytest .mark .parametrize (
535
- "fs, patchs" , [(S3_URI , None ), (AZ_URI , None )], indirect = ["fs" ]
552
+ "fs, patchs" , [(S3_URI , None ), (AZ_URI , None ), ( GCS_URI , None ) ], indirect = ["fs" ]
536
553
)
537
554
def test_gfile_makedirs (fs , patchs , monkeypatch ):
538
555
_ , path_to , _ , write , _ , join , _ = fs
@@ -569,7 +586,7 @@ def test_gfile_remove(fs, patchs, monkeypatch):
569
586
570
587
571
588
@pytest .mark .parametrize (
572
- "fs, patchs" , [(S3_URI , None ), (AZ_URI , None )], indirect = ["fs" ]
589
+ "fs, patchs" , [(S3_URI , None ), (AZ_URI , None ), ( GCS_URI , None ) ], indirect = ["fs" ]
573
590
)
574
591
def test_gfile_rmtree (fs , patchs , monkeypatch ):
575
592
_ , path_to , _ , write , mkdirs , join , _ = fs
@@ -646,7 +663,7 @@ def test_gfile_rename(fs, patchs, monkeypatch):
646
663
647
664
648
665
@pytest .mark .parametrize (
649
- "fs, patchs" , [(S3_URI , None ), (AZ_URI , None )], indirect = ["fs" ]
666
+ "fs, patchs" , [(S3_URI , None ), (AZ_URI , None ), ( GCS_URI , None ) ], indirect = ["fs" ]
650
667
)
651
668
def test_gfile_glob (fs , patchs , monkeypatch ):
652
669
_ , path_to , _ , write , _ , join , _ = fs
0 commit comments