Skip to content

Commit 53b5710

Browse files
authored
Fix upath core tests (#130)
* 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
1 parent 707adbe commit 53b5710

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
3+
from upath import UPath
4+
from upath.implementations.local import LocalPath
5+
from upath.tests.cases import BaseTests
6+
from upath.tests.utils import skip_on_windows
7+
8+
9+
@skip_on_windows
10+
class TestFSSpecLocal(BaseTests):
11+
@pytest.fixture(autouse=True)
12+
def path(self, local_testdir):
13+
path = f"file://{local_testdir}"
14+
self.path = UPath(path)
15+
16+
def test_is_LocalPath(self):
17+
assert isinstance(self.path, LocalPath)

upath/tests/test_core.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,12 @@ def test_home(self):
6767
assert isinstance(pth, UPath)
6868

6969

70-
@pytest.mark.hdfs
71-
def test_multiple_backend_paths(local_testdir, s3_fixture, hdfs):
72-
_, anon, s3so = s3_fixture
70+
def test_multiple_backend_paths(local_testdir):
7371
path = f"s3:{local_testdir}"
74-
s3_path = UPath(path, anon=anon, **s3so)
72+
s3_path = UPath(path, anon=True)
7573
assert s3_path.joinpath("text.txt")._url.scheme == "s3"
76-
host, user, port = hdfs
77-
path = f"hdfs:{local_testdir}"
78-
UPath(path, host=host, user=user, port=port)
74+
path = f"file://{local_testdir}"
75+
UPath(path)
7976
assert s3_path.joinpath("text1.txt")._url.scheme == "s3"
8077

8178

@@ -125,20 +122,12 @@ def test_new_method(local_testdir):
125122
assert isinstance(path, UPath)
126123

127124

128-
@skip_on_windows
129-
class TestFSSpecLocal(BaseTests):
130-
@pytest.fixture(autouse=True)
131-
def path(self, local_testdir):
132-
path = f"file://{local_testdir}"
133-
self.path = UPath(path)
134-
135-
136125
PATHS = (
137126
("path", "storage_options", "module", "object_type"),
138127
(
139-
("/tmp/abc", (), None, pathlib.Path),
140-
("s3://bucket/folder", ({"anon": True}), "s3fs", S3Path),
141-
("gs://bucket/folder", ({"token": "anon"}), "gcsfs", GCSPath),
128+
("/tmp/abc", {}, None, pathlib.Path),
129+
("s3://bucket/folder", {"anon": True}, "s3fs", S3Path),
130+
("gs://bucket/folder", {"token": "anon"}, "gcsfs", GCSPath),
142131
),
143132
)
144133

@@ -150,7 +139,7 @@ def test_create_from_type(path, storage_options, module, object_type):
150139
# skip if module cannot be imported
151140
pytest.importorskip(module)
152141
try:
153-
upath = UPath(path, storage_options=storage_options)
142+
upath = UPath(path, **storage_options)
154143
# test expected object type
155144
assert isinstance(upath, object_type)
156145
cast = type(upath)
@@ -159,7 +148,7 @@ def test_create_from_type(path, storage_options, module, object_type):
159148
assert isinstance(parent, cast)
160149
# test that created fs uses fsspec instance cache
161150
assert not hasattr(upath, "fs") or upath.fs is parent.fs
162-
new = cast(str(parent))
151+
new = cast(str(parent), **storage_options)
163152
# test that object cast is same type
164153
assert isinstance(new, cast)
165154
except ImportError:
@@ -190,7 +179,7 @@ def test_child_path():
190179

191180

192181
def test_pickling():
193-
path = UPath("gcs://bucket/folder", storage_options={"anon": True})
182+
path = UPath("gcs://bucket/folder", token="anon")
194183
pickled_path = pickle.dumps(path)
195184
recovered_path = pickle.loads(pickled_path)
196185

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

201190

202191
def test_pickling_child_path():
203-
path = UPath("gcs://bucket", anon=True) / "subfolder" / "subsubfolder"
192+
path = UPath("gcs://bucket", token="anon") / "subfolder" / "subsubfolder"
204193
pickled_path = pickle.dumps(path)
205194
recovered_path = pickle.loads(pickled_path)
206195

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

214203

215204
def test_copy_path():
216-
path = UPath("gcs://bucket/folder", anon=True)
205+
path = UPath("gcs://bucket/folder", token="anon")
217206
copy_path = UPath(path)
218207

219208
assert type(path) == type(copy_path)

0 commit comments

Comments
 (0)