mock_win32process.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. This is a mock win32process module.
  5. The purpose of this module is mock process creation for the PID test.
  6. CreateProcess(...) will spawn a process, and always return a PID of 42.
  7. """
  8. import win32process
  9. GetExitCodeProcess = win32process.GetExitCodeProcess
  10. STARTUPINFO = win32process.STARTUPINFO
  11. STARTF_USESTDHANDLES = win32process.STARTF_USESTDHANDLES
  12. def CreateProcess(appName,
  13. cmdline,
  14. procSecurity,
  15. threadSecurity,
  16. inheritHandles,
  17. newEnvironment,
  18. env,
  19. workingDir,
  20. startupInfo):
  21. """
  22. This function mocks the generated pid aspect of the win32.CreateProcess
  23. function.
  24. - the true win32process.CreateProcess is called
  25. - return values are harvested in a tuple.
  26. - all return values from createProcess are passed back to the calling
  27. function except for the pid, the returned pid is hardcoded to 42
  28. """
  29. hProcess, hThread, dwPid, dwTid = win32process.CreateProcess(
  30. appName,
  31. cmdline,
  32. procSecurity,
  33. threadSecurity,
  34. inheritHandles,
  35. newEnvironment,
  36. env,
  37. workingDir,
  38. startupInfo)
  39. dwPid = 42
  40. return (hProcess, hThread, dwPid, dwTid)