Skip to content

Commit

Permalink
Fix upath core tests (#130)
Browse files Browse the repository at this point in the history
* tests: test_core pass storage_options correctly

* tests: test_core gcs tests need token='anon'

* tests: test_core test multiple filesystem interaction without s3_fixture

* tests: move file:// tests to test_local implementation
  • Loading branch information
ap-- authored Aug 6, 2023
1 parent 707adbe commit 53b5710
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
17 changes: 17 additions & 0 deletions upath/tests/implementations/test_local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

from upath import UPath
from upath.implementations.local import LocalPath
from upath.tests.cases import BaseTests
from upath.tests.utils import skip_on_windows


@skip_on_windows
class TestFSSpecLocal(BaseTests):
@pytest.fixture(autouse=True)
def path(self, local_testdir):
path = f"file://{local_testdir}"
self.path = UPath(path)

def test_is_LocalPath(self):
assert isinstance(self.path, LocalPath)
35 changes: 12 additions & 23 deletions upath/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,12 @@ def test_home(self):
assert isinstance(pth, UPath)


@pytest.mark.hdfs
def test_multiple_backend_paths(local_testdir, s3_fixture, hdfs):
_, anon, s3so = s3_fixture
def test_multiple_backend_paths(local_testdir):
path = f"s3:{local_testdir}"
s3_path = UPath(path, anon=anon, **s3so)
s3_path = UPath(path, anon=True)
assert s3_path.joinpath("text.txt")._url.scheme == "s3"
host, user, port = hdfs
path = f"hdfs:{local_testdir}"
UPath(path, host=host, user=user, port=port)
path = f"file://{local_testdir}"
UPath(path)
assert s3_path.joinpath("text1.txt")._url.scheme == "s3"


Expand Down Expand Up @@ -125,20 +122,12 @@ def test_new_method(local_testdir):
assert isinstance(path, UPath)


@skip_on_windows
class TestFSSpecLocal(BaseTests):
@pytest.fixture(autouse=True)
def path(self, local_testdir):
path = f"file://{local_testdir}"
self.path = UPath(path)


PATHS = (
("path", "storage_options", "module", "object_type"),
(
("/tmp/abc", (), None, pathlib.Path),
("s3://bucket/folder", ({"anon": True}), "s3fs", S3Path),
("gs://bucket/folder", ({"token": "anon"}), "gcsfs", GCSPath),
("/tmp/abc", {}, None, pathlib.Path),
("s3://bucket/folder", {"anon": True}, "s3fs", S3Path),
("gs://bucket/folder", {"token": "anon"}, "gcsfs", GCSPath),
),
)

Expand All @@ -150,7 +139,7 @@ def test_create_from_type(path, storage_options, module, object_type):
# skip if module cannot be imported
pytest.importorskip(module)
try:
upath = UPath(path, storage_options=storage_options)
upath = UPath(path, **storage_options)
# test expected object type
assert isinstance(upath, object_type)
cast = type(upath)
Expand All @@ -159,7 +148,7 @@ def test_create_from_type(path, storage_options, module, object_type):
assert isinstance(parent, cast)
# test that created fs uses fsspec instance cache
assert not hasattr(upath, "fs") or upath.fs is parent.fs
new = cast(str(parent))
new = cast(str(parent), **storage_options)
# test that object cast is same type
assert isinstance(new, cast)
except ImportError:
Expand Down Expand Up @@ -190,7 +179,7 @@ def test_child_path():


def test_pickling():
path = UPath("gcs://bucket/folder", storage_options={"anon": True})
path = UPath("gcs://bucket/folder", token="anon")
pickled_path = pickle.dumps(path)
recovered_path = pickle.loads(pickled_path)

Expand All @@ -200,7 +189,7 @@ def test_pickling():


def test_pickling_child_path():
path = UPath("gcs://bucket", anon=True) / "subfolder" / "subsubfolder"
path = UPath("gcs://bucket", token="anon") / "subfolder" / "subsubfolder"
pickled_path = pickle.dumps(path)
recovered_path = pickle.loads(pickled_path)

Expand All @@ -213,7 +202,7 @@ def test_pickling_child_path():


def test_copy_path():
path = UPath("gcs://bucket/folder", anon=True)
path = UPath("gcs://bucket/folder", token="anon")
copy_path = UPath(path)

assert type(path) == type(copy_path)
Expand Down

0 comments on commit 53b5710

Please sign in to comment.