Skip to content

Commit db96a07

Browse files
author
brokkoli71
committed
add tests for v2 group attributes and
1 parent 09aebaa commit db96a07

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/test/java/dev/zarr/zarrjava/ZarrPythonTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ public void testZstdLibrary(int clevel, boolean checksumFlag) throws IOException
404404
public void testGroupReadWriteV2() throws Exception {
405405
StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("group_write");
406406
StoreHandle storeHandle2 = new FilesystemStore(TESTOUTPUT).resolve("group_read");
407-
Group group = Group.create(storeHandle);
407+
Group group = Group.create(storeHandle, new Attributes(b -> b.set("attr", "value")));
408408
dev.zarr.zarrjava.v2.DataType dataType = dev.zarr.zarrjava.v2.DataType.INT32;
409409
dev.zarr.zarrjava.v2.Array array = group.createGroup("group").createArray("array", arrayMetadataBuilder -> arrayMetadataBuilder
410410
.withShape(16, 16, 16)
@@ -417,6 +417,7 @@ public void testGroupReadWriteV2() throws Exception {
417417
run_python_script("zarr_python_group_v2.py", storeHandle.toPath().toString(), storeHandle2.toPath().toString());
418418

419419
Group group2 = Group.open(storeHandle2);
420+
Assertions.assertEquals("value", group2.metadata().attributes().get("attr"));
420421
Group subgroup = (Group) group2.get("group2");
421422
Assertions.assertNotNull(subgroup);
422423
dev.zarr.zarrjava.v2.Array array2 = (dev.zarr.zarrjava.v2.Array) subgroup.get("array2");

src/test/java/dev/zarr/zarrjava/ZarrV2Test.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ public void testCreateGroup() throws ZarrException, IOException {
252252

253253
Group.create(storeHandleString);
254254
Assertions.assertTrue(Files.exists(Paths.get(storeHandleString).resolve(".zgroup")));
255+
256+
Group.create(storeHandleString, new Attributes(b -> b.set("some", "value")));
257+
Assertions.assertTrue(Files.exists(Paths.get(storeHandleString).resolve(".zgroup")));
258+
Assertions.assertTrue(Files.exists(Paths.get(storeHandleString).resolve(".zattrs")));
255259
}
256260

257261
@Test

src/test/python-scripts/zarr_python_group_v2.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
expected_data = np.arange(16 * 16 * 16, dtype='int32').reshape(16, 16, 16)
1212

1313
g = zarr.open_group(store=LocalStore(store_path_read), zarr_format=2)
14+
assert g.attrs['attr'] == 'value'
1415
a = g['group']['array']
1516
read_data = a[:, :]
1617
assert np.array_equal(read_data, expected_data), f"got:\n {read_data} \nbut expected:\n {expected_data}"
1718

1819
store_path_write = Path(sys.argv[2])
1920
g2 = zarr.create_group(store=LocalStore(store_path_write), zarr_format=2)
21+
g2.attrs['attr'] = 'value'
2022
a2 = g2.create_group('group2').create_array(
2123
name='array2',
2224
shape=(16, 16, 16),

0 commit comments

Comments
 (0)