mirror of
https://github.com/hakril/PythonForWindows
synced 2026-06-08 14:31:45 +00:00
60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
import os.path
|
|
import pytest
|
|
|
|
import windows
|
|
import windows.generated_def as gdef
|
|
|
|
is_process_32_bits = windows.current_process.bitness == 32
|
|
is_process_64_bits = windows.current_process.bitness == 64
|
|
is_process_syswow = windows.current_process.is_wow_64
|
|
|
|
is_windows_32_bits = windows.system.bitness == 32
|
|
is_windows_64_bits = windows.system.bitness == 64
|
|
|
|
is_windows_10 = (windows.system.version[0] == 10)
|
|
|
|
is_admin = windows.current_process.token.is_elevated
|
|
|
|
windows_32bit_only = pytest.mark.skipif(not is_windows_32_bits, reason="Test for 32bits Kernel only")
|
|
windows_64bit_only = pytest.mark.skipif(not is_windows_64_bits, reason="Test for 64bits Kernel only")
|
|
|
|
process_32bit_only = pytest.mark.skipif(not is_process_32_bits, reason="Test for 32bits process only")
|
|
process_64bit_only = pytest.mark.skipif(not is_process_64_bits, reason="Test for 64bits process only")
|
|
process_syswow_only = pytest.mark.skipif(not is_process_syswow, reason="Test for syswow process only")
|
|
require_admin = pytest.mark.skipif(not is_admin, reason="Test must be launched as admin")
|
|
|
|
|
|
check_for_gc_garbage = pytest.mark.usefixtures("check_for_gc_garbage")
|
|
check_for_handle_leak = pytest.mark.usefixtures("check_for_handle_leak")
|
|
|
|
test_binary_name = "notepad.exe"
|
|
DEFAULT_CREATION_FLAGS = gdef.CREATE_NEW_CONSOLE
|
|
|
|
|
|
# Python Injection check fixture
|
|
|
|
python_is_installed = {
|
|
windows.current_process.bitness: True
|
|
}
|
|
|
|
if windows.current_process.bitness == 32:
|
|
with windows.utils.DisableWow64FsRedirection():
|
|
python_is_installed[64] = os.path.exists(r"C:\Windows\system32\python27.dll")
|
|
|
|
if windows.current_process.bitness == 64:
|
|
python_is_installed[32] = os.path.exists(r"C:\Windows\SysWOW64\python27.dll")
|
|
|
|
@pytest.fixture
|
|
def check_injected_python_installed(request):
|
|
# Find the process parameter
|
|
procparams = [argname for argname in request.funcargnames if argname.startswith("proc")]
|
|
if len(procparams) != 1:
|
|
raise ValueError("Could not find the fixture name of the injected python")
|
|
procparam = procparams[0]
|
|
proc = request.getfuncargvalue(procparam)
|
|
if not python_is_installed[proc.bitness]:
|
|
pytest.skip("Python {0}b not installed -> skipping test with python injection into {0}b process".format(proc.bitness))
|
|
return None
|
|
|
|
|
|
python_injection = pytest.mark.usefixtures("check_injected_python_installed") |