Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ jobs:
run: python .github\workflows\install-vs-components.py

- name: Build and register the PyCOMTest server dll
run: |
msbuild com/TestSources/PyCOMTest/PyCOMTest.sln -property:Configuration=Release
regsvr32 com/TestSources/PyCOMTest/x64/Release/PyCOMTest.dll
# Pass Silent flag to regsvr32 to avoid hanging on confirmation window
run: com/TestSources/PyCOMTest/buildAndRegister.bat /s
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this likely to work even if the build or regsvr fails?

Copy link
Collaborator Author

@Avasam Avasam Apr 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step may pass. But the test would still fail if the registration fails.

I added this param because otherwise the step hangs forever, with the script waiting for confirmation to finish.

Suggested change
run: com/TestSources/PyCOMTest/buildAndRegister.bat /s
# Pass Silent flag to regsvr32 to avoid hanging on confirmation window
run: com/TestSources/PyCOMTest/buildAndRegister.bat /s

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the /s, but don't really see the benefit of the new .bat file, especially given it might be misleading when the build or registration fails.

Copy link
Collaborator Author

@Avasam Avasam Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just meant as a helper script to build and register the required project for testing. And avoid duplication.
I could add the two lines instruction to com/win32com/test/readme.txt instead.

The helper message when the test finds the server isn't registered (what's assigned to importMsg) should probably direct the user to that readme explicitly.

When we were debugging PyComTests is took me a while to find it even existed.


- name: Run tests
# Run the tests directly from the source dir so support files (eg, .wav files etc)
Expand Down
2 changes: 2 additions & 0 deletions com/TestSources/PyCOMTest/buildAndRegister.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
msbuild %~dp0\PyCOMTest.sln -property:Configuration=Release
regsvr32 %~dp0\x64\Release\PyCOMTest.dll %*
3 changes: 2 additions & 1 deletion com/win32com/test/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ In general, this should just run the best it can, utilizing what is available
on the machine. It is likely some tests will refuse to run due to objects not
being locally available - this is normal.

The win32com source tree has source code to a C++ and VB component used purely
The `com/TestSources/` directory has source code to a C++ and VB component used purely
for testing. You may like to build and register these, particularly if you
are doing anything related to argument/result handling.
You can run `com/TestSources/PyCOMTest/buildAndRegister.bat` directly.
24 changes: 11 additions & 13 deletions com/win32com/test/testPyComTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,44 @@
import time

import pythoncom
import pywintypes
import win32com
import win32com.client.connect
import win32com.test.util
import win32timezone
import winerror
from win32api import CloseHandle, GetCurrentProcessId, OpenProcess
from win32com import universal
from win32com.client import (
VARIANT,
CastTo,
DispatchBaseClass,
Record,
constants,
gencache,
register_record_class,
)
from win32process import GetProcessMemoryInfo

importMsg = "**** PyCOMTest is not installed ***\n PyCOMTest is a Python test specific COM client and server.\n It is likely this server is not installed on this machine\n To install the server, you must get the win32com sources\n and build it using MS Visual C++"

# This test uses a Python implemented COM server - ensure correctly registered.
win32com.test.util.RegisterPythonServer(
os.path.join(os.path.dirname(__file__), "..", "servers", "test_pycomtest.py"),
"Python.Test.PyCOMTest",
)

from win32com.client import gencache

try:
gencache.EnsureModule(
"{6BCDCB60-5605-11D0-AE5F-CADD4C000000}", 0, 1, 1, bForDemand=False
)
except pythoncom.com_error:
print("The PyCOMTest module can not be located or generated.")
print(importMsg)
raise RuntimeError(importMsg)
except pythoncom.com_error as error:
importMsg = """*** PyCOMTest is not installed ***
PyCOMTest is a Python test specific COM client and server.
It is likely this server is not installed on this machine
To install the server, you must get the win32com sources
and build it using MS Visual C++"""
print(f"The PyCOMTest module can not be located or generated.\n{importMsg}\n")
raise RuntimeError(importMsg) from error

# We had a bg where RegisterInterfaces would fail if gencache had
# already been run - exercise that here
from win32com import universal

universal.RegisterInterfaces("{6BCDCB60-5605-11D0-AE5F-CADD4C000000}", 0, 1, 1)

verbose = 0
Expand All @@ -75,7 +73,7 @@ class TestStruct2(pythoncom.com_record):
GUID = "{78F0EA07-B7CF-42EA-A251-A4C6269F76AF}"


# We don't need to stick with the struct name in the TypeLibrry for the subclass name.
# We don't need to stick with the struct name in the TypeLibrary for the subclass name.
# The following class has the same GUID as TestStruct2 from the TypeLibrary.
class ArrayOfStructsTestStruct(pythoncom.com_record):
__slots__ = ()
Expand Down