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

Method test_undecodable_env

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

Source from the content-addressed store, hash-verified

2893 self.fail("Expected ValueError or subprocess.SubprocessError")
2894
2895 def test_undecodable_env(self):
2896 for key, value in (('test', 'abc\uDCFF'), ('test\uDCFF', '42')):
2897 encoded_value = value.encode("ascii", "surrogateescape")
2898
2899 # test str with surrogates
2900 script = "import os; print(ascii(os.getenv(%s)))" % repr(key)
2901 env = os.environ.copy()
2902 env[key] = value
2903 # Use C locale to get ASCII for the locale encoding to force
2904 # surrogate-escaping of \xFF in the child process
2905 env['LC_ALL'] = 'C'
2906 decoded_value = value
2907 stdout = subprocess.check_output(
2908 [sys.executable, "-c", script],
2909 env=env)
2910 stdout = stdout.rstrip(b'\n\r')
2911 self.assertEqual(stdout.decode('ascii'), ascii(decoded_value))
2912
2913 # test bytes
2914 key = key.encode("ascii", "surrogateescape")
2915 script = "import os; print(ascii(os.getenvb(%s)))" % repr(key)
2916 env = os.environ.copy()
2917 env[key] = encoded_value
2918 stdout = subprocess.check_output(
2919 [sys.executable, "-c", script],
2920 env=env)
2921 stdout = stdout.rstrip(b'\n\r')
2922 self.assertEqual(stdout.decode('ascii'), ascii(encoded_value))
2923
2924 def test_bytes_program(self):
2925 abs_program = os.fsencode(ZERO_RETURN_CMD[0])

Callers

nothing calls this directly

Calls 7

asciiFunction · 0.85
encodeMethod · 0.45
copyMethod · 0.45
check_outputMethod · 0.45
rstripMethod · 0.45
assertEqualMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected