MCPcopy Create free account
hub / github.com/python/cpython / test_zippath_from_non_installed_posix

Method test_zippath_from_non_installed_posix

Lib/test/test_venv.py:682–766  ·  view source on GitHub ↗

Test that when create venv from non-installed python, the zip path value is as expected.

(self)

Source from the content-addressed store, hash-verified

680 @unittest.skipIf(os.name == 'nt', 'not relevant on Windows')
681 @requireVenvCreate
682 def test_zippath_from_non_installed_posix(self):
683 """
684 Test that when create venv from non-installed python, the zip path
685 value is as expected.
686 """
687 rmtree(self.env_dir)
688 # First try to create a non-installed python. It's not a real full
689 # functional non-installed python, but enough for this test.
690 platlibdir = sys.platlibdir
691 non_installed_dir = os.path.realpath(tempfile.mkdtemp())
692 self.addCleanup(rmtree, non_installed_dir)
693 bindir = os.path.join(non_installed_dir, self.bindir)
694 os.mkdir(bindir)
695 python_exe = os.path.basename(sys.executable)
696 shutil.copy2(sys.executable, os.path.join(bindir, python_exe))
697 libdir = os.path.join(non_installed_dir, platlibdir, self.lib[1])
698 os.makedirs(libdir)
699 landmark = os.path.join(libdir, "os.py")
700 abi_thread = "t" if sysconfig.get_config_var("Py_GIL_DISABLED") else ""
701 stdlib_zip = f"python{sys.version_info.major}{sys.version_info.minor}{abi_thread}"
702 zip_landmark = os.path.join(non_installed_dir,
703 platlibdir,
704 stdlib_zip)
705 additional_pythonpath_for_non_installed = []
706
707 # Copy stdlib files to the non-installed python so venv can
708 # correctly calculate the prefix.
709 for eachpath in sys.path:
710 if eachpath.endswith(".zip"):
711 if os.path.isfile(eachpath):
712 shutil.copyfile(
713 eachpath,
714 os.path.join(non_installed_dir, platlibdir))
715 elif os.path.isfile(os.path.join(eachpath, "os.py")):
716 names = os.listdir(eachpath)
717 ignored_names = copy_python_src_ignore(eachpath, names)
718 for name in names:
719 if name in ignored_names:
720 continue
721 if name == "site-packages":
722 continue
723 fn = os.path.join(eachpath, name)
724 if os.path.isfile(fn):
725 shutil.copy(fn, libdir)
726 elif os.path.isdir(fn):
727 shutil.copytree(fn, os.path.join(libdir, name),
728 ignore=copy_python_src_ignore)
729 else:
730 additional_pythonpath_for_non_installed.append(
731 eachpath)
732 cmd = [os.path.join(non_installed_dir, self.bindir, python_exe),
733 "-m",
734 "venv",
735 "--without-pip",
736 "--without-scm-ignore-files",
737 self.env_dir]
738 # Our fake non-installed python is not fully functional because
739 # it cannot find the extensions. Set PYTHONPATH so it can run the

Callers

nothing calls this directly

Calls 15

rmtreeFunction · 0.90
copy_python_src_ignoreFunction · 0.90
mkdtempMethod · 0.80
addCleanupMethod · 0.80
copyfileMethod · 0.80
listdirMethod · 0.80
assertTrueMethod · 0.80
check_outputFunction · 0.70
realpathMethod · 0.45
joinMethod · 0.45
mkdirMethod · 0.45
basenameMethod · 0.45

Tested by

no test coverage detected