Skip to content

Commit

Permalink
Implementation of 'local://' URI Scheme Support (fsspec#150)
Browse files Browse the repository at this point in the history
* Update test_local.py

* Update registry.py

* Linting via nox

* upath: add local to registry tests, skip local on old fsspec version

* tests: xfail https test on ssl errors

* tests: xfail http glob test for fsspec>2023.10.0

---------

Co-authored-by: Andreas Poehlmann <[email protected]>
  • Loading branch information
glesperance and ap-- authored Jan 25, 2024
1 parent befb71e commit 9f8cc86
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions upath/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class _Registry(MutableMapping[str, "type[upath.core.UPath]"]):
"adl": "upath.implementations.cloud.AzurePath",
"az": "upath.implementations.cloud.AzurePath",
"file": "upath.implementations.local.LocalPath",
"local": "upath.implementations.local.LocalPath",
"gcs": "upath.implementations.cloud.GCSPath",
"gs": "upath.implementations.cloud.GCSPath",
"hdfs": "upath.implementations.hdfs.HDFSPath",
Expand Down
25 changes: 25 additions & 0 deletions upath/tests/implementations/test_http.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import pytest # noqa: F401
from fsspec import __version__ as fsspec_version
from fsspec import get_filesystem_class
from packaging.version import Version

from upath import UPath
from upath.implementations.http import HTTPPath

from ..cases import BaseTests
from ..utils import skip_on_windows
from ..utils import xfail_if_no_ssl_connection

try:
get_filesystem_class("http")
Expand All @@ -19,6 +22,7 @@ def test_httppath():
assert path.exists()


@xfail_if_no_ssl_connection
def test_httpspath():
path = UPath("https://example.com")
assert isinstance(path, HTTPPath)
Expand All @@ -38,6 +42,27 @@ def test_work_at_root(self):
def test_mkdir(self):
pass

@pytest.mark.parametrize(
"pattern",
(
"*.txt",
pytest.param(
"*",
marks=pytest.mark.xfail(reason="requires fsspec<=2023.10.0")
if Version(fsspec_version) > Version("2023.10.0")
else (),
),
pytest.param(
"**/*.txt",
marks=pytest.mark.xfail(reason="requires fsspec>=2023.9.0")
if Version(fsspec_version) < Version("2023.9.0")
else (),
),
),
)
def test_glob(self, pathlib_base, pattern):
super().test_glob(pathlib_base, pattern)

@pytest.mark.skip
def test_mkdir_exists_ok_false(self):
pass
Expand Down
13 changes: 13 additions & 0 deletions upath/tests/implementations/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from upath.implementations.local import LocalPath
from upath.tests.cases import BaseTests
from upath.tests.utils import skip_on_windows
from upath.tests.utils import xfail_if_version


@skip_on_windows
Expand All @@ -15,3 +16,15 @@ def path(self, local_testdir):

def test_is_LocalPath(self):
assert isinstance(self.path, LocalPath)


@skip_on_windows
@xfail_if_version("fsspec", lt="2023.10.0", reason="requires fsspec>=2023.10.0")
class TestRayIOFSSpecLocal(BaseTests):
@pytest.fixture(autouse=True)
def path(self, local_testdir):
path = f"local://{local_testdir}"
self.path = UPath(path)

def test_is_LocalPath(self):
assert isinstance(self.path, LocalPath)
1 change: 1 addition & 0 deletions upath/tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"hdfs",
"http",
"https",
"local",
"memory",
"s3",
"s3a",
Expand Down
11 changes: 11 additions & 0 deletions upath/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,14 @@ def xfail_if_version(module, *, reason, **conditions):
for op, val in conditions.items():
cond &= getattr(operator, op)(ver, Version(val))
return pytest.mark.xfail(cond, reason=reason)


def xfail_if_no_ssl_connection(func):
try:
import requests

requests.get("https://example.com")
except (ImportError, requests.exceptions.SSLError):
return pytest.mark.xfail(reason="No SSL connection")(func)
else:
return func

0 comments on commit 9f8cc86

Please sign in to comment.