Skip to content

Commit 4ac6ccd

Browse files
committed
cleanup test case
1 parent 00ec3de commit 4ac6ccd

File tree

1 file changed

+29
-36
lines changed

1 file changed

+29
-36
lines changed

mx.graalpython/mx_graalpython.py

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -435,47 +435,40 @@ def run_embedded_native_python_test(args=None):
435435
those contexts having access to the core files, due to caching in the shared
436436
engine.
437437
"""
438-
filename = dirname = None
439438
with mx.TempDirCwd(os.getcwd()) as dirname:
440-
try:
441-
python_launcher = python_gvm()
442-
graalvm_javac = os.path.join(os.path.dirname(python_launcher), "javac")
443-
graalvm_native_image = os.path.join(os.path.dirname(python_launcher), "native-image")
444-
445-
filename = os.path.join(dirname, "HelloWorld.java")
446-
with open(filename, "w") as f:
447-
f.write("""
448-
import org.graalvm.polyglot.*;
449-
450-
public class HelloWorld {
451-
static final Engine engine = Engine.newBuilder().allowExperimentalOptions(true).option("log.python.level", "FINEST").build();
452-
static {
453-
try (Context contextNull = Context.newBuilder("python").engine(engine).build()) {
454-
contextNull.initialize("python");
455-
}
456-
}
439+
python_launcher = python_gvm()
440+
graalvm_javac = os.path.join(os.path.dirname(python_launcher), "javac")
441+
graalvm_native_image = os.path.join(os.path.dirname(python_launcher), "native-image")
442+
443+
filename = os.path.join(dirname, "HelloWorld.java")
444+
with open(filename, "w") as f:
445+
f.write("""
446+
import org.graalvm.polyglot.*;
447+
448+
public class HelloWorld {
449+
static final Engine engine = Engine.newBuilder().allowExperimentalOptions(true).option("log.python.level", "FINEST").build();
450+
static {
451+
try (Context contextNull = Context.newBuilder("python").engine(engine).build()) {
452+
contextNull.initialize("python");
453+
}
454+
}
457455
458-
public static void main(String[] args) {
459-
try (Context context1 = Context.newBuilder("python").engine(engine).build()) {
460-
context1.eval("python", "print(42)");
461-
try (Context context2 = Context.newBuilder("python").engine(engine).build()) {
462-
context2.eval("python", "print(42 + 1)");
463-
}
456+
public static void main(String[] args) {
457+
try (Context context1 = Context.newBuilder("python").engine(engine).build()) {
458+
context1.eval("python", "print(b'abc'.decode('ascii'))");
459+
try (Context context2 = Context.newBuilder("python").engine(engine).build()) {
460+
context2.eval("python", "print(b'xyz'.decode('ascii'))");
464461
}
465462
}
466463
}
467-
""")
468-
out = mx.OutputCapture()
469-
mx.run([graalvm_javac, filename])
470-
mx.run([graalvm_native_image, "--initialize-at-build-time", "--language:python", "HelloWorld"])
471-
mx.run(["./helloworld"], out=mx.TeeOutputCapture(out))
472-
assert "42" in out.data
473-
assert "43" in out.data
474-
finally:
475-
try:
476-
os.unlink(filename)
477-
except:
478-
pass
464+
}
465+
""")
466+
out = mx.OutputCapture()
467+
mx.run([graalvm_javac, filename])
468+
mx.run([graalvm_native_image, "--initialize-at-build-time", "--language:python", "HelloWorld"])
469+
mx.run(["./helloworld"], out=mx.TeeOutputCapture(out))
470+
assert "abc" in out.data
471+
assert "xyz" in out.data
479472

480473

481474
def run_shared_lib_test(args=None):

0 commit comments

Comments
 (0)