Skip to content

Commit bcb3c38

Browse files
committed
bpo-36085: Change ctypes test to use full paths instead of cwd
1 parent e653d4d commit bcb3c38

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Lib/ctypes/test/test_loading.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def test_1703286_B(self):
118118
@unittest.skipUnless(os.name == "nt",
119119
'test specific to Windows')
120120
def test_load_dll_with_flags(self):
121+
import nt
121122
_sqlite3 = test.support.import_module("_sqlite3")
122123
src = _sqlite3.__file__
123124
if src.lower().endswith("_d.pyd"):
@@ -139,17 +140,25 @@ def should_pass(command):
139140
with self.subTest(command):
140141
subprocess.check_output(
141142
[sys.executable, "-c",
142-
"from ctypes import *; import nt;" + command],
143-
cwd=tmp
143+
"; ".join([
144+
"import nt",
145+
"nt.chdir({!r})".format(tmp),
146+
"from ctypes import *",
147+
command
148+
])]
144149
)
145150

146151
def should_fail(command):
147152
with self.subTest(command):
148153
with self.assertRaises(subprocess.CalledProcessError):
149154
subprocess.check_output(
150155
[sys.executable, "-c",
151-
"from ctypes import *; import nt;" + command],
152-
cwd=tmp, stderr=subprocess.STDOUT,
156+
"; ".join([
157+
"import nt",
158+
"nt.chdir({!r})".format(tmp),
159+
"from ctypes import *",
160+
command
161+
])], stderr=subprocess.STDOUT,
153162
)
154163

155164
# Default load should not find this in CWD
@@ -162,11 +171,11 @@ def should_fail(command):
162171
should_pass("WinDLL('_sqlite3.dll', winmode=0)")
163172

164173
# Full path load without DLL_LOAD_DIR shouldn't find dependency
165-
should_fail("WinDLL(nt._getfullpathname('_sqlite3.dll'), " +
174+
should_fail("WinDLL({!r}, ".format(target) +
166175
"winmode=nt._LOAD_LIBRARY_SEARCH_SYSTEM32)")
167176

168177
# Full path load with DLL_LOAD_DIR should succeed
169-
should_pass("WinDLL(nt._getfullpathname('_sqlite3.dll'), " +
178+
should_pass("WinDLL({!r}, ".format(target) +
170179
"winmode=nt._LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR)")
171180

172181
# User-specified directory should succeed

0 commit comments

Comments
 (0)