Skip to content

Commit 4125940

Browse files
committed
fix testReadFromZarrita for gzip
1 parent dd3e939 commit 4125940

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@
3333
import java.util.stream.Stream;
3434

3535
import dev.zarr.zarrjava.v3.codec.CodecBuilder;
36-
import org.junit.Ignore;
37-
import org.junit.Test;
38-
import org.junit.jupiter.api.Assertions;
39-
import org.junit.jupiter.api.BeforeAll;
36+
37+
import org.junit.jupiter.api.*;
4038
import org.junit.jupiter.params.ParameterizedTest;
4139
import org.junit.jupiter.params.provider.ValueSource;
4240

@@ -66,8 +64,8 @@ public static void clearTestoutputFolder() throws IOException {
6664
//@BeforeAll
6765
//TODO: might be needed for Windows
6866
public static void installZarritaInCondaEnv() throws IOException {
69-
// Process process = Runtime.getRuntime().exec("conda run -n " + CONDA_ENVIRONMENT + " pip install zarrita");
70-
Process process = Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "conda run -n " + CONDA_ENVIRONMENT + " pip install zarrita"});
67+
Process process = Runtime.getRuntime().exec("conda run -n " + CONDA_ENVIRONMENT + " pip install zarrita");
68+
//Process process = Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "conda run -n " + CONDA_ENVIRONMENT + " pip install zarrita"});
7169

7270
BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
7371
String s;
@@ -128,7 +126,7 @@ public void testReadFromZarrita(String codec) throws IOException, ZarrException,
128126
int exitCode = process.waitFor();
129127
assert exitCode == 0;
130128

131-
Array array = Array.open(new FilesystemStore(TESTOUTPUT).resolve("zarrita_write", codec));
129+
Array array = Array.open(new FilesystemStore(TESTOUTPUT).resolve("read_from_zarrita", codec));
132130
ucar.ma2.Array result = array.read();
133131

134132
//for expected values see zarrita_write.py
@@ -143,21 +141,20 @@ public void testReadFromZarrita(String codec) throws IOException, ZarrException,
143141
Assertions.assertArrayEquals(expectedData, (int[]) result.get1DJavaArray(ucar.ma2.DataType.INT));
144142
}
145143

146-
//ParameterizedTest instead of Test is a workaround to trigger @BeforeAll
147-
//TODO: dont misuse ParameterizedTest
148144
@ParameterizedTest
149-
@ValueSource(strings = "dummy")
150-
public void testWriteToZarrita(String dummy) throws IOException, ZarrException, InterruptedException {
151-
StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("array");
145+
@ValueSource(strings = {"blosc", "gzip", "zstd", "bytes", "transpose", "sharding", "crc32c"})
146+
public void testWriteToZarrita(String codec) throws IOException, ZarrException, InterruptedException {
147+
StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("write_to_zarrita", codec);
152148

149+
//TODO: have correct codecs
153150
Array array = Array.create(
154151
storeHandle,
155152
Array.metadataBuilder()
156153
.withShape(16, 16)
157154
.withDataType(DataType.UINT32)
158-
.withChunkShape(4, 4)
155+
.withChunkShape(8, 8)
159156
.withFillValue(0)
160-
.withCodecs(c -> c.withSharding(new int[]{4, 4}, CodecBuilder::withBlosc))
157+
.withCodecs(c -> c.withSharding(new int[]{4, 4}, c1 -> c1.withBytes("LITTLE")))
161158
.build());
162159

163160
ucar.ma2.Array testData = ucar.ma2.Array.factory(ucar.ma2.DataType.UINT, new int[]{16, 16});
@@ -167,7 +164,7 @@ public void testWriteToZarrita(String dummy) throws IOException, ZarrException,
167164

168165
String command = "zarrita/bin/python";
169166

170-
ProcessBuilder pb = new ProcessBuilder(command, ZARRITA_READ_PATH.toString(), TESTOUTPUT.toString());
167+
ProcessBuilder pb = new ProcessBuilder(command, ZARRITA_READ_PATH.toString(), codec, TESTOUTPUT.toString());
171168
Process process = pb.start();
172169

173170
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));

src/test/java/dev/zarr/zarrjava/zarrita_write.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
if codec_string == "blosc":
99
codec = [zarrita.codecs.bytes_codec(), zarrita.codecs.blosc_codec(typesize=4)]
1010
elif codec_string == "gzip":
11-
codecs = [zarrita.codecs.gzip_codec()], zarrita.codecs.bytes_codec()
11+
codec = [zarrita.codecs.bytes_codec(), zarrita.codecs.gzip_codec()]
1212
elif codec_string == "zstd":
1313
codec = [zarrita.codecs.bytes_codec(), zarrita.codecs.zstd_codec()]
1414
elif codec_string == "bytes":
@@ -24,14 +24,14 @@
2424

2525
store = zarrita.LocalStore(sys.argv[2])
2626
testdata = np.arange(0, 16 * 16, dtype='int32').reshape((16, 16))
27+
print(f"{codec=}")
2728

2829
a = zarrita.Array.create(
29-
store / 'zarrita_write' / codec_string,
30+
store / 'read_from_zarrita' / codec_string,
3031
shape=(16, 16),
3132
dtype='int32',
3233
chunk_shape=(2, 8),
3334
codecs=codec,
3435
attributes={'answer': 42}
3536
)
3637
a[:, :] = testdata
37-
print(testdata)

0 commit comments

Comments
 (0)