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

Method test_isolatedmode

Lib/test/test_cmd_line.py:644–668  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

642 @unittest.skipIf(interpreter_requires_environment(),
643 'Cannot run -I tests when PYTHON env vars are required.')
644 def test_isolatedmode(self):
645 self.verify_valid_flag('-I')
646 self.verify_valid_flag('-IEPs')
647 rc, out, err = assert_python_ok('-I', '-c',
648 'from sys import flags as f; '
649 'print(f.no_user_site, f.ignore_environment, f.isolated, f.safe_path)',
650 # dummyvar to prevent extraneous -E
651 dummyvar="")
652 self.assertEqual(out.strip(), b'1 1 1 True')
653 with os_helper.temp_cwd() as tmpdir:
654 fake = os.path.join(tmpdir, "uuid.py")
655 main = os.path.join(tmpdir, "main.py")
656 with open(fake, "w", encoding="utf-8") as f:
657 f.write("raise RuntimeError('isolated mode test')\n")
658 with open(main, "w", encoding="utf-8") as f:
659 f.write("import uuid\n")
660 f.write("print('ok')\n")
661 # Use -E to ignore PYTHONSAFEPATH env var
662 self.assertRaises(subprocess.CalledProcessError,
663 subprocess.check_output,
664 [sys.executable, '-E', main], cwd=tmpdir,
665 stderr=subprocess.DEVNULL)
666 out = subprocess.check_output([sys.executable, "-I", main],
667 cwd=tmpdir)
668 self.assertEqual(out.strip(), b"ok")
669
670 def test_sys_flags_set(self):
671 # Issue 31845: a startup refactoring broke reading flags from env vars

Callers

nothing calls this directly

Calls 9

verify_valid_flagMethod · 0.95
assert_python_okFunction · 0.90
openFunction · 0.50
assertEqualMethod · 0.45
stripMethod · 0.45
joinMethod · 0.45
writeMethod · 0.45
assertRaisesMethod · 0.45
check_outputMethod · 0.45

Tested by

no test coverage detected