From cf4deb5762f6a3a516fc38de8ebbec6509c2dd59 Mon Sep 17 00:00:00 2001 From: junkmd Date: Fri, 26 Dec 2025 23:08:20 +0900 Subject: [PATCH 1/5] test: Rename the test file to be testing-oriented rather than COM type library-specific. --- comtypes/test/{test_wmi.py => test_variant_outparam.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename comtypes/test/{test_wmi.py => test_variant_outparam.py} (100%) diff --git a/comtypes/test/test_wmi.py b/comtypes/test/test_variant_outparam.py similarity index 100% rename from comtypes/test/test_wmi.py rename to comtypes/test/test_variant_outparam.py From 9699a09c88b0615a08557845fff34a88fe711c23 Mon Sep 17 00:00:00 2001 From: junkmd Date: Fri, 26 Dec 2025 23:08:20 +0900 Subject: [PATCH 2/5] test: Verify `[out]` parameter types for COM methods/properties. This commit enhances tests using WMI. It ensures that `ISWbemProperty.Value` behaves correctly as a property with an `[out] POINTER(VARIANT)` parameter by: - Retrieving type information using `GetTypeInfo` and `GetRefTypeInfo`. - Inspecting `wParamFlags` to confirm `PARAMFLAG_FOUT | PARAMFLAG_FRETVAL`. - Validating the `vt` of the parameter as `VT_PTR` to `VT_VARIANT`. --- comtypes/test/test_variant_outparam.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/comtypes/test/test_variant_outparam.py b/comtypes/test/test_variant_outparam.py index cfa6c5683..6a3256fcf 100644 --- a/comtypes/test/test_variant_outparam.py +++ b/comtypes/test/test_variant_outparam.py @@ -1,5 +1,6 @@ import unittest as ut +from comtypes import automation, typeinfo from comtypes.client import CoGetObject @@ -26,7 +27,6 @@ def test_wmi(self): for item in disks: # obj[index] is forwarded to obj.Item(index) - # .Value is a property with "[out] POINTER(VARIANT)" parameter. item: "WbemScripting.ISWbemObject" a = item.Properties_["Caption"].Value b = item.Properties_.Item("Caption").Value @@ -36,6 +36,24 @@ def test_wmi(self): self.assertTrue(isinstance(a, str)) self.assertTrue(isinstance(b, str)) self.assertTrue(isinstance(c, str)) + # Verify parameter types from the interface type. + dispti = item.Properties_["Caption"].GetTypeInfo(0) + # GetRefTypeOfImplType(-1) returns the custom portion + # of a dispinterface, if it is dual + # See https://learn.microsoft.com/en-us/windows/win32/api/oaidl/nf-oaidl-itypeinfo-getreftypeofimpltype#remarks + dualti = dispti.GetRefTypeInfo(dispti.GetRefTypeOfImplType(-1)) + # .Value is a property with "[out] POINTER(VARIANT)" parameter. + fd = dualti.GetFuncDesc(0) + names = dualti.GetNames(fd.memid, fd.cParams + 1) + self.assertEqual(names, ["Value", "varValue"]) + edesc = fd.lprgelemdescParam[0] + self.assertEqual( + edesc._.paramdesc.wParamFlags, + typeinfo.PARAMFLAG_FOUT | typeinfo.PARAMFLAG_FRETVAL, + ) + tdesc = edesc.tdesc + self.assertEqual(tdesc.vt, automation.VT_PTR) + self.assertEqual(tdesc._.lptdesc[0].vt, automation.VT_VARIANT) result = {} for prop in item.Properties_: prop: "WbemScripting.ISWbemProperty" From 83d2daf0ee3a47a4feaefa54bdb9e6188297e277 Mon Sep 17 00:00:00 2001 From: junkmd Date: Fri, 26 Dec 2025 23:08:21 +0900 Subject: [PATCH 3/5] test: Refactor WMI-related tests for clarity and robustness Rename `Test` class to `TestWMI` for better clarity. Replace direct attribute access of `WbemScripting.wbemPrivilegeCreateToken` with `hasattr` check to enhance test robustness. Remove redundant `prop.Value` access as it is already assigned to `result`. --- comtypes/test/test_variant_outparam.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/comtypes/test/test_variant_outparam.py b/comtypes/test/test_variant_outparam.py index 6a3256fcf..5cf360a54 100644 --- a/comtypes/test/test_variant_outparam.py +++ b/comtypes/test/test_variant_outparam.py @@ -8,7 +8,7 @@ # Some methods/properties have "[out] POINTER(VARIANT)" parameters. # This test checks that these parameters are returned as strings: # that's what VARIANT.__ctypes_from_outparam__ does. -class Test(ut.TestCase): +class TestWMI(ut.TestCase): def test_wmi(self): wmi: "WbemScripting.ISWbemServices" = CoGetObject("winmgmts:") disks = wmi.InstancesOf("Win32_LogicalDisk") @@ -23,7 +23,7 @@ def test_wmi(self): # actual typelib is available or not. XXX from comtypes.gen import WbemScripting - WbemScripting.wbemPrivilegeCreateToken + self.assertTrue(hasattr(WbemScripting, "wbemPrivilegeCreateToken")) for item in disks: # obj[index] is forwarded to obj.Item(index) @@ -58,7 +58,6 @@ def test_wmi(self): for prop in item.Properties_: prop: "WbemScripting.ISWbemProperty" self.assertTrue(isinstance(prop.Name, str)) - prop.Value result[prop.Name] = prop.Value # print "\t", (prop.Name, prop.Value) self.assertEqual(len(item.Properties_), item.Properties_.Count) From cd3ad9c7fbd81c4f5d5ea14d5ccd60f59a302a47 Mon Sep 17 00:00:00 2001 From: junkmd Date: Fri, 26 Dec 2025 23:08:21 +0900 Subject: [PATCH 4/5] test: Rename `test_msi.py` to `test_puredispatch.py`. The test file `test_msi.py` has been renamed to `test_puredispatch.py` to better reflect its content and purpose. --- comtypes/test/{test_msi.py => test_puredispatch.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename comtypes/test/{test_msi.py => test_puredispatch.py} (100%) diff --git a/comtypes/test/test_msi.py b/comtypes/test/test_puredispatch.py similarity index 100% rename from comtypes/test/test_msi.py rename to comtypes/test/test_puredispatch.py From c6bee286277e4a720d80c980cb8f5f469029f494 Mon Sep 17 00:00:00 2001 From: junkmd Date: Fri, 26 Dec 2025 23:08:21 +0900 Subject: [PATCH 5/5] test: Refactor skipping mechanism in `test_eventinterface.py`. Move the test skipping logic from module-level `setUpModule` to individual `ut.skip` decorators for test methods. --- comtypes/test/test_eventinterface.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/comtypes/test/test_eventinterface.py b/comtypes/test/test_eventinterface.py index fa81561fe..f2b9d3039 100644 --- a/comtypes/test/test_eventinterface.py +++ b/comtypes/test/test_eventinterface.py @@ -4,15 +4,11 @@ from comtypes.client import CreateObject, GetEvents - -def setUpModule(): - # The primary goal is to verify how `GetEvents` behaves when the - # `interface` argument is explicitly specified versus when it is omitted, - # using an object that has multiple outgoing event interfaces. - raise ut.SkipTest( - "External test dependencies like this seem bad. Find a different built-in " - "win32 API to use." - ) +# FIXME: External test dependencies like this seem bad. Find a different +# built-in win32 API to use. +# The primary goal is to verify how `GetEvents` behaves when the +# `interface` argument is explicitly specified versus when it is omitted, +# using an object that has multiple outgoing event interfaces. class EventSink: @@ -93,6 +89,10 @@ def tearDown(self): time.sleep(2) + @ut.skip( + "External test dependencies like this seem bad. Find a different built-in " + "win32 API to use." + ) def test_default_eventinterface(self): sink = EventSink() ie = CreateObject("InternetExplorer.Application") @@ -121,6 +121,10 @@ def test_default_eventinterface(self): del ie del conn + @ut.skip( + "External test dependencies like this seem bad. Find a different built-in " + "win32 API to use." + ) def test_nondefault_eventinterface(self): sink = EventSink() ie = CreateObject("InternetExplorer.Application")