Skip to content

Commit 942bcfb

Browse files
author
Martin Durant
committed
Separate tests
1 parent 7885fbd commit 942bcfb

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

zarr/creation.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,15 @@ def create(shape, chunks=True, dtype=None, compressor='default',
127127
return z
128128

129129

130-
def normalize_store_arg(store, clobber=False, default=dict):
130+
def normalize_store_arg(store, clobber=False, default=dict, storage_options=None):
131131
if store is None:
132132
return default()
133133
elif isinstance(store, str):
134134
mode = 'w' if clobber else 'r'
135-
if "://" in store:
136-
return FSStore(store)
135+
if "://" in store or "::" in store:
136+
return FSStore(store, **(storage_options or {}))
137+
elif storage_options:
138+
raise ValueError("storage_options passed with non-fsspec path")
137139
if store.endswith('.zip'):
138140
return ZipStore(store, mode=mode)
139141
elif store.endswith('.n5'):
@@ -437,9 +439,11 @@ def open_array(store=None, mode='a', shape=None, chunks=True, dtype=None,
437439

438440
# handle polymorphic store arg
439441
clobber = mode == 'w'
440-
store = normalize_store_arg(store, clobber=clobber)
442+
storage_options = kwargs.pop("storage_options", None)
443+
store = normalize_store_arg(store, clobber=clobber, storage_options=storage_options)
441444
if chunk_store is not None:
442-
chunk_store = normalize_store_arg(chunk_store, clobber=clobber)
445+
chunk_store = normalize_store_arg(chunk_store, clobber=clobber,
446+
storage_options=storage_options)
443447
path = normalize_storage_path(path)
444448

445449
# API compatibility with h5py

zarr/hierarchy.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,8 +1032,9 @@ def move(self, source, dest):
10321032
self._write_op(self._move_nosync, source, dest)
10331033

10341034

1035-
def _normalize_store_arg(store, clobber=False):
1036-
return normalize_store_arg(store, clobber=clobber, default=MemoryStore)
1035+
def _normalize_store_arg(store, clobber=False, storage_options=None):
1036+
return normalize_store_arg(store, clobber=clobber, default=MemoryStore,
1037+
storage_options=storage_options)
10371038

10381039

10391040
def group(store=None, overwrite=False, chunk_store=None,

zarr/tests/test_storage.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
array_meta_key, atexit_rmglob, atexit_rmtree,
3030
attrs_key, default_compressor, getsize,
3131
group_meta_key, init_array, init_group, migrate_1to2)
32-
from zarr.storage import FSStore as NestedDirectoryStore
33-
from zarr.storage import FSStore as DirectoryStore
32+
from zarr.storage import FSStore
3433
from zarr.tests.util import CountingDict, skip_test_env_var
3534

3635

@@ -829,6 +828,30 @@ def test_normalize_keys(self):
829828
assert 'foo' in store
830829

831830

831+
class TestFSStore(StoreTests, unittest.TestCase):
832+
833+
def create_store(self, normalize_keys=False):
834+
path = tempfile.mkdtemp()
835+
atexit.register(atexit_rmtree, path)
836+
store = FSStore(path, normalize_keys=normalize_keys)
837+
return store
838+
839+
def test_complex(self):
840+
path1 = tempfile.mkdtemp()
841+
path2 = tempfile.mkdtemp()
842+
store = FSStore("simplecache::file://" + path1,
843+
simplecache={"same_names": True, "cache_storage": path2})
844+
assert not store
845+
assert not os.listdir(path1)
846+
assert not os.listdir(path2)
847+
store['foo'] = b"hello"
848+
assert 'foo' in os.listdir(path1)
849+
assert 'foo' in store
850+
assert not os.listdir(path2)
851+
assert store["foo"] == b"hello"
852+
assert 'foo' in os.listdir(path2)
853+
854+
832855
class TestNestedDirectoryStore(TestDirectoryStore, unittest.TestCase):
833856

834857
def create_store(self, normalize_keys=False):
@@ -964,6 +987,16 @@ def test_filters(self):
964987
init_array(store, shape=1000, chunks=100, filters=filters)
965988

966989

990+
class TestNestedFSStore(TestNestedDirectoryStore):
991+
992+
def create_store(self, normalize_keys=False):
993+
path = tempfile.mkdtemp()
994+
atexit.register(atexit_rmtree, path)
995+
store = FSStore(path, normalize_keys=normalize_keys,
996+
key_separator='/', auto_mkdir=True)
997+
return store
998+
999+
9671000
class TestTempStore(StoreTests, unittest.TestCase):
9681001

9691002
def create_store(self):

0 commit comments

Comments
 (0)