1+ import pathlib
2+
13import numpy as np
24import pytest
35from numpy .testing import assert_array_equal
4- from pytest_asyncio import fixture
56
67import zarr
78from zarr import Array , Group
89from zarr .abc .store import Store
910from zarr .api .synchronous import create , load , open , open_group , save , save_array , save_group
11+ from zarr .store .memory import MemoryStore
1012
1113
1214def test_create_array (memory_store : Store ) -> None :
@@ -30,7 +32,7 @@ def test_create_array(memory_store: Store) -> None:
3032 assert z .chunks == (40 ,)
3133
3234
33- async def test_open_array (memory_store : Store ) -> None :
35+ async def test_open_array (memory_store : MemoryStore ) -> None :
3436 store = memory_store
3537
3638 # open array, create if doesn't exist
@@ -57,7 +59,7 @@ async def test_open_array(memory_store: Store) -> None:
5759 open (store = "doesnotexist" , mode = "r" )
5860
5961
60- async def test_open_group (memory_store : Store ) -> None :
62+ async def test_open_group (memory_store : MemoryStore ) -> None :
6163 store = memory_store
6264
6365 # open group, create if doesn't exist
@@ -85,59 +87,65 @@ def test_save_errors() -> None:
8587 save_group ("data/group.zarr" )
8688 with pytest .raises (TypeError ):
8789 # no array provided
88- save_array ("data/group.zarr" )
90+ save_array ("data/group.zarr" ) # type: ignore[call-arg]
8991 with pytest .raises (ValueError ):
9092 # no arrays provided
9193 save ("data/group.zarr" )
9294
9395
94- @fixture
95- def tmppath (tmpdir ):
96- return str (tmpdir / "example.zarr" )
97-
98-
99- def test_open_with_mode_r (tmppath ) -> None :
96+ def test_open_with_mode_r (tmp_path : pathlib .Path ) -> None :
10097 # 'r' means read only (must exist)
10198 with pytest .raises (FileNotFoundError ):
102- zarr .open (store = tmppath , mode = "r" )
103- zarr .ones (store = tmppath , shape = (3 , 3 ))
104- z2 = zarr .open (store = tmppath , mode = "r" )
99+ zarr .open (store = tmp_path , mode = "r" )
100+ zarr .ones (store = tmp_path , shape = (3 , 3 ))
101+ z2 = zarr .open (store = tmp_path , mode = "r" )
102+ assert isinstance (z2 , Array )
105103 assert (z2 [:] == 1 ).all ()
106104 with pytest .raises (ValueError ):
107105 z2 [:] = 3
108106
109107
110- def test_open_with_mode_r_plus (tmppath ) -> None :
108+ def test_open_with_mode_r_plus (tmp_path : pathlib . Path ) -> None :
111109 # 'r+' means read/write (must exist)
112110 with pytest .raises (FileNotFoundError ):
113- zarr .open (store = tmppath , mode = "r+" )
114- zarr .ones (store = tmppath , shape = (3 , 3 ))
115- z2 = zarr .open (store = tmppath , mode = "r+" )
111+ zarr .open (store = tmp_path , mode = "r+" )
112+ zarr .ones (store = tmp_path , shape = (3 , 3 ))
113+ z2 = zarr .open (store = tmp_path , mode = "r+" )
114+ assert isinstance (z2 , Array )
116115 assert (z2 [:] == 1 ).all ()
117116 z2 [:] = 3
118117
119118
120- def test_open_with_mode_a (tmppath ) -> None :
119+ def test_open_with_mode_a (tmp_path : pathlib . Path ) -> None :
121120 # 'a' means read/write (create if doesn't exist)
122- zarr .open (store = tmppath , mode = "a" , shape = (3 , 3 ))[...] = 1
123- z2 = zarr .open (store = tmppath , mode = "a" )
121+ arr = zarr .open (store = tmp_path , mode = "a" , shape = (3 , 3 ))
122+ assert isinstance (arr , Array )
123+ arr [...] = 1
124+ z2 = zarr .open (store = tmp_path , mode = "a" )
125+ assert isinstance (z2 , Array )
124126 assert (z2 [:] == 1 ).all ()
125127 z2 [:] = 3
126128
127129
128- def test_open_with_mode_w (tmppath ) -> None :
130+ def test_open_with_mode_w (tmp_path : pathlib . Path ) -> None :
129131 # 'w' means create (overwrite if exists);
130- zarr .open (store = tmppath , mode = "w" , shape = (3 , 3 ))[...] = 3
131- z2 = zarr .open (store = tmppath , mode = "w" , shape = (3 , 3 ))
132+ arr = zarr .open (store = tmp_path , mode = "w" , shape = (3 , 3 ))
133+ assert isinstance (arr , Array )
134+
135+ arr [...] = 3
136+ z2 = zarr .open (store = tmp_path , mode = "w" , shape = (3 , 3 ))
137+ assert isinstance (z2 , Array )
132138 assert not (z2 [:] == 3 ).all ()
133139 z2 [:] = 3
134140
135141
136- def test_open_with_mode_w_minus (tmppath ) -> None :
142+ def test_open_with_mode_w_minus (tmp_path : pathlib . Path ) -> None :
137143 # 'w-' means create (fail if exists)
138- zarr .open (store = tmppath , mode = "w-" , shape = (3 , 3 ))[...] = 1
144+ arr = zarr .open (store = tmp_path , mode = "w-" , shape = (3 , 3 ))
145+ assert isinstance (arr , Array )
146+ arr [...] = 1
139147 with pytest .raises (FileExistsError ):
140- zarr .open (store = tmppath , mode = "w-" )
148+ zarr .open (store = tmp_path , mode = "w-" )
141149
142150
143151# def test_lazy_loader():
0 commit comments