Skip to content

Commit ad6553c

Browse files
committed
Add test_pythonsafepath_env in test_cmd_line
1 parent f3e18e9 commit ad6553c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Lib/subprocess.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ def _args_from_interpreter_flags():
288288
'verbose': 'v',
289289
'bytes_warning': 'b',
290290
'quiet': 'q',
291+
'safe_path': 'P'
291292
# -O is handled in _optim_args_from_interpreter_flags()
292293
}
293294
args = _optim_args_from_interpreter_flags()

Lib/test/test_cmd_line.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,25 @@ def test_sys_flags_not_set(self):
884884
PYTHONVERBOSE="1",
885885
)
886886

887+
# TODO: RUSTPYTHON
888+
@unittest.expectedFailure
889+
def test_pythonsafepath_env(self):
890+
# Test the PYTHONSAFEPATH environment variable
891+
code = "import sys; print(sys.flags.safe_path)"
892+
env = dict(os.environ)
893+
env.pop('PYTHONSAFEPATH', None)
894+
args = (sys.executable, '-P', code)
895+
896+
proc = subprocess.run(args, stdout=subprocess.PIPE,
897+
universal_newlines=True, env=env)
898+
self.assertEqual(proc.stdout.rstrip(), 'False')
899+
self.assertEqual(proc.returncode, 0, proc)
900+
901+
env['PYTHONSAFEPATH'] = '1'
902+
proc = subprocess.run(args, stdout=subprocess.PIPE,
903+
universal_newlines=True, env=env)
904+
self.assertEqual(proc.stdout.rstrip(), 'True')
905+
self.assertEqual(proc.returncode, 0, proc)
887906

888907
def test_main():
889908
support.run_unittest(CmdLineTest, IgnoreEnvironmentTest)

0 commit comments

Comments
 (0)