4
4
import atexit
5
5
import json
6
6
import shutil
7
+ import os
7
8
from multiprocessing .pool import ThreadPool , Pool as ProcessPool
8
9
from multiprocessing import cpu_count
9
10
import tempfile
26
27
from zarr .hierarchy import Group
27
28
28
29
29
- if PY2 :
30
-
31
- class TemporaryDirectory (object ):
32
- def __init__ (self ):
33
- self .name = tempfile .mkdtemp ()
34
- atexit .register (atexit_rmtree , self .name )
35
-
36
- else :
37
- from tempfile import TemporaryDirectory
38
-
39
-
40
30
class TestAttributesWithThreadSynchronizer (TestAttributes ):
41
31
42
32
def init_attributes (self , store , read_only = False ):
@@ -79,7 +69,7 @@ def _set_arange(arg):
79
69
class MixinArraySyncTests (object ):
80
70
81
71
def test_parallel_setitem (self ):
82
- n = 200
72
+ n = 20
83
73
84
74
# setup
85
75
arr = self .create_array (shape = n * 1000 , chunks = 999 , dtype = 'i4' )
@@ -94,7 +84,7 @@ def test_parallel_setitem(self):
94
84
assert_array_equal (np .arange (n * 1000 ), arr [:])
95
85
96
86
def test_parallel_append (self ):
97
- n = 200
87
+ n = 20
98
88
99
89
# setup
100
90
arr = self .create_array (shape = 1000 , chunks = 999 , dtype = 'i4' )
@@ -140,9 +130,12 @@ def create_pool(self):
140
130
class TestArrayWithProcessSynchronizer (TestArray , MixinArraySyncTests ):
141
131
142
132
def create_array (self , read_only = False , ** kwargs ):
143
- store = DirectoryStore (TemporaryDirectory ().name )
133
+ path = 'test_sync'
134
+ if os .path .exists (path ):
135
+ shutil .rmtree (path )
136
+ store = DirectoryStore (path )
144
137
init_array (store , ** kwargs )
145
- synchronizer = ProcessSynchronizer (TemporaryDirectory (). name )
138
+ synchronizer = ProcessSynchronizer ('test_sync_locks' )
146
139
return Array (store , synchronizer = synchronizer ,
147
140
read_only = read_only , cache_metadata = False )
148
141
@@ -242,15 +235,18 @@ def test_synchronizer_property(self):
242
235
class TestGroupWithProcessSynchronizer (TestGroup , MixinGroupSyncTests ):
243
236
244
237
def create_store (self ):
245
- return DirectoryStore (TemporaryDirectory ().name ), None
238
+ path = 'test_sync'
239
+ if os .path .exists (path ):
240
+ shutil .rmtree (path )
241
+ store = DirectoryStore (path )
242
+ return store , None
246
243
247
244
def create_group (self , store = None , path = None , read_only = False ,
248
245
chunk_store = None , synchronizer = None ):
249
246
if store is None :
250
- store = DirectoryStore (TemporaryDirectory ().name )
251
- chunk_store = None
247
+ store , chunk_store = self .create_store ()
252
248
init_group (store , path = path , chunk_store = chunk_store )
253
- synchronizer = ProcessSynchronizer (TemporaryDirectory (). name )
249
+ synchronizer = ProcessSynchronizer ('test_sync_locks' )
254
250
g = Group (store , path = path , read_only = read_only ,
255
251
synchronizer = synchronizer , chunk_store = chunk_store )
256
252
return g
0 commit comments