# HG changeset patch # User Risto Kankkunen # Date 1248883273 -10800 # Node ID 37718f514acb3d1879897a701a376628b668eee5 # Parent a42fb4f1716ae713c8f846edb0621de4499b283e No os.kill() in Windows, use ctypes to call Win32 TerminateProcess() diff --git a/tests/test_push_command.py b/tests/test_push_command.py --- a/tests/test_push_command.py +++ b/tests/test_push_command.py @@ -106,7 +106,8 @@ class PushTests(test_util.TestBase): self.assertNotEqual('an_author', tip.user()) self.assertEqual('None', tip.user().rsplit('@', 1)[0]) finally: - os.kill(self.svnserve_pid, 9) + # TODO: use svnserve.kill() in Python >2.5 + test_util.kill_process(svnserve) def test_push_to_default(self, commit=True): repo = self.repo diff --git a/tests/test_util.py b/tests/test_util.py --- 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',