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

Method test_dll_dependency_import

Lib/test/test_import/__init__.py:775–817  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

773
774 @unittest.skipUnless(sys.platform == "win32", "Windows-specific")
775 def test_dll_dependency_import(self):
776 from _winapi import GetModuleFileName
777 dllname = GetModuleFileName(sys.dllhandle)
778 pydname = importlib.util.find_spec("_sqlite3").origin
779 depname = os.path.join(
780 os.path.dirname(pydname),
781 "sqlite3{}.dll".format("_d" if "_d" in pydname else ""))
782
783 with os_helper.temp_dir() as tmp:
784 tmp2 = os.path.join(tmp, "DLLs")
785 os.mkdir(tmp2)
786
787 pyexe = os.path.join(tmp, os.path.basename(sys.executable))
788 shutil.copy(sys.executable, pyexe)
789 shutil.copy(dllname, tmp)
790 for f in glob.glob(os.path.join(glob.escape(sys.prefix), "vcruntime*.dll")):
791 shutil.copy(f, tmp)
792
793 shutil.copy(pydname, tmp2)
794
795 env = None
796 env = {k.upper(): os.environ[k] for k in os.environ}
797 env["PYTHONPATH"] = tmp2 + ";" + STDLIB_DIR
798
799 # Test 1: import with added DLL directory
800 subprocess.check_call([
801 pyexe, "-Sc", ";".join([
802 "import os",
803 "p = os.add_dll_directory({!r})".format(
804 os.path.dirname(depname)),
805 "import _sqlite3",
806 "p.close"
807 ])],
808 stderr=subprocess.STDOUT,
809 env=env,
810 cwd=os.path.dirname(pyexe))
811
812 # Test 2: import with DLL adjacent to PYD
813 shutil.copy(depname, tmp2)
814 subprocess.check_call([pyexe, "-Sc", "import _sqlite3"],
815 stderr=subprocess.STDOUT,
816 env=env,
817 cwd=os.path.dirname(pyexe))
818
819 def test_issue105979(self):
820 # this used to crash

Callers

nothing calls this directly

Calls 11

temp_dirMethod · 0.80
escapeMethod · 0.80
find_specMethod · 0.45
joinMethod · 0.45
dirnameMethod · 0.45
formatMethod · 0.45
mkdirMethod · 0.45
basenameMethod · 0.45
copyMethod · 0.45
globMethod · 0.45
upperMethod · 0.45

Tested by

no test coverage detected