8000 Avoid using GraalPy internal classes in tests where possible · oracle/graalpython@083270f · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 083270f

Browse files
committed
Avoid using GraalPy internal classes in tests where possible
1 parent a231727 commit 083270f

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/PythonTests.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@
4949
import org.graalvm.polyglot.Value;
5050
import org.junit.Assert;
5151

52-
import com.oracle.graal.python.runtime.exception.PException;
53-
import com.oracle.truffle.api.Truffle;
54-
import com.oracle.truffle.api.frame.FrameDescriptor;
55-
import com.oracle.truffle.api.frame.VirtualFrame;
56-
import com.oracle.truffle.api.interop.InteropLibrary;
57-
import com.oracle.truffle.api.interop.UnsupportedMessageException;
5852
import com.oracle.truffle.api.strings.TruffleString;
5953

6054
public class PythonTests {
@@ -192,10 +186,6 @@ public static Value eval(String code) {
192186
return PythonTests.runScript(new String[0], code, printStream, System.err);
193187
}
194188

195-
public static VirtualFrame createVirtualFrame() {
196-
return Truffle.getRuntime().createVirtualFrame(null, new FrameDescriptor());
197-
}
198-
199189
static void flush(OutputStream out, OutputStream err) {
200190
PythonTests.outStream.flush();
201191
PythonTests.errStream.flush();
@@ -314,24 +304,6 @@ public static void runThrowableScript(String[] args, String source, OutputStream
314304
}
315305
}
316306

317-
/**
318-
* This method returns the properly formatted error message of the given Python exception. It
319-
* does not use {@code PException.toString} since this method is just meant for debugging an
320-
* does not reliably return a properly formatted string. Instead, this method uses the
321-
* {@link InteropLibrary} which provides interop messages to get the error message.
322-
*/
323-
public static String getExceptionMessage(PException e) {
324-
InteropLibrary interop = InteropLibrary.getUncached();
325-
Assert.assertTrue("PException claims to be not an exception", interop.isException(e));
326-
try {
327-
Object exceptionMessageObject = interop.getExceptionMessage(e);
328-
Assert.assertTrue("returned message object is not a string", interop.isString(exceptionMessageObject));
329-
return interop.asString(exceptionMessageObject);
330-
} catch (UnsupportedMessageException ume) {
331-
throw new IllegalStateException("should not be reached");
332-
}
333-
}
334-
335307
public static TruffleString ts(String s) {
336308
return TruffleString.fromJavaStringUncached(s, TruffleString.Encoding.UTF_8);
337309
}

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/advance/AsyncActionThreadingTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949

5050
import org.graalvm.polyglot.Context;
5151
import org.graalvm.polyglot.PolyglotException;
52+
import org.junit.Assume;
5253
import org.junit.Test;
5354

54-
import com.oracle.graal.python.runtime.PythonOptions;
5555
import com.oracle.graal.python.test.PythonTests;
5656

5757
public class AsyncActionThreadingTest extends PythonTests {
@@ -75,9 +75,7 @@ Stream<Thread> pythonThreads() {
7575

7676
@Test
7777
public void testNoNewThreadsWithoutAutomaticAsyncActions() {
78-
if (PythonOptions.AUTOMATIC_ASYNC_ACTIONS) {
79-
return;
80-
}
78+
Assume.assumeTrue("false".equalsIgnoreCase(System.getProperty("python.AutomaticAsyncActions")));
8179
long threadCount = pythonThreadCount();
8280
Context c = PythonTests.enterContext();
8381
try {

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/engine/SharedEngineMultithreadingTestBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@
5050
import java.util.concurrent.Future;
5151
import java.util.concurrent.ThreadFactory;
5252
import java.util.concurrent.TimeUnit;
53+
import java.util.function.Consumer;
5354

5455
import org.graalvm.polyglot.Context;
5556
import org.graalvm.polyglot.Engine;
5657
import org.junit.Rule;
5758

5859
import com.oracle.graal.python.test.CleanupRule;
5960
import com.oracle.graal.python.test.PythonTests;
60-
import com.oracle.graal.python.util.Consumer;
6161

6262
/**
6363
* Base class for tests that run in multiple context with a shared engine and in parallel.

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/interop/JavaInteropTest.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@
7373
import org.junit.runners.Parameterized.Parameter;
7474
import org.junit.runners.Parameterized.Parameters;
7575

76-
import com.oracle.graal.python.runtime.interop.InteropArray;
7776
import com.oracle.graal.python.test.PythonTests;
77+
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
7878
import com.oracle.truffle.api.interop.ArityException;
7979
import com.oracle.truffle.api.interop.InteropLibrary;
8080
import com.oracle.truffle.api.interop.TruffleObject;
@@ -856,4 +856,34 @@ public void testSysFlagsReflectContext() {
856856
}).distinct().count());
857857
}
858858
}
859+
860+
@ExportLibrary(InteropLibrary.class)
861+
public static final class InteropArray implements TruffleObject {
862+
@CompilationFinal(dimensions = 1) private final Object[] array;
863+
864+
public InteropArray(Object[] array) {
865+
this.array = array;
866+
}
867+
868+
@ExportMessage(name = "readArrayElement")
869+
Object get(long idx) {
870+
return array[(int) idx];
871+
}
872+
873+
@ExportMessage(name = "getArraySize")
874+
int size() {
875+
return array.length;
876+
}
877+
878+
@SuppressWarnings("static-method")
879+
@ExportMessage
880+
boolean hasArrayElements() {
881+
return true;
882+
}
883+
884+
@ExportMessage
885+
boolean isArrayElementReadable(long idx) {
886+
return idx < array.length;
887+
}
888+
}
859889
}

0 commit comments

Comments
 (0)
0