Skip to content

Commit 58cb4f4

Browse files
committed
add tests for fsspec.utils.stringify_path and remove redundant check
1 parent d315173 commit 58cb4f4

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

fsspec/tests/test_utils.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import io
22
import sys
3-
from pathlib import Path
3+
from pathlib import Path, PurePath
44
from unittest.mock import Mock
55

66
import pytest
@@ -440,3 +440,39 @@ def test_size():
440440
f = io.BytesIO(b"hello")
441441
assert fsspec.utils.file_size(f) == 5
442442
assert f.tell() == 0
443+
444+
445+
class _HasFspath:
446+
def __fspath__(self):
447+
return "foo"
448+
449+
450+
class _HasPathAttr:
451+
def __init__(self):
452+
self.path = "foo"
453+
454+
455+
@pytest.mark.parametrize(
456+
"path,expected",
457+
[
458+
# coerce to string
459+
("foo", "foo"),
460+
(Path("foo"), "foo"),
461+
(PurePath("foo"), "foo"),
462+
(_HasFspath(), "foo"),
463+
(_HasPathAttr(), "foo"),
464+
# passthrough
465+
(b"bytes", b"bytes"),
466+
(None, None),
467+
(1, 1),
468+
(True, True),
469+
(o := object(), o),
470+
([], []),
471+
((), ()),
472+
(set(), set()),
473+
],
474+
)
475+
def test_stringify_path(path, expected):
476+
path = fsspec.utils.stringify_path(path)
477+
478+
assert path == expected

fsspec/utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,6 @@ def stringify_path(filepath: str | os.PathLike[str] | pathlib.Path) -> str:
350350
return filepath
351351
elif hasattr(filepath, "__fspath__"):
352352
return filepath.__fspath__()
353-
elif isinstance(filepath, pathlib.Path):
354-
return str(filepath)
355353
elif hasattr(filepath, "path"):
356354
return filepath.path
357355
else:

0 commit comments

Comments
 (0)