73
73
import java .util .concurrent .Callable ;
74
74
import java .util .function .BiFunction ;
75
75
import java .util .function .Function ;
76
+ import java .util .logging .Handler ;
77
+ import java .util .logging .Level ;
78
+ import java .util .logging .Logger ;
76
79
77
80
import org .graalvm .polyglot .Context ;
81
+ import org .graalvm .polyglot .Context .Builder ;
78
82
import org .graalvm .polyglot .HostAccess ;
79
83
import org .graalvm .polyglot .PolyglotException ;
80
84
import org .graalvm .polyglot .io .FileSystem ;
@@ -110,6 +114,14 @@ public class VirtualFileSystemTest {
110
114
extractFilter (p -> p .getFileName ().toString ().equals ("extractme" )).//
111
115
resourceLoadingClass (VirtualFileSystemTest .class ).build ();
112
116
117
+ public VirtualFileSystemTest () {
118
+ Logger logger = Logger .getLogger (VirtualFileSystem .class .getName ());
119
+ for (Handler handler : logger .getHandlers ()) {
120
+ handler .setLevel (Level .FINE );
121
+ }
122
+ logger .setLevel (Level .FINE );
123
+ }
124
+
113
125
@ Test
114
126
public void defaultValues () throws Exception {
115
127
VirtualFileSystem fs = VirtualFileSystem .create ();
@@ -322,7 +334,7 @@ public void delete() throws Exception {
322
334
assertFalse (Files .exists (realFSPath ));
323
335
}
324
336
325
- private void checkDelete (FileSystem fs , String path ) {
337
+ private static void checkDelete (FileSystem fs , String path ) {
326
338
checkException (SecurityException .class , () -> {
327
339
fs .delete (Path .of (path ));
328
340
return null ;
@@ -373,7 +385,7 @@ public void newByteChannel() throws IOException {
373
385
}
374
386
}
375
387
376
- private void checkCanOnlyRead (FileSystem fs , Path path , StandardOpenOption ... options ) {
388
+ private static void checkCanOnlyRead (FileSystem fs , Path path , StandardOpenOption ... options ) {
377
389
checkException (SecurityException .class , () -> fs .newByteChannel (path , Set .of (options )), "should only be able to read from VFS" );
378
390
}
379
391
@@ -766,7 +778,7 @@ public Context getContext(Function<VirtualFileSystem.Builder, VirtualFileSystem.
766
778
builder = builderFunction .apply (builder );
767
779
}
768
780
VirtualFileSystem fs = builder .build ();
769
- Context context = GraalPyResources .contextBuilder (fs ).build ();
781
+ Context context = addTestOptions ( GraalPyResources .contextBuilder (fs ) ).build ();
770
782
if (builderFunction == null ) {
771
783
cachedContext = context ;
772
784
}
@@ -775,10 +787,10 @@ public Context getContext(Function<VirtualFileSystem.Builder, VirtualFileSystem.
775
787
776
788
@ Test
777
789
public void vfsBuilderTest () {
778
- Context context = GraalPyResources .contextBuilder ().allowAllAccess (true ).allowHostAccess (HostAccess .ALL ).build ();
790
+ Context context = addTestOptions ( GraalPyResources .contextBuilder () ).allowAllAccess (true ).allowHostAccess (HostAccess .ALL ).build ();
779
791
context .eval (PYTHON , "import java; java.type('java.lang.String')" );
780
792
781
- context = GraalPyResources .contextBuilder ().allowAllAccess (false ).allowHostAccess (HostAccess .NONE ).build ();
793
+ context = addTestOptions ( GraalPyResources .contextBuilder () ).allowAllAccess (false ).allowHostAccess (HostAccess .NONE ).build ();
782
794
context .eval (PYTHON , """
783
795
import java
784
796
try:
@@ -793,13 +805,13 @@ public void vfsBuilderTest() {
793
805
unixMountPoint (VFS_MOUNT_POINT ).//
794
806
windowsMountPoint (VFS_WIN_MOUNT_POINT ).//
795
807
resourceLoadingClass (VirtualFileSystemTest .class ).build ();
796
- context = GraalPyResources .contextBuilder (fs ).build ();
808
+ context = addTestOptions ( GraalPyResources .contextBuilder (fs ) ).build ();
797
809
context .eval (PYTHON , patchMountPoint ("from os import listdir; listdir('/test_mount_point')" ));
798
810
799
811
context = GraalPyResources .createContext ();
800
812
context .eval (PYTHON , "from os import listdir; listdir('.')" );
801
813
802
- context = GraalPyResources .contextBuilder ().allowIO (IOAccess .NONE ).build ();
814
+ context = addTestOptions ( GraalPyResources .contextBuilder () ).allowIO (IOAccess .NONE ).build ();
803
815
boolean gotPE = false ;
804
816
try {
805
817
context .eval (PYTHON , "from os import listdir; listdir('.')" );
@@ -835,9 +847,13 @@ public void externalResourcesBuilderTest() throws IOException {
835
847
checkExtractedFile (resourcesDir .resolve (Path .of ("file1" )), new String []{"text1" , "text2" });
836
848
837
849
// create context with extracted resource dir and check if we can see the extracted file
838
- try (Context context = GraalPyResources .contextBuilder (resourcesDir ).build ()) {
850
+ try (Context context = addTestOptions ( GraalPyResources .contextBuilder (resourcesDir ) ).build ()) {
839
851
context .eval ("python" , "import os; assert os.path.exists('" + resourcesDir .resolve ("file1" ).toString ().replace ("\\ " , "\\ \\ " ) + "')" );
840
852
}
841
853
}
842
854
855
+ private static Builder addTestOptions (Builder builder ) {
856
+ return builder .option ("engine.WarnInterpreterOnly" , "false" );
857
+ }
858
+
843
859
}
0 commit comments