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

Method test_shebang_command_in_venv

Lib/test/test_launcher.py:772–795  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

770 )
771
772 def test_shebang_command_in_venv(self):
773 stem = "python-that-is-not-on-path"
774
775 # First ensure that our test name doesn't exist, and the launcher does
776 # not match any installed env
777 with self.script(f'#! /usr/bin/env {stem} arg1') as script:
778 data = self.run_py([script], expect_returncode=103)
779
780 with self.fake_venv() as (venv_exe, env):
781 # Put a "normal" Python on PATH as a distraction.
782 # The active VIRTUAL_ENV should be preferred when the name isn't an
783 # exact match.
784 exe = Path(Path(venv_exe).name).absolute()
785 exe.touch()
786 self.addCleanup(exe.unlink)
787 env["PATH"] = f"{exe.parent};{os.environ['PATH']}"
788
789 with self.script(f'#! /usr/bin/env {stem} arg1') as script:
790 data = self.run_py([script], env=env)
791 self.assertEqual(data["stdout"].strip(), f"{quote(venv_exe)} arg1 {quote(script)}")
792
793 with self.script(f'#! /usr/bin/env {exe.stem} arg1') as script:
794 data = self.run_py([script], env=env)
795 self.assertEqual(data["stdout"].strip(), f"{quote(exe)} arg1 {quote(script)}")
796
797 def test_shebang_executable_extension(self):
798 with self.script('#! /usr/bin/env python3.99') as script:

Callers

nothing calls this directly

Calls 10

PathClass · 0.90
run_pyMethod · 0.80
fake_venvMethod · 0.80
absoluteMethod · 0.80
addCleanupMethod · 0.80
quoteFunction · 0.70
scriptMethod · 0.45
touchMethod · 0.45
assertEqualMethod · 0.45
stripMethod · 0.45

Tested by

no test coverage detected