Skip to content

Commit f459a52

Browse files
committed
add group attributes unit tests
1 parent 13ccf1a commit f459a52

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ public void testCreateBlosc(String cname, String shuffle, int clevel) throws IOE
3838
Assertions.assertEquals(0, outArray.getByte(0));
3939
}
4040

41-
42-
4341
@ParameterizedTest
4442
@CsvSource({
4543
"BOOL", "FLOAT64"
@@ -48,7 +46,7 @@ public void testReadBloscDetectTypesize(DataType dt) throws IOException, ZarrExc
4846
String arrayname = dt == DataType.BOOL ? "bool" : "double";
4947
StoreHandle storeHandle = new FilesystemStore(TESTDATA).resolve("v2_sample", arrayname);
5048
Array array = Array.open(storeHandle);
51-
ucar.ma2.Array output = array.read(new long[]{0, 0, 0}, new int[]{3, 4, 5});
49+
array.read(new long[]{0, 0, 0}, new int[]{3, 4, 5});
5250
Assertions.assertEquals(dt, array.metadata().dataType);
5351
}
5452

@@ -344,4 +342,18 @@ public void testResizeArray() throws IOException, ZarrException {
344342
Arrays.fill(expectedData, 1);
345343
Assertions.assertArrayEquals(expectedData, (int[]) data.get1DJavaArray(ma2DataType));
346344
}
345+
346+
@Test
347+
public void testGroupAttributes() throws IOException, ZarrException {
348+
StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("testGroupAttributesV2");
349+
350+
Group group = Group.create(storeHandle, new Attributes() {{
351+
put("group_attr", "group_value");
352+
}});
353+
354+
Assertions.assertEquals("group_value", group.metadata().attributes().getString("group_attr"));
355+
356+
group = Group.open(storeHandle);
357+
Assertions.assertEquals("group_value", group.metadata().attributes().getString("group_attr"));
358+
}
347359
}

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,16 +556,17 @@ public void testCreateGroup() throws ZarrException, IOException {
556556

557557
Group group = Group.create(storeHandle, new GroupMetadata(attributes));
558558
Assertions.assertTrue(storeHandle.resolve("zarr.json").exists());
559-
Assertions.assertEquals("world", group.metadata.attributes.get("hello"));
559+
Assertions.assertEquals("world", group.metadata.attributes().get("hello"));
560560

561561
group = Group.create(storeHandlePath, new GroupMetadata(attributes));
562562
Assertions.assertTrue(Files.exists(storeHandlePath.resolve("zarr.json")));
563-
Assertions.assertEquals("world", group.metadata.attributes.get("hello"));
563+
Assertions.assertEquals("world", group.metadata.attributes().get("hello"));
564564

565565
group = Group.create(storeHandleString, new GroupMetadata(attributes));
566566
Assertions.assertTrue(Files.exists(Paths.get(storeHandleString).resolve("zarr.json")));
567-
Assertions.assertEquals("world", group.metadata.attributes.get("hello"));
567+
Assertions.assertEquals("world", group.metadata.attributes().get("hello"));
568568
}
569+
569570
@Test
570571
public void testAttributes() throws IOException, ZarrException {
571572
StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("testAttributesV3");
@@ -593,7 +594,6 @@ public void testAttributes() throws IOException, ZarrException {
593594
Assertions.assertEquals("attribute", arrayOpened.metadata().attributes().getString("another"));
594595
}
595596

596-
597597
@Test
598598
public void testSetAndUpdateAttributes() throws IOException, ZarrException {
599599
StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("testSetAttributesV3");
@@ -654,4 +654,18 @@ public void testResizeArray() throws IOException, ZarrException {
654654
Arrays.fill(expectedData, 1);
655655
Assertions.assertArrayEquals(expectedData, (int[]) data.get1DJavaArray(ma2DataType));
656656
}
657+
658+
@Test
659+
public void testGroupAttributes() throws IOException, ZarrException {
660+
StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("testGroupAttributesV3");
661+
662+
Group group = Group.create(storeHandle, new Attributes() {{
663+
put("group_attr", "group_value");
664+
}});
665+
666+
Assertions.assertEquals("group_value", group.metadata().attributes().getString("group_attr"));
667+
668+
group = Group.open(storeHandle);
669+
Assertions.assertEquals("group_value", group.metadata().attributes().getString("group_attr"));
670+
}
657671
}

0 commit comments

Comments
 (0)