MCPcopy Index your code
hub / github.com/RustPython/RustPython / _test_invalid_env

Method _test_invalid_env

Lib/test/test_os.py:3720–3766  ·  view source on GitHub ↗
(self, spawn)

Source from the content-addressed store, hash-verified

3718 self.assertRaises(ValueError, os.spawnve, os.P_NOWAIT, program, [''], {})
3719
3720 def _test_invalid_env(self, spawn):
3721 program = sys.executable
3722 args = self.quote_args([program, '-c', 'pass'])
3723
3724 # null character in the environment variable name
3725 newenv = os.environ.copy()
3726 newenv["FRUIT\0VEGETABLE"] = "cabbage"
3727 try:
3728 exitcode = spawn(os.P_WAIT, program, args, newenv)
3729 except ValueError:
3730 pass
3731 else:
3732 self.assertEqual(exitcode, 127)
3733
3734 # null character in the environment variable value
3735 newenv = os.environ.copy()
3736 newenv["FRUIT"] = "orange\0VEGETABLE=cabbage"
3737 try:
3738 exitcode = spawn(os.P_WAIT, program, args, newenv)
3739 except ValueError:
3740 pass
3741 else:
3742 self.assertEqual(exitcode, 127)
3743
3744 # equal character in the environment variable name
3745 newenv = os.environ.copy()
3746 newenv["FRUIT=ORANGE"] = "lemon"
3747 try:
3748 exitcode = spawn(os.P_WAIT, program, args, newenv)
3749 except ValueError:
3750 pass
3751 else:
3752 self.assertEqual(exitcode, 127)
3753
3754 # equal character in the environment variable value
3755 filename = os_helper.TESTFN
3756 self.addCleanup(os_helper.unlink, filename)
3757 with open(filename, "w", encoding="utf-8") as fp:
3758 fp.write('import sys, os\n'
3759 'if os.getenv("FRUIT") != "orange=lemon":\n'
3760 ' raise AssertionError')
3761
3762 args = self.quote_args([program, filename])
3763 newenv = os.environ.copy()
3764 newenv["FRUIT"] = "orange=lemon"
3765 exitcode = spawn(os.P_WAIT, program, args, newenv)
3766 self.assertEqual(exitcode, 0)
3767
3768 @requires_os_func('spawnve')
3769 def test_spawnve_invalid_env(self):

Callers 2

Calls 7

quote_argsMethod · 0.95
addCleanupMethod · 0.80
spawnFunction · 0.50
openFunction · 0.50
copyMethod · 0.45
assertEqualMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected