File tree Expand file tree Collapse file tree 3 files changed +25
-16
lines changed Expand file tree Collapse file tree 3 files changed +25
-16
lines changed Original file line number Diff line number Diff line change @@ -1384,26 +1384,33 @@ def iterdir(
1384
1384
1385
1385
if scheme == "file" :
1386
1386
resolved_path = _resolve_local_path (path_str )
1387
+ if not resolved_path .exists ():
1388
+ raise FileNotFoundError (f"No such file or directory: '{ resolved_path } '" )
1389
+
1390
+ result = []
1387
1391
if resolved_path .is_file ():
1388
1392
if _match_file (
1389
1393
resolved_path ,
1390
1394
extensions ,
1391
1395
glob ,
1392
1396
):
1393
- return [resolved_path ]
1394
- else :
1395
- return []
1397
+ result .append (resolved_path )
1398
+ return result
1399
+
1400
+ if resolved_path .is_dir ():
1401
+ for entry in resolved_path .iterdir ():
1402
+ if entry .is_file ():
1403
+ if _match_file (
1404
+ entry ,
1405
+ extensions ,
1406
+ glob ,
1407
+ ):
1408
+ result .append (entry )
1409
+ return result
1396
1410
1397
- result = []
1398
- for entry in resolved_path .iterdir ():
1399
- if entry .is_file ():
1400
- if _match_file (
1401
- entry ,
1402
- extensions ,
1403
- glob ,
1404
- ):
1405
- result .append (entry )
1406
- return result
1411
+ raise ValueError (
1412
+ f"The path '{ resolved_path } ' is neither a file nor a directory."
1413
+ )
1407
1414
1408
1415
# Remote paths
1409
1416
fsspec = import_optional_dependency ("fsspec" , extra = scheme )
Original file line number Diff line number Diff line change @@ -89,10 +89,9 @@ def test_nonexistent_path(all_parsers):
89
89
parser = all_parsers
90
90
path = f"{ uuid .uuid4 ()} .csv"
91
91
92
- msg = r"\[Errno 2\] "
93
- with pytest .raises (FileNotFoundError , match = msg ) as e :
92
+ msg = rf"No such file or directory: ' { path } ' "
93
+ with pytest .raises (FileNotFoundError , match = msg ):
94
94
parser .read_csv (path )
95
- assert path == e .value .filename
96
95
97
96
98
97
@pytest .mark .skipif (WASM , reason = "limited file system access on WASM" )
Original file line number Diff line number Diff line change @@ -703,6 +703,9 @@ def test_iterdir_local(local_csv_directory):
703
703
assert file .suffix == ".csv"
704
704
705
705
706
+ def test_iterdir_local_passthrough (local_csv_directory ): ...
707
+
708
+
706
709
def test_remote_csv_directory (remote_csv_directory ):
707
710
import fsspec
708
711
from fsspec .implementations .memory import MemoryFileSystem
You can’t perform that action at this time.
0 commit comments