(self, spawn)
| 3417 | self.assertRaises(ValueError, os.spawnve, os.P_NOWAIT, program, [''], {}) |
| 3418 | |
| 3419 | def _test_invalid_env(self, spawn): |
| 3420 | program = sys.executable |
| 3421 | args = self.quote_args([program, '-c', 'pass']) |
| 3422 | |
| 3423 | # null character in the environment variable name |
| 3424 | newenv = os.environ.copy() |
| 3425 | newenv["FRUIT\0VEGETABLE"] = "cabbage" |
| 3426 | try: |
| 3427 | exitcode = spawn(os.P_WAIT, program, args, newenv) |
| 3428 | except ValueError: |
| 3429 | pass |
| 3430 | else: |
| 3431 | self.assertEqual(exitcode, 127) |
| 3432 | |
| 3433 | # null character in the environment variable value |
| 3434 | newenv = os.environ.copy() |
| 3435 | newenv["FRUIT"] = "orange\0VEGETABLE=cabbage" |
| 3436 | try: |
| 3437 | exitcode = spawn(os.P_WAIT, program, args, newenv) |
| 3438 | except ValueError: |
| 3439 | pass |
| 3440 | else: |
| 3441 | self.assertEqual(exitcode, 127) |
| 3442 | |
| 3443 | # equal character in the environment variable name |
| 3444 | newenv = os.environ.copy() |
| 3445 | newenv["FRUIT=ORANGE"] = "lemon" |
| 3446 | try: |
| 3447 | exitcode = spawn(os.P_WAIT, program, args, newenv) |
| 3448 | except ValueError: |
| 3449 | pass |
| 3450 | else: |
| 3451 | self.assertEqual(exitcode, 127) |
| 3452 | |
| 3453 | # equal character in the environment variable value |
| 3454 | filename = os_helper.TESTFN |
| 3455 | self.addCleanup(os_helper.unlink, filename) |
| 3456 | with open(filename, "w", encoding="utf-8") as fp: |
| 3457 | fp.write('import sys, os\n' |
| 3458 | 'if os.getenv("FRUIT") != "orange=lemon":\n' |
| 3459 | ' raise AssertionError') |
| 3460 | |
| 3461 | args = self.quote_args([program, filename]) |
| 3462 | newenv = os.environ.copy() |
| 3463 | newenv["FRUIT"] = "orange=lemon" |
| 3464 | exitcode = spawn(os.P_WAIT, program, args, newenv) |
| 3465 | self.assertEqual(exitcode, 0) |
| 3466 | |
| 3467 | @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 3468 | @requires_os_func('spawnve') |
no test coverage detected