MCPcopy Index your code
hub / github.com/python/cpython / test_invalid_env

Method test_invalid_env

Lib/test/test_subprocess.py:878–906  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

876 subprocess.Popen([sys.executable, "-c", "pass#\0"])
877
878 def test_invalid_env(self):
879 # null character in the environment variable name
880 newenv = os.environ.copy()
881 newenv["FRUIT\0VEGETABLE"] = "cabbage"
882 with self.assertRaises(ValueError):
883 subprocess.Popen(ZERO_RETURN_CMD, env=newenv)
884
885 # null character in the environment variable value
886 newenv = os.environ.copy()
887 newenv["FRUIT"] = "orange\0VEGETABLE=cabbage"
888 with self.assertRaises(ValueError):
889 subprocess.Popen(ZERO_RETURN_CMD, env=newenv)
890
891 # equal character in the environment variable name
892 newenv = os.environ.copy()
893 newenv["FRUIT=ORANGE"] = "lemon"
894 with self.assertRaises(ValueError):
895 subprocess.Popen(ZERO_RETURN_CMD, env=newenv)
896
897 # equal character in the environment variable value
898 newenv = os.environ.copy()
899 newenv["FRUIT"] = "orange=lemon"
900 with subprocess.Popen([sys.executable, "-c",
901 'import sys, os;'
902 'sys.stdout.write(os.getenv("FRUIT"))'],
903 stdout=subprocess.PIPE,
904 env=newenv) as p:
905 stdout, stderr = p.communicate()
906 self.assertEqual(stdout, b"orange=lemon")
907
908 @unittest.skipUnless(sys.platform == "win32", "Windows only issue")
909 def test_win32_invalid_env(self):

Callers

nothing calls this directly

Calls 4

copyMethod · 0.45
assertRaisesMethod · 0.45
communicateMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected