48
48
if 'MAVEN_REPO_OVERRIDE' in os .environ :
49
49
MVN_CMD += ['-Dmaven.repo.remote=' + os .environ ['MAVEN_REPO_OVERRIDE' ]]
50
50
51
+ def run_cmd (cmd , env , cwd = None ):
52
+ process = subprocess .Popen (cmd , env = env , cwd = cwd , stdout = subprocess .PIPE , stderr = subprocess .STDOUT , universal_newlines = True , text = True )
53
+ out = []
54
+ for line in iter (process .stdout .readline , "" ):
55
+ print (line , end = "" )
56
+ out .append (line )
57
+ return "" .join (out )
58
+
51
59
def get_executable (file ):
52
60
if os .path .isfile (file ):
53
61
return file
@@ -99,24 +107,15 @@ def test_polyglot_app():
99
107
target_dir = os .path .join (tmpdir , "polyglot_app_test" )
100
108
101
109
cmd = [graalpy , "-m" , "standalone" , "--verbose" , "polyglot_app" , "-o" , target_dir ]
102
- p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
103
- out = p .stdout .decode (errors = 'backslashreplace' )
104
- print (p .stdout .decode (errors = 'backslashreplace' ))
105
- print (p .stderr .decode (errors = 'backslashreplace' ))
110
+ out = run_cmd (cmd , env )
106
111
assert "Creating polyglot java python application in directory " + target_dir in out
107
112
108
113
cmd = MVN_CMD + ["package" , "-Pnative" ]
109
- p = subprocess .run (cmd , cwd = target_dir , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
110
- out = p .stdout .decode (errors = 'backslashreplace' )
111
- print (out )
112
- print (p .stderr .decode (errors = 'backslashreplace' ))
114
+ out = run_cmd (cmd , env , cwd = target_dir )
113
115
assert "BUILD SUCCESS" in out
114
116
115
117
cmd = [os .path .join (target_dir , "target" , "polyglot_app" )]
116
- p = subprocess .run (cmd , cwd = target_dir , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
117
- out = p .stdout .decode (errors = 'backslashreplace' )
118
- print (out )
119
- print (p .stderr .decode (errors = 'backslashreplace' ))
118
+ out = run_cmd (cmd , env , cwd = target_dir )
120
119
assert out .endswith ("hello java\n " )
121
120
122
121
@@ -137,21 +136,15 @@ def test_native_executable_one_file():
137
136
target_file = os .path .join (tmpdir , "hello" )
138
137
cmd = [graalpy , "-m" , "standalone" , "--verbose" , "native" , "-m" , source_file , "-o" , target_file ]
139
138
140
- p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
141
- out = p .stdout .decode (errors = 'backslashreplace' )
142
- print (out )
143
- print (p .stderr .decode (errors = 'backslashreplace' ))
139
+ out = run_cmd (cmd , env )
144
140
assert "Bundling Python resources into" in out
145
141
146
142
cmd = [target_file , "arg1" , "arg2" ]
147
- p = subprocess .run (" " .join (cmd ), env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE , shell = True )
148
- out = p .stdout .decode (errors = 'backslashreplace' )
149
- print (out )
150
- print (p .stderr .decode (errors = 'backslashreplace' ))
143
+ out = run_cmd (cmd , env )
151
144
assert "hello world, argv[1:]: " + str (cmd [1 :]) in out
152
145
153
146
@unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
154
- def test_native_executable_one_file_venv ():
147
+ def test_native_executable_venv_and_one_file ():
155
148
graalpy = get_gp ()
156
149
if graalpy is None :
157
150
return
@@ -166,31 +159,19 @@ def test_native_executable_one_file_venv():
166
159
167
160
venv_dir = os .path .join (target_dir , "venv" )
168
161
cmd = [graalpy , "-m" , "venv" , venv_dir ]
169
- p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
170
- out = p .stdout .decode (errors = 'backslashreplace' )
171
- print (out )
172
- print (p .stderr .decode (errors = 'backslashreplace' ))
162
+ out = run_cmd (cmd , env )
173
163
174
164
venv_python = os .path .join (venv_dir , "Scripts" , "python.cmd" ) if os .name == "nt" else os .path .join (venv_dir , "bin" , "python" )
175
165
cmd = [venv_python , "-m" , "pip" , "--no-cache-dir" , "install" , "termcolor" ]
176
- p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
177
- out = p .stdout .decode (errors = 'backslashreplace' )
178
- print (out )
179
- print (p .stderr .decode (errors = 'backslashreplace' ))
166
+ out = run_cmd (cmd , env )
180
167
181
168
target_file = os .path .join (target_dir , "hello" )
182
169
cmd = [graalpy , "-m" , "standalone" , "--verbose" , "native" , "-Os" , "-m" , source_file , "--venv" , venv_dir , "-o" , target_file ]
183
- p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
184
- out = p .stdout .decode (errors = 'backslashreplace' )
185
- print (out )
186
- print (p .stderr .decode (errors = 'backslashreplace' ))
170
+ out = run_cmd (cmd , env )
187
171
assert "Bundling Python resources into" in out
188
172
189
173
cmd = [target_file ]
190
- p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
191
- out = p .stdout .decode (errors = 'backslashreplace' )
192
- print (out )
193
- print (p .stderr .decode (errors = 'backslashreplace' ))
174
+ out = run_cmd (cmd , env )
194
175
195
176
assert "hello standalone world" in out
196
177
@@ -219,15 +200,9 @@ def test_native_executable_module():
219
200
target_file = os .path .join (tmp_dir , "hello" )
220
201
cmd = [graalpy , "-m" , "standalone" , "--verbose" , "native" , "-Os" , "-m" , module_dir , "-o" , target_file ]
221
202
222
- p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
223
- out = p .stdout .decode (errors = 'backslashreplace' )
224
- print (out )
225
- print (p .stderr .decode (errors = 'backslashreplace' ))
203
+ out = run_cmd (cmd , env )
226
204
assert "Bundling Python resources into" in out
227
205
228
206
cmd = [target_file ]
229
- p = subprocess .run (cmd , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
230
- out = p .stdout .decode (errors = 'backslashreplace' )
231
- print (out )
232
- print (p .stderr .decode (errors = 'backslashreplace' ))
207
+ out = run_cmd (cmd , env )
233
208
assert "hello standalone world" in out
0 commit comments