41
41
import subprocess
42
42
import tempfile
43
43
import unittest
44
+ import shutil
45
+ import glob
44
46
45
47
is_enabled = 'ENABLE_STANDALONE_UNITTESTS' in os .environ and os .environ ['ENABLE_STANDALONE_UNITTESTS' ] == "true"
48
+ MVN = shutil .which ('mvn' )
46
49
47
50
def get_executable (file ):
48
51
if os .path .isfile (file ):
@@ -75,12 +78,25 @@ def get_gp():
75
78
sep = "\n " ,
76
79
)
77
80
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
+
78
88
return java_home , graalpy , java
79
89
80
90
def get_env (java_home ):
81
91
env = os .environ .copy ()
82
92
env .update ({"JAVA_HOME" : java_home })
83
93
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
+
84
100
to_be_removed = []
85
101
for k in env :
86
102
# subprocess complaining about key names with "=" in them
@@ -93,7 +109,7 @@ def get_env(java_home):
93
109
94
110
return env
95
111
96
- @unittest .skipUnless (is_enabled )
112
+ @unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
97
113
def test_polyglot_app ():
98
114
99
115
java_home , graalpy , java = get_gp ()
@@ -105,40 +121,40 @@ def test_polyglot_app():
105
121
106
122
cmd = [graalpy , "-m" , "standalone" , "--verbose" , "polyglot_app" , "-o" , target_dir ]
107
123
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' ))
111
127
assert "Creating polyglot java python application in directory " + target_dir in out
112
128
113
- cmd = ["mvn" , "package" , "-Pnative" ]
129
+ cmd = [MVN , "package" , "-Pnative" ]
114
130
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' )
116
132
print (out )
117
- print (p .stderr .decode ())
133
+ print (p .stderr .decode (errors = 'backslashreplace' ))
118
134
assert "BUILD SUCCESS" in out
119
135
120
136
cmd = [os .path .join (target_dir , "target" , "polyglot_app" )]
121
137
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' )
123
139
print (out )
124
- print (p .stderr .decode ())
140
+ print (p .stderr .decode (errors = 'backslashreplace' ))
125
141
assert out .endswith ("hello java\n " )
126
142
127
- cmd = ["mvn" , "package" , "-Pjar" ]
143
+ cmd = [MVN , "package" , "-Pjar" ]
128
144
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' )
130
146
print (out )
131
- print (p .stderr .decode ())
147
+ print (p .stderr .decode (errors = 'backslashreplace' ))
132
148
assert "BUILD SUCCESS" in out
133
149
134
150
cmd = [java , "-jar" , os .path .join (target_dir , "target" , "polyglot_app-1.0-SNAPSHOT.jar" )]
135
151
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' )
137
153
print (out )
138
- print (p .stderr .decode ())
154
+ print (p .stderr .decode (errors = 'backslashreplace' ))
139
155
assert out .endswith ("hello java\n " )
140
156
141
- @unittest .skipUnless (is_enabled )
157
+ @unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
142
158
def test_native_executable_one_file ():
143
159
java_home , graalpy , java = get_gp ()
144
160
if graalpy is None or java is None :
@@ -156,19 +172,19 @@ def test_native_executable_one_file():
156
172
cmd = [graalpy , "-m" , "standalone" , "--verbose" , "native" , "-m" , source_file , "-o" , target_file ]
157
173
158
174
p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
159
- out = p .stdout .decode ()
175
+ out = p .stdout .decode (errors = 'backslashreplace' )
160
176
print (out )
161
- print (p .stderr .decode ())
177
+ print (p .stderr .decode (errors = 'backslashreplace' ))
162
178
assert "Bundling Python resources into" in out
163
179
164
180
cmd = [target_file ]
165
181
p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
166
- out = p .stdout .decode ()
182
+ out = p .stdout .decode (errors = 'backslashreplace' )
167
183
print (out )
168
- print (p .stderr .decode ())
184
+ print (p .stderr .decode (errors = 'backslashreplace' ))
169
185
assert "hello world" in out
170
186
171
- @unittest .skipUnless (is_enabled )
187
+ @unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
172
188
def test_native_executable_one_file_venv ():
173
189
java_home , graalpy , java = get_gp ()
174
190
if graalpy is None or java is None :
@@ -186,34 +202,34 @@ def test_native_executable_one_file_venv():
186
202
venv_dir = os .path .join (target_dir , "venv" )
187
203
cmd = [graalpy , "-m" , "venv" , venv_dir ]
188
204
p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
189
- out = p .stdout .decode ()
205
+ out = p .stdout .decode (errors = 'backslashreplace' )
190
206
print (out )
191
- print (p .stderr .decode ())
207
+ print (p .stderr .decode (errors = 'backslashreplace' ))
192
208
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" ]
195
211
p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
196
- out = p .stdout .decode ()
212
+ out = p .stdout .decode (errors = 'backslashreplace' )
197
213
print (out )
198
- print (p .stderr .decode ())
214
+ print (p .stderr .decode (errors = 'backslashreplace' ))
199
215
200
216
target_file = os .path .join (target_dir , "hello" )
201
217
cmd = [graalpy , "-m" , "standalone" , "--verbose" , "native" , "-Os" , "-m" , source_file , "--venv" , venv_dir , "-o" , target_file ]
202
218
p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
203
- out = p .stdout .decode ()
219
+ out = p .stdout .decode (errors = 'backslashreplace' )
204
220
print (out )
205
- print (p .stderr .decode ())
221
+ print (p .stderr .decode (errors = 'backslashreplace' ))
206
222
assert "Bundling Python resources into" in out
207
223
208
224
cmd = [target_file ]
209
225
p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
210
- out = p .stdout .decode ()
226
+ out = p .stdout .decode (errors = 'backslashreplace' )
211
227
print (out )
212
- print (p .stderr .decode ())
228
+ print (p .stderr .decode (errors = 'backslashreplace' ))
213
229
214
230
assert "hello standalone world" in out
215
231
216
- @unittest .skipUnless (is_enabled )
232
+ @unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
217
233
def test_native_executable_module ():
218
234
java_home , graalpy , java = get_gp ()
219
235
if graalpy is None or java is None :
@@ -240,14 +256,14 @@ def test_native_executable_module():
240
256
cmd = [graalpy , "-m" , "standalone" , "--verbose" , "native" , "-Os" , "-m" , module_dir , "-o" , target_file ]
241
257
242
258
p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
243
- out = p .stdout .decode ()
259
+ out = p .stdout .decode (errors = 'backslashreplace' )
244
260
print (out )
245
- print (p .stderr .decode ())
261
+ print (p .stderr .decode (errors = 'backslashreplace' ))
246
262
assert "Bundling Python resources into" in out
247
263
248
264
cmd = [target_file ]
249
265
p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
250
- out = p .stdout .decode ()
266
+ out = p .stdout .decode (errors = 'backslashreplace' )
251
267
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