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") 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 diff --git a/comtypes/test/test_wmi.py b/comtypes/test/test_variant_outparam.py similarity index 65% rename from comtypes/test/test_wmi.py rename to comtypes/test/test_variant_outparam.py index cfa6c5683..5cf360a54 100644 --- a/comtypes/test/test_wmi.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 @@ -7,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") @@ -22,11 +23,10 @@ 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) - # .Value is a property with "[out] POINTER(VARIANT)" parameter. item: "WbemScripting.ISWbemObject" a = item.Properties_["Caption"].Value b = item.Properties_.Item("Caption").Value @@ -36,11 +36,28 @@ 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" 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)