@@ -2325,6 +2325,62 @@ def test_unlink_removes_junction(self):
23252325 os .unlink (self .junction )
23262326 self .assertFalse (os .path .exists (self .junction ))
23272327
2328+ @unittest .skipUnless (sys .platform == "win32" , "Win32 specific tests" )
2329+ class Win32NtTests (unittest .TestCase ):
2330+ def setUp (self ):
2331+ from test import support
2332+ self .nt = support .import_module ('nt' )
2333+ pass
2334+
2335+ def tearDown (self ):
2336+ pass
2337+
2338+ def test_getfinalpathname_handles (self ):
2339+ try :
2340+ import ctypes , ctypes .wintypes
2341+ except ImportError :
2342+ raise unittest .SkipTest ('ctypes module is required for this test' )
2343+
2344+ kernel = ctypes .WinDLL ('Kernel32.dll' , use_last_error = True )
2345+ kernel .GetCurrentProcess .restype = ctypes .wintypes .HANDLE
2346+
2347+ kernel .GetProcessHandleCount .restype = ctypes .wintypes .BOOL
2348+ kernel .GetProcessHandleCount .argtypes = (ctypes .wintypes .HANDLE ,
2349+ ctypes .wintypes .LPDWORD )
2350+
2351+ # This is a pseudo-handle that doesn't need to be closed
2352+ hproc = kernel .GetCurrentProcess ()
2353+
2354+ handle_count = ctypes .wintypes .DWORD ()
2355+ ok = kernel .GetProcessHandleCount (hproc , ctypes .byref (handle_count ))
2356+ self .assertEqual (1 , ok )
2357+
2358+ before_count = handle_count .value
2359+
2360+ # The first two test the error path, __file__ tests the success path
2361+ filenames = [ r'\\?\C:' ,
2362+ r'\\?\NUL' ,
2363+ r'\\?\CONIN' ,
2364+ __file__ ]
2365+
2366+ for i in range (10 ):
2367+ for name in filenames :
2368+ try :
2369+ tmp = self .nt ._getfinalpathname (name )
2370+ except :
2371+ # Failure is expected
2372+ pass
2373+ try :
2374+ tmp = os .stat (name )
2375+ except :
2376+ pass
2377+
2378+ ok = kernel .GetProcessHandleCount (hproc , ctypes .byref (handle_count ))
2379+ self .assertEqual (1 , ok )
2380+
2381+ handle_delta = handle_count .value - before_count
2382+
2383+ self .assertEqual (0 , handle_delta )
23282384
23292385@support .skip_unless_symlink
23302386class NonLocalSymlinkTests (unittest .TestCase ):
0 commit comments