2020import pytest
2121import tensorstore as ts
2222
23- pytestmark = pytest .mark .asyncio
24-
2523
2624@contextlib .contextmanager
2725def make_dataset ():
@@ -33,9 +31,7 @@ def make_dataset():
3331 'path' : dir_path ,
3432 },
3533 'metadata' : {
36- 'compression' : {
37- 'type' : 'gzip'
38- },
34+ 'compression' : {'type' : 'gzip' },
3935 'dataType' : 'uint16' ,
4036 'dimensions' : [3 , 4 ],
4137 'blockSize' : [2 , 3 ],
@@ -53,112 +49,138 @@ async def test_transaction_read_write():
5349 assert txn .open
5450 dataset .with_transaction (txn )[1 :2 , 3 :4 ] = 42
5551 dataset .with_transaction (txn )[0 :2 , :1 ] = 5
56- np .testing .assert_equal ([
57- [5 , 0 , 0 , 0 ],
58- [5 , 0 , 0 , 42 ],
59- [0 , 0 , 0 , 0 ],
60- ],
61- dataset .with_transaction (txn ).read ().result ())
62- np .testing .assert_equal ([
63- [0 , 0 , 0 , 0 ],
64- [0 , 0 , 0 , 0 ],
65- [0 , 0 , 0 , 0 ],
66- ],
67- dataset .read ().result ())
52+ np .testing .assert_equal (
53+ [
54+ [5 , 0 , 0 , 0 ],
55+ [5 , 0 , 0 , 42 ],
56+ [0 , 0 , 0 , 0 ],
57+ ],
58+ dataset .with_transaction (txn ).read ().result (),
59+ )
60+ np .testing .assert_equal (
61+ [
62+ [0 , 0 , 0 , 0 ],
63+ [0 , 0 , 0 , 0 ],
64+ [0 , 0 , 0 , 0 ],
65+ ],
66+ dataset .read ().result (),
67+ )
6868 txn .commit_async ().result ()
6969 assert txn .commit_started
7070 assert not txn .open
71- np .testing .assert_equal ([
72- [5 , 0 , 0 , 0 ],
73- [5 , 0 , 0 , 42 ],
74- [0 , 0 , 0 , 0 ],
75- ],
76- dataset .read ().result ())
71+ np .testing .assert_equal (
72+ [
73+ [5 , 0 , 0 , 0 ],
74+ [5 , 0 , 0 , 42 ],
75+ [0 , 0 , 0 , 0 ],
76+ ],
77+ dataset .read ().result (),
78+ )
7779
7880
7981async def test_transaction_context_manager_commit ():
8082 with make_dataset () as dataset :
8183 with ts .Transaction () as txn :
8284 dataset .with_transaction (txn )[1 :2 , 3 :4 ] = 42
83- np .testing .assert_equal ([
84- [0 , 0 , 0 , 0 ],
85- [0 , 0 , 0 , 42 ],
86- [0 , 0 , 0 , 0 ],
87- ],
88- dataset .with_transaction (txn ).read ().result ())
89- np .testing .assert_equal ([
90- [0 , 0 , 0 , 0 ],
91- [0 , 0 , 0 , 0 ],
92- [0 , 0 , 0 , 0 ],
93- ],
94- dataset .read ().result ())
95- np .testing .assert_equal ([
96- [0 , 0 , 0 , 0 ],
97- [0 , 0 , 0 , 42 ],
98- [0 , 0 , 0 , 0 ],
99- ],
100- dataset .read ().result ())
85+ np .testing .assert_equal (
86+ [
87+ [0 , 0 , 0 , 0 ],
88+ [0 , 0 , 0 , 42 ],
89+ [0 , 0 , 0 , 0 ],
90+ ],
91+ dataset .with_transaction (txn ).read ().result (),
92+ )
93+ np .testing .assert_equal (
94+ [
95+ [0 , 0 , 0 , 0 ],
96+ [0 , 0 , 0 , 0 ],
97+ [0 , 0 , 0 , 0 ],
98+ ],
99+ dataset .read ().result (),
100+ )
101+ np .testing .assert_equal (
102+ [
103+ [0 , 0 , 0 , 0 ],
104+ [0 , 0 , 0 , 42 ],
105+ [0 , 0 , 0 , 0 ],
106+ ],
107+ dataset .read ().result (),
108+ )
101109
102110
103111async def test_transaction_context_manager_abort ():
104112 with make_dataset () as dataset :
105113 with pytest .raises (ValueError , match = 'want to abort' ):
106114 with ts .Transaction () as txn :
107115 dataset .with_transaction (txn )[1 :2 , 3 :4 ] = 42
108- np .testing .assert_equal ([
116+ np .testing .assert_equal (
117+ [
118+ [0 , 0 , 0 , 0 ],
119+ [0 , 0 , 0 , 42 ],
120+ [0 , 0 , 0 , 0 ],
121+ ],
122+ dataset .with_transaction (txn ).read ().result (),
123+ )
124+ raise ValueError ('want to abort' )
125+ np .testing .assert_equal (
126+ [
127+ [0 , 0 , 0 , 0 ],
109128 [0 , 0 , 0 , 0 ],
110- [0 , 0 , 0 , 42 ],
111129 [0 , 0 , 0 , 0 ],
112130 ],
113- dataset .with_transaction (txn ).read ().result ())
114- raise ValueError ('want to abort' )
115- np .testing .assert_equal ([
116- [0 , 0 , 0 , 0 ],
117- [0 , 0 , 0 , 0 ],
118- [0 , 0 , 0 , 0 ],
119- ],
120- dataset .read ().result ())
131+ dataset .read ().result (),
132+ )
121133
122134
123135async def test_transaction_async_context_manager_commit ():
124136 with make_dataset () as dataset :
125137 async with ts .Transaction () as txn :
126138 dataset .with_transaction (txn )[1 :2 , 3 :4 ] = 42
127- np .testing .assert_equal ([
128- [0 , 0 , 0 , 0 ],
129- [0 , 0 , 0 , 42 ],
130- [0 , 0 , 0 , 0 ],
131- ],
132- dataset .with_transaction (txn ).read ().result ())
133- np .testing .assert_equal ([
134- [0 , 0 , 0 , 0 ],
135- [0 , 0 , 0 , 0 ],
136- [0 , 0 , 0 , 0 ],
137- ],
138- dataset .read ().result ())
139- np .testing .assert_equal ([
140- [0 , 0 , 0 , 0 ],
141- [0 , 0 , 0 , 42 ],
142- [0 , 0 , 0 , 0 ],
143- ],
144- dataset .read ().result ())
139+ np .testing .assert_equal (
140+ [
141+ [0 , 0 , 0 , 0 ],
142+ [0 , 0 , 0 , 42 ],
143+ [0 , 0 , 0 , 0 ],
144+ ],
145+ dataset .with_transaction (txn ).read ().result (),
146+ )
147+ np .testing .assert_equal (
148+ [
149+ [0 , 0 , 0 , 0 ],
150+ [0 , 0 , 0 , 0 ],
151+ [0 , 0 , 0 , 0 ],
152+ ],
153+ dataset .read ().result (),
154+ )
155+ np .testing .assert_equal (
156+ [
157+ [0 , 0 , 0 , 0 ],
158+ [0 , 0 , 0 , 42 ],
159+ [0 , 0 , 0 , 0 ],
160+ ],
161+ dataset .read ().result (),
162+ )
145163
146164
147165async def test_transaction_async_context_manager_abort ():
148166 with make_dataset () as dataset :
149167 with pytest .raises (ValueError , match = 'want to abort' ):
150168 async with ts .Transaction () as txn :
151169 dataset .with_transaction (txn )[1 :2 , 3 :4 ] = 42
152- np .testing .assert_equal ([
170+ np .testing .assert_equal (
171+ [
172+ [0 , 0 , 0 , 0 ],
173+ [0 , 0 , 0 , 42 ],
174+ [0 , 0 , 0 , 0 ],
175+ ],
176+ dataset .with_transaction (txn ).read ().result (),
177+ )
178+ raise ValueError ('want to abort' )
179+ np .testing .assert_equal (
180+ [
181+ [0 , 0 , 0 , 0 ],
153182 [0 , 0 , 0 , 0 ],
154- [0 , 0 , 0 , 42 ],
155183 [0 , 0 , 0 , 0 ],
156184 ],
157- dataset .with_transaction (txn ).read ().result ())
158- raise ValueError ('want to abort' )
159- np .testing .assert_equal ([
160- [0 , 0 , 0 , 0 ],
161- [0 , 0 , 0 , 0 ],
162- [0 , 0 , 0 , 0 ],
163- ],
164- dataset .read ().result ())
185+ dataset .read ().result (),
186+ )
0 commit comments