|
82 | 82 | import org.graalvm.polyglot.Context.Builder;
|
83 | 83 | import org.graalvm.polyglot.HostAccess;
|
84 | 84 | import org.graalvm.polyglot.PolyglotException;
|
| 85 | +import org.graalvm.polyglot.Value; |
85 | 86 | import org.graalvm.polyglot.io.FileSystem;
|
86 | 87 | import org.graalvm.polyglot.io.IOAccess;
|
87 | 88 | import org.graalvm.python.embedding.utils.GraalPyResources;
|
@@ -886,6 +887,62 @@ public void vfsMountPointTest() {
|
886 | 887 | }
|
887 | 888 | }
|
888 | 889 |
|
| 890 | + @SuppressWarnings("unchecked") |
| 891 | + @Test |
| 892 | + public void pythonPathsTest() throws IOException { |
| 893 | + Context ctx = GraalPyResources.createContext(); |
| 894 | + String getPathsSource = "import sys; [__graalpython__.get_python_home_paths(), sys.path, sys.executable]"; |
| 895 | + |
| 896 | + Value paths = ctx.eval("python", getPathsSource); |
| 897 | + String defaultMountPoint = VirtualFileSystem.newBuilder().build().getMountPoint(); |
| 898 | + assertEquals(IS_WINDOWS ? "X:\\graalpy_vfs" : "/graalpy_vfs", defaultMountPoint); |
| 899 | + checkPaths(paths.as(List.class), defaultMountPoint); |
| 900 | + |
| 901 | + ctx = GraalPyResources.contextBuilder().build(); |
| 902 | + paths = ctx.eval("python", getPathsSource); |
| 903 | + checkPaths(paths.as(List.class), defaultMountPoint); |
| 904 | + |
| 905 | + VirtualFileSystem vfs = VirtualFileSystem.newBuilder().// |
| 906 | + unixMountPoint(VFS_UNIX_MOUNT_POINT).// |
| 907 | + windowsMountPoint(VFS_WIN_MOUNT_POINT).build(); |
| 908 | + assertEquals(VFS_MOUNT_POINT, vfs.getMountPoint()); |
| 909 | + ctx = GraalPyResources.contextBuilder(vfs).build(); |
| 910 | + paths = ctx.eval("python", getPathsSource); |
| 911 | + checkPaths(paths.as(List.class), vfs.getMountPoint(), true); |
| 912 | + |
| 913 | + Path resourcesDir = Files.createTempDirectory("python-resources"); |
| 914 | + ctx = GraalPyResources.contextBuilder(resourcesDir).build(); |
| 915 | + paths = ctx.eval("python", getPathsSource); |
| 916 | + checkPaths(paths.as(List.class), resourcesDir.toString()); |
| 917 | + } |
| 918 | + |
| 919 | + private static void checkPaths(List<Object> l, String pathPrefix) { |
| 920 | + checkPaths(l, pathPrefix, false); |
| 921 | + } |
| 922 | + |
| 923 | + @SuppressWarnings("unchecked") |
| 924 | + private static void checkPaths(List<Object> l, String pathPrefix, boolean checkHome) { |
| 925 | + // python.PythonHome |
| 926 | + // TODO how to check python.PythonHome? |
| 927 | + // /org.graalvm.python.vfs/home has to be in fileslist.txt |
| 928 | + // - if it is in fileslist.txt, than it also has to contain the whole stdlib, |
| 929 | + // or other tests will fail when trying to load python |
| 930 | + // - the pythonHome value is implicitly covered in maven and gradle plugin tests |
| 931 | + // if (checkHome) { |
| 932 | + // assertTrue(((String) l.get(0)).contains(pathPrefix + File.separator + "home" + |
| 933 | + // File.separator + |
| 934 | + // "lib-graalpython")); |
| 935 | + // assertTrue(((String) l.get(0)).contains(pathPrefix + File.separator + "home" + |
| 936 | + // File.separator + |
| 937 | + // "lib-python" + File.separator + "3")); |
| 938 | + // } |
| 939 | + |
| 940 | + // option python.PythonPath |
| 941 | + assertTrue(((List<Object>) l.get(1)).contains(pathPrefix + File.separator + "src")); |
| 942 | + // option python.Executable |
| 943 | + assertEquals(l.get(2), pathPrefix + (IS_WINDOWS ? "\\venv\\Scripts\\python.exe" : "/venv/bin/python")); |
| 944 | + } |
| 945 | + |
889 | 946 | private static Builder addTestOptions(Builder builder) {
|
890 | 947 | return builder.option("engine.WarnInterpreterOnly", "false");
|
891 | 948 | }
|
|
0 commit comments