|
11 | 11 | from subprocess import CalledProcessError |
12 | 12 | from tempfile import mkdtemp |
13 | 13 |
|
| 14 | +from tests.util import run_subprocess_with_graalpy_startup_retry |
| 15 | + |
14 | 16 | POSIX_BACKEND_IS_JAVA = sys.implementation.name == "graalpy" and __graalpython__.posix_module_backend() == 'java' |
15 | 17 |
|
16 | 18 | def test_os_pipe(): |
@@ -228,54 +230,52 @@ def test_subprocess_inherits_environ(self): |
228 | 230 | @unittest.skipIf(sys.platform == 'win32', "TODO the cmd replacement breaks the test") |
229 | 231 | def test_graal_python_args(self): |
230 | 232 | if sys.implementation.name == "graalpy": |
231 | | - import subprocess |
232 | | - |
233 | 233 | def env_with_graal_python_args(args): |
234 | 234 | env = os.environ.copy() |
235 | 235 | env["GRAAL_PYTHON_ARGS"] = args |
236 | 236 | return env |
237 | 237 |
|
238 | 238 | env = env_with_graal_python_args("-c 12") |
239 | | - result = subprocess.run([sys.executable], env=env) |
240 | | - self.assertEqual(0, result.returncode) |
| 239 | + result = run_subprocess_with_graalpy_startup_retry([sys.executable], env=env, text=True) |
| 240 | + self.assertEqual(0, result.returncode, result.stderr) |
241 | 241 |
|
242 | 242 | env = env_with_graal_python_args("-c 'print(12)'") |
243 | | - result = subprocess.check_output([sys.executable], env=env, text=True) |
| 243 | + result = run_subprocess_with_graalpy_startup_retry([sys.executable], env=env, text=True, check=True).stdout |
244 | 244 | self.assertEqual('12\n', result) |
245 | 245 |
|
246 | 246 | env = env_with_graal_python_args("""-c 'print("Hello world")'""") |
247 | | - result = subprocess.check_output([sys.executable], env=env, text=True) |
| 247 | + result = run_subprocess_with_graalpy_startup_retry([sys.executable], env=env, text=True, check=True).stdout |
248 | 248 | self.assertEqual('Hello world\n', result) |
249 | 249 |
|
250 | 250 | env = env_with_graal_python_args("""-c ""'print("Hello world")'""""") |
251 | | - result = subprocess.check_output([sys.executable], env=env, text=True) |
| 251 | + result = run_subprocess_with_graalpy_startup_retry([sys.executable], env=env, text=True, check=True).stdout |
252 | 252 | self.assertEqual('Hello world\n', result) |
253 | 253 |
|
254 | 254 | env = env_with_graal_python_args(r"""-c 'print(\'"Hello world"\')'""") |
255 | | - result = subprocess.check_output([sys.executable], env=env, text=True) |
| 255 | + result = run_subprocess_with_graalpy_startup_retry([sys.executable], env=env, text=True, check=True).stdout |
256 | 256 | self.assertEqual('"Hello world"\n', result) |
257 | 257 |
|
258 | 258 | env = env_with_graal_python_args("""\v-c\vprint('"Hello world"')""") |
259 | | - result = subprocess.check_output([sys.executable], env=env, text=True) |
| 259 | + result = run_subprocess_with_graalpy_startup_retry([sys.executable], env=env, text=True, check=True).stdout |
260 | 260 | self.assertEqual('"Hello world"\n', result) |
261 | 261 |
|
262 | 262 | env = env_with_graal_python_args("""\v-c\vprint('Hello', "world")""") |
263 | | - result = subprocess.check_output([sys.executable], env=env, text=True) |
| 263 | + result = run_subprocess_with_graalpy_startup_retry([sys.executable], env=env, text=True, check=True).stdout |
264 | 264 | self.assertEqual('Hello world\n', result) |
265 | 265 |
|
266 | 266 | # check that the subprocess receives the args and thus it should fail because it recurses |
267 | 267 | args = """\v-c\vimport os\nprint(os.environ.get("GRAAL_PYTHON_ARGS"))""" |
268 | 268 | env = env_with_graal_python_args(args) |
269 | | - result = subprocess.check_output([sys.executable], env=env, text=True) |
| 269 | + result = run_subprocess_with_graalpy_startup_retry([sys.executable], env=env, text=True, check=True).stdout |
270 | 270 | self.assertEqual(f"{args}\n", result) |
271 | 271 |
|
272 | 272 | # check that the subprocess does not receive the args when we end with \v |
273 | 273 | env = env_with_graal_python_args("""\v-c\vimport os\nprint(os.environ.get("GRAAL_PYTHON_ARGS"))\v""") |
274 | | - result = subprocess.check_output([sys.executable], env=env, text=True) |
| 274 | + result = run_subprocess_with_graalpy_startup_retry([sys.executable], env=env, text=True, check=True).stdout |
275 | 275 | self.assertEqual('None\n', result) |
276 | 276 |
|
277 | 277 | # check that the subprocess receives an empty arg |
278 | 278 | args = """\v-c\vimport sys\nprint(repr(sys.argv))\va1\v\va3""" |
279 | 279 | env = env_with_graal_python_args(args) |
280 | | - result = subprocess.check_output([sys.executable], env=env, text=True) |
| 280 | + result = run_subprocess_with_graalpy_startup_retry([sys.executable], env=env, text=True, check=True).stdout |
281 | 281 | self.assertEqual("['-c', 'a1', '', 'a3']\n", result) |
0 commit comments