Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -2337,19 +2337,10 @@ def test_unlink_removes_junction(self):

@unittest.skipUnless(sys.platform == "win32", "Win32 specific tests")
class Win32NtTests(unittest.TestCase):
def setUp(self):
from test import support
self.nt = support.import_module('nt')
pass

def tearDown(self):
pass

def test_getfinalpathname_handles(self):
try:
import ctypes, ctypes.wintypes
except ImportError:
raise unittest.SkipTest('ctypes module is required for this test')
nt = support.import_module('nt')
ctypes = support.import_module('ctypes')
import ctypes.wintypes

kernel = ctypes.WinDLL('Kernel32.dll', use_last_error=True)
kernel.GetCurrentProcess.restype = ctypes.wintypes.HANDLE
Expand All @@ -2368,21 +2359,23 @@ def test_getfinalpathname_handles(self):
before_count = handle_count.value

# The first two test the error path, __file__ tests the success path
filenames = [ r'\\?\C:',
r'\\?\NUL',
r'\\?\CONIN',
__file__ ]
filenames = [
r'\\?\C:',
r'\\?\NUL',
r'\\?\CONIN',
__file__,
]

for i in range(10):
for _ in range(10):
for name in filenames:
try:
tmp = self.nt._getfinalpathname(name)
except:
nt._getfinalpathname(name)
except Exception:
# Failure is expected
pass
try:
tmp = os.stat(name)
except:
os.stat(name)
except Exception:
pass

ok = kernel.GetProcessHandleCount(hproc, ctypes.byref(handle_count))
Expand Down