(self)
| 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]) |
nothing calls this directly
no test coverage detected