Mercurial > hgsubversion
diff tests/test_util.py @ 483:37718f514acb
No os.kill() in Windows, use ctypes to call Win32 TerminateProcess()
author | Risto Kankkunen <risto.kankkunen@iki.fi> |
---|---|
date | Wed, 29 Jul 2009 19:01:13 +0300 |
parents | 83fcb1cf6d8f |
children | 5607e81ba616 |
line wrap: on
line diff
--- a/tests/test_util.py +++ b/tests/test_util.py @@ -26,6 +26,50 @@ import sys # stderr." canCloseFds='win32' not in sys.platform +if not 'win32' in sys.platform: + def kill_process(popen_obj): + os.kill(popen_obj.pid, 9) +else: + import ctypes + from ctypes.wintypes import BOOL, DWORD, HANDLE, UINT + + def win_status_check(result, func, args): + if result == 0: + raise ctypes.WinError() + return args + + def WINAPI(returns, func, *params): + assert len(params) % 2 == 0 + + func.argtypes = tuple(params[0::2]) + func.resvalue = returns + func.errcheck = win_status_check + + return func + + # dwDesiredAccess + PROCESS_TERMINATE = 0x0001 + + OpenProcess = WINAPI(HANDLE, ctypes.windll.kernel32.OpenProcess, + DWORD, 'dwDesiredAccess', + BOOL, 'bInheritHandle', + DWORD, 'dwProcessId', + ) + + CloseHandle = WINAPI(BOOL, ctypes.windll.kernel32.CloseHandle, + HANDLE, 'hObject' + ) + + TerminateProcess = WINAPI(BOOL, ctypes.windll.kernel32.TerminateProcess, + HANDLE, 'hProcess', + UINT, 'uExitCode' + ) + + def kill_process(popen_obj): + phnd = OpenProcess(PROCESS_TERMINATE, False, popen_obj.pid) + TerminateProcess(phnd, 1) + CloseHandle(phnd) + # Fixtures that need to be pulled at a subdirectory of the repo path subdir = {'truncatedhistory.svndump': '/project2', 'fetch_missing_files_subdir.svndump': '/foo',