From 1ac4cf0bce18abc51f78a815db60038d494156fe Mon Sep 17 00:00:00 2001 From: Martin Durant Date: Tue, 19 Nov 2024 17:04:12 -0500 Subject: [PATCH] move tests --- fsspec/implementations/memory.py | 4 +++- fsspec/implementations/tests/memory/memory_test.py | 8 ++++++++ fsspec/tests/abstract/__init__.py | 2 ++ fsspec/tests/abstract/open.py | 11 +++++++++++ fsspec/tests/abstract/pipe.py | 11 +++++++++++ fsspec/tests/abstract/put.py | 8 -------- 6 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 fsspec/tests/abstract/open.py create mode 100644 fsspec/tests/abstract/pipe.py diff --git a/fsspec/implementations/memory.py b/fsspec/implementations/memory.py index 291c806b1..c1c526b56 100644 --- a/fsspec/implementations/memory.py +++ b/fsspec/implementations/memory.py @@ -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() diff --git a/fsspec/implementations/tests/memory/memory_test.py b/fsspec/implementations/tests/memory/memory_test.py index fd0ebaac8..c165d4d82 100644 --- a/fsspec/implementations/tests/memory/memory_test.py +++ b/fsspec/implementations/tests/memory/memory_test.py @@ -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 diff --git a/fsspec/tests/abstract/__init__.py b/fsspec/tests/abstract/__init__.py index 44181420f..0b660cf23 100644 --- a/fsspec/tests/abstract/__init__.py +++ b/fsspec/tests/abstract/__init__.py @@ -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: diff --git a/fsspec/tests/abstract/open.py b/fsspec/tests/abstract/open.py new file mode 100644 index 000000000..bb75ea852 --- /dev/null +++ b/fsspec/tests/abstract/open.py @@ -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") diff --git a/fsspec/tests/abstract/pipe.py b/fsspec/tests/abstract/pipe.py new file mode 100644 index 000000000..8ecca96e9 --- /dev/null +++ b/fsspec/tests/abstract/pipe.py @@ -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" diff --git a/fsspec/tests/abstract/put.py b/fsspec/tests/abstract/put.py index 21bd1aa2b..9fc349977 100644 --- a/fsspec/tests/abstract/put.py +++ b/fsspec/tests/abstract/put.py @@ -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 ):