This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fury.git
The following commit(s) were added to refs/heads/main by this push:
new 0d47fb84 chore(java): skip xlang tests when pyfory is not available
(#2266)
0d47fb84 is described below
commit 0d47fb847da558a444f8a35ab1073e80c9f3ad7b
Author: Steven Schlansker <[email protected]>
AuthorDate: Sat May 31 20:12:10 2025 -0700
chore(java): skip xlang tests when pyfory is not available (#2266)
## What does this PR do?
right now a Java dev has to contend with failing tests that require
Python
by skipping the xlang tests when pyfory is not available, a Java
developer can build without needing to set up pyfory
---
ci/run_ci.sh | 1 +
.../test/java/org/apache/fory/CrossLanguageTest.java | 6 ++++++
.../org/apache/fory/format/CrossLanguageTest.java | 6 ++++++
.../src/main/java/org/apache/fory/test/TestUtils.java | 19 +++++++++++++++++++
4 files changed, 32 insertions(+)
diff --git a/ci/run_ci.sh b/ci/run_ci.sh
index 5f5a8b0b..5cc487e8 100755
--- a/ci/run_ci.sh
+++ b/ci/run_ci.sh
@@ -24,6 +24,7 @@ ROOT="$(git rev-parse --show-toplevel)"
echo "Root path: $ROOT, home path: $HOME"
cd "$ROOT"
+export FORY_CI=true
install_python() {
wget -q
https://repo.anaconda.com/miniconda/Miniconda3-py38_23.5.2-0-Linux-x86_64.sh -O
Miniconda3.sh
diff --git
a/java/fory-core/src/test/java/org/apache/fory/CrossLanguageTest.java
b/java/fory-core/src/test/java/org/apache/fory/CrossLanguageTest.java
index 4c0226f9..1d887425 100644
--- a/java/fory-core/src/test/java/org/apache/fory/CrossLanguageTest.java
+++ b/java/fory-core/src/test/java/org/apache/fory/CrossLanguageTest.java
@@ -71,6 +71,7 @@ import org.apache.fory.type.Descriptor;
import org.apache.fory.util.DateTimeUtils;
import org.apache.fory.util.MurmurHash3;
import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/** Tests in this class need fory python installed. */
@@ -80,6 +81,11 @@ public class CrossLanguageTest extends ForyTestBase {
private static final String PYTHON_MODULE =
"pyfory.tests.test_cross_language";
private static final String PYTHON_EXECUTABLE = "python";
+ @BeforeClass
+ public void isPyforyInstalled() {
+ TestUtils.verifyPyforyInstalled();
+ }
+
/**
* Execute an external command.
*
diff --git
a/java/fory-format/src/test/java/org/apache/fory/format/CrossLanguageTest.java
b/java/fory-format/src/test/java/org/apache/fory/format/CrossLanguageTest.java
index c6b6ffb2..8fe07212 100644
---
a/java/fory-format/src/test/java/org/apache/fory/format/CrossLanguageTest.java
+++
b/java/fory-format/src/test/java/org/apache/fory/format/CrossLanguageTest.java
@@ -69,6 +69,7 @@ import org.apache.fory.memory.MemoryUtils;
import org.apache.fory.serializer.BufferObject;
import org.apache.fory.test.TestUtils;
import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/** Tests in this class need fory python installed. */
@@ -78,6 +79,11 @@ public class CrossLanguageTest {
private static final String PYTHON_MODULE =
"pyfory.tests.test_cross_language";
private static final String PYTHON_EXECUTABLE = "python";
+ @BeforeClass
+ public void isPythonInstalled() {
+ TestUtils.verifyPyforyInstalled();
+ }
+
@Data
public static class A {
public Integer f1;
diff --git
a/java/fory-test-core/src/main/java/org/apache/fory/test/TestUtils.java
b/java/fory-test-core/src/main/java/org/apache/fory/test/TestUtils.java
index bc846ad8..a5418238 100644
--- a/java/fory-test-core/src/main/java/org/apache/fory/test/TestUtils.java
+++ b/java/fory-test-core/src/main/java/org/apache/fory/test/TestUtils.java
@@ -21,10 +21,13 @@ package org.apache.fory.test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.TimeUnit;
+import org.testng.SkipException;
public class TestUtils {
public static String random(int size, int rand) {
@@ -74,4 +77,20 @@ public class TestUtils {
throw new RuntimeException("Error executing command " + String.join(" ",
command), e);
}
}
+
+ public static void verifyPyforyInstalled() {
+ // Don't skip in CI, fail if something goes wrong instead
+ if (System.getenv("FORY_CI") != null) {
+ return;
+ }
+ if (executeCommand(
+ Arrays.asList(
+ "python",
+ "-c",
+ "import importlib, sys; sys.exit(0 if
importlib.util.find_spec(\"pyfory\") is None else 1)"),
+ 10,
+ Collections.emptyMap())) {
+ throw new SkipException("pyfory not installed");
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]