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

Fix CI mock filesystem fixtures #5740

Merged
merged 8 commits into from
Apr 13, 2023
Merged
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
10 changes: 5 additions & 5 deletions tests/fixtures/fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from pathlib import Path
from unittest.mock import patch

import fsspec
import pytest
from fsspec.implementations.local import AbstractFileSystem, LocalFileSystem, stringify_path
from fsspec.registry import _registry as _fsspec_registry


class MockFileSystem(AbstractFileSystem):
Expand Down Expand Up @@ -92,11 +92,11 @@ def _strip_protocol(cls, path):

@pytest.fixture
def mock_fsspec():
original_registry = fsspec.registry.copy()
fsspec.register_implementation("mock", MockFileSystem, clobber=True)
fsspec.register_implementation("tmp", TmpDirFileSystem, clobber=True)
_fsspec_registry["mock"] = MockFileSystem
_fsspec_registry["tmp"] = TmpDirFileSystem
yield
fsspec.registry = original_registry
del _fsspec_registry["mock"]
del _fsspec_registry["tmp"]


@pytest.fixture
Expand Down
11 changes: 11 additions & 0 deletions tests/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@

import fsspec
import pytest
from fsspec.registry import _registry as _fsspec_registry

from datasets.filesystems import COMPRESSION_FILESYSTEMS, HfFileSystem, extract_path_from_uri, is_remote_filesystem

from .utils import require_lz4, require_zstandard


def test_mockfs(mockfs):
assert "mock" in _fsspec_registry
assert "bz2" in _fsspec_registry


def test_non_mockfs():
assert "mock" not in _fsspec_registry
assert "bz2" in _fsspec_registry


def test_extract_path_from_uri():
mock_bucket = "mock-s3-bucket"
dataset_path = f"s3://{mock_bucket}"
Expand Down
7 changes: 3 additions & 4 deletions tests/test_streaming_download_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import re
from pathlib import Path

import fsspec
import pytest
from fsspec.registry import _registry as _fsspec_registry
from fsspec.spec import AbstractBufferedFile, AbstractFileSystem

from datasets.download.streaming_download_manager import (
Expand Down Expand Up @@ -130,10 +130,9 @@ def _open(

@pytest.fixture
def mock_fsspec():
original_registry = fsspec.registry.copy()
fsspec.register_implementation("mock", DummyTestFS, clobber=True)
_fsspec_registry["mock"] = DummyTestFS
yield
fsspec.registry = original_registry
del _fsspec_registry["mock"]


def _readd_double_slash_removed_by_path(path_as_posix: str) -> str:
Expand Down