Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
test for block hash identity with z5
Browse files Browse the repository at this point in the history
  • Loading branch information
clbarnes committed Jul 17, 2019
1 parent d0670df commit a67d9f5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
17 changes: 12 additions & 5 deletions tests/test_h5_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from h5py_like.test_utils import FileTestBase, DatasetTestBase, GroupTestBase, ModeTestBase
from pyn5 import File

from .common import z5py
from .common import z5py, blocks_hash
from .common import blocks_in, attrs_in

ds_kwargs = deepcopy(DatasetTestBase.dataset_kwargs)
Expand Down Expand Up @@ -98,6 +98,7 @@ def test_created_dirs(file_):


def test_vs_z5(file_, z5_file):
"""Check same as z5"""
z5_path = Path(z5_file.path)
shape = (10, 20)
data = np.arange(np.product(shape)).reshape(shape)
Expand All @@ -113,11 +114,17 @@ def test_vs_z5(file_, z5_file):
for key in ("blockSize", "dimensions", "dataType", "compression"):
assert attrs[key] == z5_attrs[key]

data2 = pyn5.File(z5_path)["ds"][:]
data3 = z5py.N5File(file_._path)["ds"][:]

assert np.array_equal(data, data2)
assert np.array_equal(data2, data3)
def test_vs_z5_hash(file_, z5_file):
"""Check identical block contents to z5"""
z5_path = Path(z5_file.path)
shape = (10, 20)
data = np.arange(np.product(shape)).reshape(shape)

file_.create_dataset("ds", data=data, chunks=(6, 7), compression="raw")
z5_file.create_dataset("ds", data=data, chunks=(6, 7), compression="raw")

assert blocks_hash(file_._path) == blocks_hash(z5_path)


def test_compression_opts(file_, compression_name_opt):
Expand Down
23 changes: 22 additions & 1 deletion tests/test_pyn5.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import pyn5

from .common import blocks_in, attrs_in, z5py
from .common import blocks_in, attrs_in, z5py, blocks_hash
from .conftest import BLOCKSIZE


Expand Down Expand Up @@ -155,6 +155,7 @@ def test_data_ordering(tmp_path):


def test_vs_z5(tmp_path, z5_file):
"""Check different dimensions, same dtype/compression as z5"""
root = tmp_path / "test.n5"

z5_path = Path(z5_file.path)
Expand Down Expand Up @@ -188,6 +189,26 @@ def test_vs_z5(tmp_path, z5_file):
])


def test_vs_z5_hash(tmp_path, z5_file):
"""Check different block hashes to z5"""
root = tmp_path / "test.n5"

z5_path = Path(z5_file.path)
shape = (10, 20)
data = np.arange(np.product(shape)).reshape(shape)
chunks = (6, 7)

pyn5.create_dataset(
str(root), "ds", shape, chunks, data.dtype.name.upper(), json.dumps({"type": "raw"})
)
ds = pyn5.DatasetINT64(str(root), "ds", False)
ds.write_ndarray((0, 0), data, 0)

z5_file.create_dataset("ds", data=data, chunks=(6, 7), compression="raw")

assert blocks_hash(root) != blocks_hash(z5_path)


class TestPythonReadWrite(unittest.TestCase):
def setUp(self):
self.root = "test.n5"
Expand Down

0 comments on commit a67d9f5

Please sign in to comment.