Skip to content

Commit a8d4f42

Browse files
maxrjonesd-v-b
andauthored
Use context manager for temp dirs in store tests (#3110)
Co-authored-by: Davis Bennett <[email protected]>
1 parent d103619 commit a8d4f42

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

tests/test_store/test_core.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,26 @@
1818
)
1919

2020

21+
@pytest.fixture(
22+
params=["none", "temp_dir_str", "temp_dir_path", "store_path", "memory_store", "dict"]
23+
)
24+
def store_like(request):
25+
if request.param == "none":
26+
yield None
27+
elif request.param == "temp_dir_str":
28+
with tempfile.TemporaryDirectory() as temp_dir:
29+
yield temp_dir
30+
elif request.param == "temp_dir_path":
31+
with tempfile.TemporaryDirectory() as temp_dir:
32+
yield Path(temp_dir)
33+
elif request.param == "store_path":
34+
yield StorePath(store=MemoryStore(store_dict={}), path="/")
35+
elif request.param == "memory_store":
36+
yield MemoryStore(store_dict={})
37+
elif request.param == "dict":
38+
yield {}
39+
40+
2141
@pytest.mark.parametrize("path", ["foo", "foo/bar"])
2242
@pytest.mark.parametrize("write_group", [True, False])
2343
@pytest.mark.parametrize("zarr_format", [2, 3])
@@ -134,17 +154,6 @@ async def test_make_store_path_fsspec(monkeypatch) -> None:
134154
assert isinstance(store_path.store, FsspecStore)
135155

136156

137-
@pytest.mark.parametrize(
138-
"store_like",
139-
[
140-
None,
141-
tempfile.TemporaryDirectory().name,
142-
Path(tempfile.TemporaryDirectory().name),
143-
StorePath(store=MemoryStore(store_dict={}), path="/"),
144-
MemoryStore(store_dict={}),
145-
{},
146-
],
147-
)
148157
async def test_make_store_path_storage_options_raises(store_like: StoreLike) -> None:
149158
with pytest.raises(TypeError, match="storage_options"):
150159
await make_store_path(store_like, storage_options={"foo": "bar"})

0 commit comments

Comments
 (0)