4141import subprocess
4242import tempfile
4343import unittest
44+ import shutil
45+ import glob
4446
4547is_enabled = 'ENABLE_STANDALONE_UNITTESTS' in os .environ and os .environ ['ENABLE_STANDALONE_UNITTESTS' ] == "true"
48+ MVN = shutil .which ('mvn' )
4649
4750def get_executable (file ):
4851 if os .path .isfile (file ):
@@ -75,12 +78,25 @@ def get_gp():
7578 sep = "\n " ,
7679 )
7780 assert False
81+
82+ print ("Running tests for standalone module:" )
83+ print (" __graalpython__.home:" , __graalpython__ .home )
84+ print (" java_home:" , java_home )
85+ print (" graalpy:" , graalpy )
86+ print (" java:" , java )
87+
7888 return java_home , graalpy , java
7989
8090def get_env (java_home ):
8191 env = os .environ .copy ()
8292 env .update ({"JAVA_HOME" : java_home })
8393
94+ graalvm_home = os .environ .get ("GRAALVM_HOME" , java_home )
95+ if "*" in graalvm_home :
96+ graalvm_home = os .path .abspath (glob .glob (graalvm_home )[0 ])
97+ print ("Patching GRAALVM_HOME: " , graalvm_home )
98+ env .update ({"GRAALVM_HOME" : graalvm_home })
99+
84100 to_be_removed = []
85101 for k in env :
86102 # subprocess complaining about key names with "=" in them
@@ -93,7 +109,7 @@ def get_env(java_home):
93109
94110 return env
95111
96- @unittest .skipUnless (is_enabled )
112+ @unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
97113def test_polyglot_app ():
98114
99115 java_home , graalpy , java = get_gp ()
@@ -105,40 +121,40 @@ def test_polyglot_app():
105121
106122 cmd = [graalpy , "-m" , "standalone" , "--verbose" , "polyglot_app" , "-o" , target_dir ]
107123 p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
108- out = p .stdout .decode ()
109- print (p .stdout .decode ())
110- print (p .stderr .decode ())
124+ out = p .stdout .decode (errors = 'backslashreplace' )
125+ print (p .stdout .decode (errors = 'backslashreplace' ))
126+ print (p .stderr .decode (errors = 'backslashreplace' ))
111127 assert "Creating polyglot java python application in directory " + target_dir in out
112128
113- cmd = ["mvn" , "package" , "-Pnative" ]
129+ cmd = [MVN , "package" , "-Pnative" ]
114130 p = subprocess .run (cmd , cwd = target_dir , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
115- out = p .stdout .decode ()
131+ out = p .stdout .decode (errors = 'backslashreplace' )
116132 print (out )
117- print (p .stderr .decode ())
133+ print (p .stderr .decode (errors = 'backslashreplace' ))
118134 assert "BUILD SUCCESS" in out
119135
120136 cmd = [os .path .join (target_dir , "target" , "polyglot_app" )]
121137 p = subprocess .run (cmd , cwd = target_dir , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
122- out = p .stdout .decode ()
138+ out = p .stdout .decode (errors = 'backslashreplace' )
123139 print (out )
124- print (p .stderr .decode ())
140+ print (p .stderr .decode (errors = 'backslashreplace' ))
125141 assert out .endswith ("hello java\n " )
126142
127- cmd = ["mvn" , "package" , "-Pjar" ]
143+ cmd = [MVN , "package" , "-Pjar" ]
128144 p = subprocess .run (cmd , cwd = target_dir , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
129- out = p .stdout .decode ()
145+ out = p .stdout .decode (errors = 'backslashreplace' )
130146 print (out )
131- print (p .stderr .decode ())
147+ print (p .stderr .decode (errors = 'backslashreplace' ))
132148 assert "BUILD SUCCESS" in out
133149
134150 cmd = [java , "-jar" , os .path .join (target_dir , "target" , "polyglot_app-1.0-SNAPSHOT.jar" )]
135151 p = subprocess .run (cmd , cwd = target_dir , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
136- out = p .stdout .decode ()
152+ out = p .stdout .decode (errors = 'backslashreplace' )
137153 print (out )
138- print (p .stderr .decode ())
154+ print (p .stderr .decode (errors = 'backslashreplace' ))
139155 assert out .endswith ("hello java\n " )
140156
141- @unittest .skipUnless (is_enabled )
157+ @unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
142158def test_native_executable_one_file ():
143159 java_home , graalpy , java = get_gp ()
144160 if graalpy is None or java is None :
@@ -156,19 +172,19 @@ def test_native_executable_one_file():
156172 cmd = [graalpy , "-m" , "standalone" , "--verbose" , "native" , "-m" , source_file , "-o" , target_file ]
157173
158174 p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
159- out = p .stdout .decode ()
175+ out = p .stdout .decode (errors = 'backslashreplace' )
160176 print (out )
161- print (p .stderr .decode ())
177+ print (p .stderr .decode (errors = 'backslashreplace' ))
162178 assert "Bundling Python resources into" in out
163179
164180 cmd = [target_file ]
165181 p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
166- out = p .stdout .decode ()
182+ out = p .stdout .decode (errors = 'backslashreplace' )
167183 print (out )
168- print (p .stderr .decode ())
184+ print (p .stderr .decode (errors = 'backslashreplace' ))
169185 assert "hello world" in out
170186
171- @unittest .skipUnless (is_enabled )
187+ @unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
172188def test_native_executable_one_file_venv ():
173189 java_home , graalpy , java = get_gp ()
174190 if graalpy is None or java is None :
@@ -186,34 +202,34 @@ def test_native_executable_one_file_venv():
186202 venv_dir = os .path .join (target_dir , "venv" )
187203 cmd = [graalpy , "-m" , "venv" , venv_dir ]
188204 p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
189- out = p .stdout .decode ()
205+ out = p .stdout .decode (errors = 'backslashreplace' )
190206 print (out )
191- print (p .stderr .decode ())
207+ print (p .stderr .decode (errors = 'backslashreplace' ))
192208
193- pip = os .path .join (venv_dir , "bin" , "pip " )
194- cmd = [pip , "install" , "termcolor" ]
209+ venv_python = os .path .join (venv_dir , "Scripts" , "python.cmd" ) if os . name == "nt" else os . path . join ( venv_dir , " bin" , "python " )
210+ cmd = [venv_python , "-m" , " pip" , "--no-cache-dir" , "install" , "termcolor" ]
195211 p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
196- out = p .stdout .decode ()
212+ out = p .stdout .decode (errors = 'backslashreplace' )
197213 print (out )
198- print (p .stderr .decode ())
214+ print (p .stderr .decode (errors = 'backslashreplace' ))
199215
200216 target_file = os .path .join (target_dir , "hello" )
201217 cmd = [graalpy , "-m" , "standalone" , "--verbose" , "native" , "-Os" , "-m" , source_file , "--venv" , venv_dir , "-o" , target_file ]
202218 p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
203- out = p .stdout .decode ()
219+ out = p .stdout .decode (errors = 'backslashreplace' )
204220 print (out )
205- print (p .stderr .decode ())
221+ print (p .stderr .decode (errors = 'backslashreplace' ))
206222 assert "Bundling Python resources into" in out
207223
208224 cmd = [target_file ]
209225 p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
210- out = p .stdout .decode ()
226+ out = p .stdout .decode (errors = 'backslashreplace' )
211227 print (out )
212- print (p .stderr .decode ())
228+ print (p .stderr .decode (errors = 'backslashreplace' ))
213229
214230 assert "hello standalone world" in out
215231
216- @unittest .skipUnless (is_enabled )
232+ @unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
217233def test_native_executable_module ():
218234 java_home , graalpy , java = get_gp ()
219235 if graalpy is None or java is None :
@@ -240,14 +256,14 @@ def test_native_executable_module():
240256 cmd = [graalpy , "-m" , "standalone" , "--verbose" , "native" , "-Os" , "-m" , module_dir , "-o" , target_file ]
241257
242258 p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
243- out = p .stdout .decode ()
259+ out = p .stdout .decode (errors = 'backslashreplace' )
244260 print (out )
245- print (p .stderr .decode ())
261+ print (p .stderr .decode (errors = 'backslashreplace' ))
246262 assert "Bundling Python resources into" in out
247263
248264 cmd = [target_file ]
249265 p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
250- out = p .stdout .decode ()
266+ out = p .stdout .decode (errors = 'backslashreplace' )
251267 print (out )
252- print (p .stderr .decode ())
253- assert "hello standalone world" in out
268+ print (p .stderr .decode (errors = 'backslashreplace' ))
269+ assert "hello standalone world" in out
0 commit comments