Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for implementation signatures #1104

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions fsspec/implementations/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

import fsspec
from fsspec.implementations.arrow import ArrowFSWrapper
from fsspec.implementations.local import LocalFileSystem
from fsspec.implementations.memory import MemoryFileSystem
Expand All @@ -24,15 +25,23 @@ class MultiProtocolFileSystem(LocalFileSystem):

@pytest.fixture(scope="function")
def fs(request):
pyarrow_fs = pytest.importorskip("pyarrow.fs")
FileSystem = pyarrow_fs.FileSystem
if request.param == "arrow":
pyarrow_fs = pytest.importorskip("pyarrow.fs")
FileSystem = pyarrow_fs.FileSystem
fs = ArrowFSWrapper(FileSystem.from_uri("file:///")[0])
return fs
cls = FILESYSTEMS[request.param]
return cls()


@pytest.fixture(scope="function")
def fscls(request):
try:
return fsspec.get_filesystem_class(request.param)
except ImportError:
pytest.skip(f"filesystem {request.param} not installed")
martindurant marked this conversation as resolved.
Show resolved Hide resolved


@pytest.fixture(scope="function")
def temp_file():
with tempfile.TemporaryDirectory() as temp_dir:
Expand Down
114 changes: 114 additions & 0 deletions fsspec/implementations/tests/test_common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import time
from inspect import signature

import pytest

Expand Down Expand Up @@ -31,3 +32,116 @@ def test_modified(fs: AbstractFileSystem, temp_file):
assert modified > created
finally:
fs.rm(temp_file)


@pytest.mark.xfail
@pytest.mark.parametrize(
"method",
[
"cat",
"cat_file",
"cat_ranges",
"checksum",
"copy",
"cp",
"cp_file",
"created",
"delete",
"disk_usage",
"download",
"du",
"end_transaction",
"exists",
"expand_path",
"find",
"from_json",
"get",
"get_file",
"get_mapper",
"glob",
"head",
"info",
"invalidate_cache",
"isdir",
"isfile",
"lexists",
"listdir",
"ls",
"makedir",
"makedirs",
"mkdir",
"mkdirs",
"modified",
"move",
"mv",
"open",
"pipe",
"pipe_file",
"put",
"put_file",
"read_block",
"read_bytes",
"read_text",
"rename",
"rm",
"rm_file",
"rmdir",
"sign",
"size",
"sizes",
"start_transaction",
"stat",
"tail",
"to_json",
"touch",
"ukey",
"unstrip_protocol",
"upload",
"walk",
"write_bytes",
"write_text",
],
)
@pytest.mark.parametrize(
"fscls",
[
"file",
"memory",
"http",
"zip",
"tar",
"sftp",
"ssh",
"ftp",
"webhdfs",
"cached",
"blockcache",
"filecache",
"simplecache",
"dask",
"dbfs",
"github",
"git",
"smb",
"jupyter",
"libarchive",
"reference",
"hdfs",
],
indirect=["fscls"],
)
def test_signature(fscls, method):
abstract_fs = AbstractFileSystem
abs_signature = signature(getattr(abstract_fs, method))
fs_signature = signature(getattr(fscls, method))
# We only compare parameters shown in the abstract class
# We allow extra parameters in the subclass
for k1, k2 in zip(abs_signature.parameters, fs_signature.parameters):
if k1 in ["self", "args", "kwargs"]:
continue
assert (
abs_signature.parameters[k1].kind == fs_signature.parameters[k2].kind
), f"{abs_signature} != {fs_signature}"
assert (
abs_signature.parameters[k1].default == fs_signature.parameters[k2].default
), f"{abs_signature} != {fs_signature}"