Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Java classloader to find test resources #9760

Merged
merged 2 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions java/src/test/java/ai/rapids/cudf/TableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TableTest extends CudfTestBase {
private static final File TEST_PARQUET_FILE = new File("src/test/resources/acq.parquet");
private static final File TEST_ORC_FILE = new File("src/test/resources/TestOrcFile.orc");
private static final File TEST_ORC_TIMESTAMP_DATE_FILE = new File(
"src/test/resources/timestamp-date-test.orc");
private static final File TEST_DECIMAL_PARQUET_FILE = new File("src/test/resources/decimal.parquet");
private static final File TEST_PARQUET_FILE = TestUtils.getResourceAsFile("acq.parquet");
private static final File TEST_ORC_FILE = TestUtils.getResourceAsFile("TestOrcFile.orc");
private static final File TEST_ORC_TIMESTAMP_DATE_FILE = TestUtils.getResourceAsFile("timestamp-date-test.orc");
private static final File TEST_DECIMAL_PARQUET_FILE = TestUtils.getResourceAsFile("decimal.parquet");
private static final File TEST_SIMPLE_CSV_FILE = TestUtils.getResourceAsFile("simple.csv");

private static final Schema CSV_DATA_BUFFER_SCHEMA = Schema.builder()
.column(DType.INT32, "A")
Expand Down Expand Up @@ -548,7 +548,7 @@ void testReadCSVPrune() {
.column(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
.column(110.0, 111.0, 112.0, 113.0, 114.0, 115.0, 116.0, 117.0, 118.2, 119.8)
.build();
Table table = Table.readCSV(schema, opts, new File("./src/test/resources/simple.csv"))) {
Table table = Table.readCSV(schema, opts, TEST_SIMPLE_CSV_FILE)) {
assertTablesAreEqual(expected, table);
}
}
Expand Down Expand Up @@ -675,7 +675,7 @@ void testReadCSV() {
.column(120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L, 128L, 129L)
.column("one", "two", "three", "four", "five", "six", "seven\ud801\uddb8", "eight\uBF68", "nine\u03E8", "ten")
.build();
Table table = Table.readCSV(schema, new File("./src/test/resources/simple.csv"))) {
Table table = Table.readCSV(schema, TEST_SIMPLE_CSV_FILE)) {
assertTablesAreEqual(expected, table);
}
}
Expand Down
17 changes: 16 additions & 1 deletion java/src/test/java/ai/rapids/cudf/TestUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,6 +18,9 @@

package ai.rapids.cudf;

import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
Expand Down Expand Up @@ -211,4 +214,16 @@ static Double[] getDoubles(final long seed, final int size, int specialValues) {
});
return result;
}

public static File getResourceAsFile(String resourceName) {
URL url = TableTest.class.getClassLoader().getResource(resourceName);
jlowe marked this conversation as resolved.
Show resolved Hide resolved
if (url == null) {
throw new IllegalArgumentException("Unable to locate resource: " + resourceName);
jlowe marked this conversation as resolved.
Show resolved Hide resolved
}
try {
return new File(url.toURI());
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
}