Skip to content

Commit

Permalink
Fix can_be_local for pathlib.Path (#1419)
Browse files Browse the repository at this point in the history
  • Loading branch information
BENR0 authored Nov 9, 2023
1 parent 0c829ec commit 4f1c9b6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions fsspec/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io
import sys
from pathlib import Path
from unittest.mock import Mock

import pytest
Expand All @@ -8,6 +9,7 @@
from fsspec.utils import (
can_be_local,
common_prefix,
get_protocol,
infer_storage_options,
merge_offset_ranges,
mirror_from,
Expand Down Expand Up @@ -333,6 +335,24 @@ def test_log():
assert logger.level == logging.DEBUG


@pytest.mark.parametrize(
"par",
[
("afile", "file"),
("file://afile", "file"),
("noproto://afile", "noproto"),
("noproto::stuff", "noproto"),
("simplecache::stuff", "simplecache"),
("simplecache://stuff", "simplecache"),
("s3://afile", "s3"),
(Path("afile"), "file"),
],
)
def test_get_protocol(par):
url, outcome = par
assert get_protocol(url) == outcome


@pytest.mark.parametrize(
"par",
[
Expand All @@ -342,6 +362,7 @@ def test_log():
("noproto::stuff", False),
("simplecache::stuff", True),
("simplecache://stuff", True),
(Path("afile"), True),
],
)
def test_can_local(par):
Expand Down
1 change: 1 addition & 0 deletions fsspec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ def isfilelike(f: Any) -> TypeGuard[IO[bytes]]:


def get_protocol(url: str) -> str:
url = stringify_path(url)
parts = re.split(r"(\:\:|\://)", url, 1)
if len(parts) > 1:
return parts[0]
Expand Down

0 comments on commit 4f1c9b6

Please sign in to comment.