@@ -14,14 +14,19 @@ class JythonBindingsTest extends JOSMFixtureBasedTest {
1414 public static String __file__holder = null
1515 public static boolean scriptPathInSysPath = false
1616 public static int sum = 0
17+ public static boolean jythonPathInSysPath = true
1718
18- @Test
19- void ensure__file__IsSet () {
20- final jythonDesc = ScriptEngineMetaDataProvider
19+ static def getJythonDescriptor () {
20+ return ScriptEngineMetaDataProvider
2121 .getAvailablePluggedScriptEngines()
2222 .filter(desc -> desc. isJython())
2323 .findAny()
2424 .orElseThrow(() -> new IllegalStateException (" No Jython scripting engine found" ))
25+ }
26+
27+ @Test
28+ void ensure__file__IsSet () {
29+ final jythonDesc = jythonDescriptor
2530
2631 final executor = new ScriptExecutor (MainApplication . getMainFrame())
2732
@@ -38,11 +43,7 @@ JythonBindingsTest.__file__holder = __file__
3843
3944 @Test
4045 void ensureSysPathIsSet () {
41- final jythonDesc = ScriptEngineMetaDataProvider
42- .getAvailablePluggedScriptEngines()
43- .filter(desc -> desc. isJython())
44- .findAny()
45- .orElseThrow(() -> new IllegalStateException (" No Jython scripting engine found" ))
46+ final jythonDesc = jythonDescriptor
4647
4748 final executor = new ScriptExecutor (MainApplication . getMainFrame())
4849
@@ -62,11 +63,7 @@ for path in sys.path:
6263
6364 @Test
6465 void ensureImportFromSysPathWorks () {
65- final jythonDesc = ScriptEngineMetaDataProvider
66- .getAvailablePluggedScriptEngines()
67- .filter(desc -> desc. isJython())
68- .findAny()
69- .orElseThrow(() -> new IllegalStateException (" No Jython scripting engine found" ))
66+ final jythonDesc = jythonDescriptor
7067
7168 final executor = new ScriptExecutor (MainApplication . getMainFrame())
7269
@@ -91,4 +88,30 @@ JythonBindingsTest.sum = add(5,3)
9188 moduleFile. delete()
9289
9390 }
91+
92+ @Test
93+ void ensureJYTHONPATHinSysPath () {
94+ final jythonDesc = jythonDescriptor
95+
96+ final executor = new ScriptExecutor (MainApplication . getMainFrame())
97+
98+ // generate temporary script file
99+ final scriptFile = File . createTempFile(" test-script" , " " )
100+ scriptFile. write("""
101+ import sys
102+ from java.lang import System
103+ from java.io import File
104+ from org.openstreetmap.josm.plugins.scripting.jsr223 import JythonBindingsTest
105+ jythonpath = System.getenv('JYTHONPATH')
106+ if jythonpath:
107+ paths = jythonpath.split(File.pathSeparator)
108+ result = True
109+ for path in paths:
110+ result = result and path in sys.path
111+ JythonBindingsTest.jythonPathInSysPath = result
112+ """ )
113+ executor. runScriptWithPluggedEngine(jythonDesc, scriptFile)
114+ assertTrue (jythonPathInSysPath)
115+ scriptFile. delete()
116+ }
94117}
0 commit comments