Skip to content

Commit dd3e939

Browse files
committed
adapt test-setup for linux
1 parent 351b7f8 commit dd3e939

File tree

1 file changed

+47
-27
lines changed

1 file changed

+47
-27
lines changed

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

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ public class ZarrTest {
4646

4747
final static Path TESTDATA = Paths.get("testdata");
4848
final static Path TESTOUTPUT = Paths.get("testoutput");
49-
final static Path ZARRITA_WRITE_PATH = Paths.get("src\\test\\java\\dev\\zarr\\zarrjava\\zarrita_write.py");
50-
final static Path ZARRITA_READ_PATH = Paths.get("src\\test\\java\\dev\\zarr\\zarrjava\\zarrita_read.py");
49+
50+
//TODO: is the Path with / instead of \ readable in Windows?
51+
final static Path ZARRITA_WRITE_PATH = Paths.get("src/test/java/dev/zarr/zarrjava/zarrita_write.py");
52+
final static Path ZARRITA_READ_PATH = Paths.get("src/test/java/dev/zarr/zarrjava/zarrita_read.py");
53+
5154
final static String CONDA_ENVIRONMENT = "zarrita_env";
5255

5356
@BeforeAll
@@ -60,9 +63,11 @@ public static void clearTestoutputFolder() throws IOException {
6063
Files.createDirectory(TESTOUTPUT);
6164
}
6265

63-
@BeforeAll
66+
//@BeforeAll
67+
//TODO: might be needed for Windows
6468
public static void installZarritaInCondaEnv() throws IOException {
65-
Process process = Runtime.getRuntime().exec("conda run -n " + CONDA_ENVIRONMENT + " pip install zarrita");
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"});
6671

6772
BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
6873
String s;
@@ -103,17 +108,25 @@ public static void installZarritaInCondaEnv() throws IOException {
103108

104109
@ParameterizedTest
105110
@ValueSource(strings = {"blosc", "gzip", "zstd", "bytes", "transpose", "sharding", "crc32c"})
106-
public void testReadFromZarrita(String codec) throws IOException, ZarrException {
107-
String command = "conda run -n " + CONDA_ENVIRONMENT + " python " + ZARRITA_WRITE_PATH + " " + codec + " " + TESTOUTPUT;
108-
Process process = Runtime.getRuntime().exec(command);
109-
System.out.println("exec: " + command);
111+
public void testReadFromZarrita(String codec) throws IOException, ZarrException, InterruptedException {
112+
String command = "zarrita/bin/python";
110113

111-
BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
112-
String s;
113-
while ((s = stdError.readLine()) != null) {
114-
System.err.println(s);
114+
ProcessBuilder pb = new ProcessBuilder(command, ZARRITA_WRITE_PATH.toString(), codec, TESTOUTPUT.toString());
115+
Process process = pb.start();
116+
117+
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
118+
String line;
119+
while ((line = reader.readLine()) != null) {
120+
System.out.println(line);
115121
}
116-
assert process.exitValue() == 0;
122+
123+
BufferedReader readerErr = new BufferedReader(new InputStreamReader(process.getErrorStream()));
124+
while ((line = readerErr.readLine()) != null) {
125+
System.err.println(line);
126+
}
127+
128+
int exitCode = process.waitFor();
129+
assert exitCode == 0;
117130

118131
Array array = Array.open(new FilesystemStore(TESTOUTPUT).resolve("zarrita_write", codec));
119132
ucar.ma2.Array result = array.read();
@@ -130,8 +143,11 @@ public void testReadFromZarrita(String codec) throws IOException, ZarrException
130143
Assertions.assertArrayEquals(expectedData, (int[]) result.get1DJavaArray(ucar.ma2.DataType.INT));
131144
}
132145

133-
@Test
134-
public void testWriteToZarrita() throws IOException, ZarrException {
146+
//ParameterizedTest instead of Test is a workaround to trigger @BeforeAll
147+
//TODO: dont misuse ParameterizedTest
148+
@ParameterizedTest
149+
@ValueSource(strings = "dummy")
150+
public void testWriteToZarrita(String dummy) throws IOException, ZarrException, InterruptedException {
135151
StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("array");
136152

137153
Array array = Array.create(
@@ -149,22 +165,26 @@ public void testWriteToZarrita() throws IOException, ZarrException {
149165
array.write(testData);
150166

151167

152-
String command = "conda run -n " + CONDA_ENVIRONMENT + " python " + ZARRITA_READ_PATH;
153-
Process process = Runtime.getRuntime().exec(command);
154-
System.out.println("exec: " + command);
168+
String command = "zarrita/bin/python";
155169

156-
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
157-
BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
158-
String s;
159-
System.out.println("result: ");
160-
while ((s = stdInput.readLine()) != null) {
161-
System.out.println(s);
170+
ProcessBuilder pb = new ProcessBuilder(command, ZARRITA_READ_PATH.toString(), TESTOUTPUT.toString());
171+
Process process = pb.start();
172+
173+
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
174+
String line;
175+
while ((line = reader.readLine()) != null) {
176+
System.out.println(line);
162177
}
163-
while ((s = stdError.readLine()) != null) {
164-
System.err.println(s);
178+
179+
BufferedReader readerErr = new BufferedReader(new InputStreamReader(process.getErrorStream()));
180+
while ((line = readerErr.readLine()) != null) {
181+
System.err.println(line);
165182
}
183+
184+
int exitCode = process.waitFor();
185+
assert exitCode == 0;
166186
//TODO return metadata from zarrita_read.py and do assertions here
167-
assert process.exitValue() == 0;
187+
168188
}
169189

170190

0 commit comments

Comments
 (0)