Skip to content

Commit 16218cf

Browse files
naonusyouknowone
authored andcommitted
Add test_pythonsafepath_env in test_cmd_line
1 parent 62d09b4 commit 16218cf

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Lib/subprocess.py

+1
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ def _args_from_interpreter_flags():
309309
'verbose': 'v',
310310
'bytes_warning': 'b',
311311
'quiet': 'q',
312+
'safe_path': 'P'
312313
# -O is handled in _optim_args_from_interpreter_flags()
313314
}
314315
args = _optim_args_from_interpreter_flags()

Lib/test/test_cmd_line.py

+19
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,25 @@ def test_sys_flags_not_set(self):
10081008
PYTHONSAFEPATH="1",
10091009
)
10101010

1011+
# TODO: RUSTPYTHON
1012+
@unittest.expectedFailure
1013+
def test_pythonsafepath_env(self):
1014+
# Test the PYTHONSAFEPATH environment variable
1015+
code = "import sys; print(sys.flags.safe_path)"
1016+
env = dict(os.environ)
1017+
env.pop('PYTHONSAFEPATH', None)
1018+
args = (sys.executable, '-P', code)
1019+
1020+
proc = subprocess.run(args, stdout=subprocess.PIPE,
1021+
universal_newlines=True, env=env)
1022+
self.assertEqual(proc.stdout.rstrip(), 'False')
1023+
self.assertEqual(proc.returncode, 0, proc)
1024+
1025+
env['PYTHONSAFEPATH'] = '1'
1026+
proc = subprocess.run(args, stdout=subprocess.PIPE,
1027+
universal_newlines=True, env=env)
1028+
self.assertEqual(proc.stdout.rstrip(), 'True')
1029+
self.assertEqual(proc.returncode, 0, proc)
10111030

10121031
class SyntaxErrorTests(unittest.TestCase):
10131032
def check_string(self, code):

0 commit comments

Comments
 (0)