1
+ import pathlib
2
+
1
3
import numpy as np
2
4
import pytest
3
5
from numpy .testing import assert_array_equal
4
- from pytest_asyncio import fixture
5
6
6
7
import zarr
7
8
from zarr import Array , Group
8
9
from zarr .abc .store import Store
9
10
from zarr .api .synchronous import create , load , open , open_group , save , save_array , save_group
11
+ from zarr .store .memory import MemoryStore
10
12
11
13
12
14
def test_create_array (memory_store : Store ) -> None :
@@ -30,7 +32,7 @@ def test_create_array(memory_store: Store) -> None:
30
32
assert z .chunks == (40 ,)
31
33
32
34
33
- async def test_open_array (memory_store : Store ) -> None :
35
+ async def test_open_array (memory_store : MemoryStore ) -> None :
34
36
store = memory_store
35
37
36
38
# open array, create if doesn't exist
@@ -57,7 +59,7 @@ async def test_open_array(memory_store: Store) -> None:
57
59
open (store = "doesnotexist" , mode = "r" )
58
60
59
61
60
- async def test_open_group (memory_store : Store ) -> None :
62
+ async def test_open_group (memory_store : MemoryStore ) -> None :
61
63
store = memory_store
62
64
63
65
# open group, create if doesn't exist
@@ -85,59 +87,65 @@ def test_save_errors() -> None:
85
87
save_group ("data/group.zarr" )
86
88
with pytest .raises (TypeError ):
87
89
# no array provided
88
- save_array ("data/group.zarr" )
90
+ save_array ("data/group.zarr" ) # type: ignore[call-arg]
89
91
with pytest .raises (ValueError ):
90
92
# no arrays provided
91
93
save ("data/group.zarr" )
92
94
93
95
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 :
100
97
# 'r' means read only (must exist)
101
98
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 )
105
103
assert (z2 [:] == 1 ).all ()
106
104
with pytest .raises (ValueError ):
107
105
z2 [:] = 3
108
106
109
107
110
- def test_open_with_mode_r_plus (tmppath ) -> None :
108
+ def test_open_with_mode_r_plus (tmp_path : pathlib . Path ) -> None :
111
109
# 'r+' means read/write (must exist)
112
110
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 )
116
115
assert (z2 [:] == 1 ).all ()
117
116
z2 [:] = 3
118
117
119
118
120
- def test_open_with_mode_a (tmppath ) -> None :
119
+ def test_open_with_mode_a (tmp_path : pathlib . Path ) -> None :
121
120
# '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 )
124
126
assert (z2 [:] == 1 ).all ()
125
127
z2 [:] = 3
126
128
127
129
128
- def test_open_with_mode_w (tmppath ) -> None :
130
+ def test_open_with_mode_w (tmp_path : pathlib . Path ) -> None :
129
131
# '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 )
132
138
assert not (z2 [:] == 3 ).all ()
133
139
z2 [:] = 3
134
140
135
141
136
- def test_open_with_mode_w_minus (tmppath ) -> None :
142
+ def test_open_with_mode_w_minus (tmp_path : pathlib . Path ) -> None :
137
143
# '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
139
147
with pytest .raises (FileExistsError ):
140
- zarr .open (store = tmppath , mode = "w-" )
148
+ zarr .open (store = tmp_path , mode = "w-" )
141
149
142
150
143
151
# def test_lazy_loader():
0 commit comments