Skip to content

Commit

Permalink
WIP: OmexTextCase (ndjson, csv) unifies unit/nightly test reports
Browse files Browse the repository at this point in the history
  • Loading branch information
jcschaff committed Dec 14, 2024
1 parent edfe91d commit 89dcc86
Show file tree
Hide file tree
Showing 3 changed files with 1,334 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package org.vcell.cli.testsupport;

public class OmexTestCase {

public enum TestDataRepo {
vcell, sysbio
}
public enum TestCollection {
VCELL_BIOMD(TestDataRepo.vcell, "vcell-cli/src/test/resources/bsts-omex/misc-projects"),
VCELL_BSTS_VCML(TestDataRepo.vcell, "vcell-cli/src/test/resources/bsts-omex/vcml"),
VCELL_BSTS_SBML_CORE(TestDataRepo.vcell, "vcell-cli/src/test/resources/bsts-omex/sbml-core"),
VCELL_BSTS_SYNTHS(TestDataRepo.vcell, "vcell-cli/src/test/resources/bsts-omex/synths"),
SYSBIO_BIOMD(TestDataRepo.sysbio, "omex_files");

public final TestDataRepo repo;
public final String pathPrefix;

TestCollection(TestDataRepo repo, String pathPrefix) {
this.repo = repo;
this.pathPrefix = pathPrefix;
}
}
public enum Status {
PASS,
FAIL,
SKIP
}

public TestCollection test_collection;
public String file_path;
public Boolean should_fail;
public Status known_status;
public FailureType known_failure_type;
public String known_failure_desc;

// from csv
public OmexTestCase(String[] csvLine) {
test_collection = TestCollection.valueOf(csvLine[0]);
file_path = csvLine[1];
should_fail = Boolean.parseBoolean(csvLine[2]);
if (csvLine[3].trim().isEmpty()) {
known_status = null;
} else {
known_status = Status.valueOf(csvLine[3]);
}
if (csvLine[4].trim().isEmpty()) {
known_failure_type = null;
} else {
known_failure_type = FailureType.valueOf(csvLine[4]);
}
known_failure_desc = parseCsvStringField(csvLine[5]);
}

// to csv
public String[] toCsvLine() {
return new String[] {
test_collection.toString(),
file_path,
should_fail.toString(),
(known_status !=null) ? known_status.toString() : "",
(known_failure_type !=null) ? known_failure_type.toString() : "",
printCsvStringField(known_failure_desc)
};
}

@Override
public String toString() {
return "OmexTestCase{" +
"test_collection=" + test_collection +
", file_path='" + file_path + '\'' +
", should_fail=" + should_fail +
", known_status=" + known_status +
", known_failure_type=" + known_failure_type +
", known_failure_desc="+((known_failure_desc!=null)?('\'' + known_failure_desc + '\''):null) +
'}';
}
private String parseCsvStringField(String str) {
str = str.strip();
// strip leading and trailing double quotes
if (str.startsWith("\"") && str.endsWith("\"")) {
str = str.substring(1, str.length()-1);
}
// strip escaped double quotes
str = str.replace("\"\"", "\"");
if (str.isEmpty()){
return null;
}
return str;
}

private String printCsvStringField(String str) {
if (str == null){
return "";
}
return "\"" + str.replace("\"", "\"\"") + "\"";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.vcell.cli.testsupport;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class OmexTestingDatabase {

// read a newline-delimited json file into a list of OmexTextCase objects
public static List<OmexTestCase> readOmexTestCasesFromNdjson(String path) throws IOException {
List<OmexTestCase> testCases = new ArrayList<>();
ObjectMapper objectMapper = new ObjectMapper();
try (BufferedReader reader = new BufferedReader(new FileReader(path));) {
String line = reader.readLine();
while (line != null) {
// use jackson objectmapper to read an OmexTestCase object from a json string
OmexTestCase testCase = objectMapper.readValue(line, OmexTestCase.class);
testCases.add(testCase);
}
}
return testCases;
}

// read a csv file into a list of OmexTextCase objects
public static List<OmexTestCase> readOmexTestCasesFromCsv(String path) throws IOException{
List<OmexTestCase> testCases = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(path));) {
String line = reader.readLine(); // read header
line = reader.readLine(); // read first line
while (line != null) {
line = line + " "; // add a space to the end of the line to handle empty fields at the end
line = line.replace(",,",", ,"); // replace empty fields with ", ,"
String[] fields = line.split(",");
testCases.add(new OmexTestCase(fields));
line = reader.readLine();
}
}
return testCases;
}

public static void main(String[] args) {
try {
List<OmexTestCase> testCases = readOmexTestCasesFromCsv("/Users/jimschaff/Documents/workspace/vcell/vcell-cli/src/main/resources/known_problems.csv");
ObjectMapper objectMapper = new ObjectMapper();
for (OmexTestCase testCase : testCases) {
System.out.println(Arrays.stream(testCase.toCsvLine()).collect(Collectors.joining(",")));
System.out.println(testCase);
System.out.println(objectMapper.writeValueAsString(testCase));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Loading

0 comments on commit 89dcc86

Please sign in to comment.