Skip to content

Commit

Permalink
move tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martindurant committed Nov 19, 2024
1 parent 06e1dd2 commit 1ac4cf0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
4 changes: 3 additions & 1 deletion fsspec/implementations/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ def _open(
return f
else:
raise FileNotFoundError(path)
elif mode == "wb":
elif mode in {"wb", "xb"}:
if mode == "xb" and self.exists(path):
raise FileExistsError
m = MemoryFile(self, path, kwargs.get("data"))
if not self._intrans:
m.commit()
Expand Down
8 changes: 8 additions & 0 deletions fsspec/implementations/tests/memory/memory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ class TestMemoryGet(abstract.AbstractGetTests, MemoryFixtures):

class TestMemoryPut(abstract.AbstractPutTests, MemoryFixtures):
pass


class TestMemoryPipe(abstract.AbstractPipeTests, MemoryFixtures):
pass


class TestMemoryOpen(abstract.AbstractOpenTests, MemoryFixtures):
pass
2 changes: 2 additions & 0 deletions fsspec/tests/abstract/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from fsspec.implementations.local import LocalFileSystem
from fsspec.tests.abstract.copy import AbstractCopyTests # noqa: F401
from fsspec.tests.abstract.get import AbstractGetTests # noqa: F401
from fsspec.tests.abstract.open import AbstractOpenTests # noqa: F401
from fsspec.tests.abstract.put import AbstractPutTests # noqa: F401
from fsspec.tests.abstract.pipe import AbstractPipeTests # noqa: F401


class BaseAbstractFixtures:
Expand Down
11 changes: 11 additions & 0 deletions fsspec/tests/abstract/open.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest


class AbstractOpenTests:
def test_open_exclusive(self, fs, fs_target):
with fs.open(fs_target, "wb") as f:
f.write(b"data")
with fs.open(fs_target, "rb") as f:
assert f.read() == b"data"
with pytest.raises(FileExistsError):
fs.open(fs_target, "xb")
11 changes: 11 additions & 0 deletions fsspec/tests/abstract/pipe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest


class AbstractPipeTests:
def test_pipe_exclusive(self, fs, fs_target):
fs.pipe_file(fs_target, b"data")
assert fs.cat_file(fs_target) == b"data"
with pytest.raises(FileExistsError):
fs.pipe_file(fs_target, b"data", mode="create")
fs.pipe_file(fs_target, b"new data", mode="overwrite")
assert fs.cat_file(fs_target) == b"new data"
8 changes: 0 additions & 8 deletions fsspec/tests/abstract/put.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,14 +568,6 @@ def test_put_directory_without_files_with_same_name_prefix(
assert fs.isfile(fs_join(fs_target, "subdir", "subfile.txt"))
assert fs.isfile(fs_join(fs_target, "subdir.txt"))

def test_pipe_exclusive(self, fs, fs_target):
fs.pipe_file(fs_target, b"data")
assert fs.cat_file(fs_target) == b"data"
with pytest.raises(FileExistsError):
fs.pipe_file(fs_target, b"data", mode="create")
fs.pipe_file(fs_target, b"new data", mode="overwrite")
assert fs.cat_file(fs_target) == b"new data"

def test_copy_with_source_and_destination_as_list(
self, fs, fs_target, fs_join, local_join, local_10_files_with_hashed_names
):
Expand Down

0 comments on commit 1ac4cf0

Please sign in to comment.