Skip to content

Commit

Permalink
Add test_comobject(part 1). (enthought#709)
Browse files Browse the repository at this point in the history
* Add `test_comobject.py` and first test cases.

* Add `TYPE_CHECKING` only `GetTypeInfoCount` to `IDispatch`.
  • Loading branch information
junkmd authored Dec 19, 2024
1 parent 9d716c7 commit 2617ff0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions comtypes/automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,10 @@ class IDispatch(IUnknown):
),
]

if TYPE_CHECKING:

def GetTypeInfoCount(self) -> int: ...

def GetTypeInfo(self, index: int, lcid: int = 0) -> "hints.ITypeInfo":
"""Return type information. Index 0 specifies typeinfo for IDispatch"""
import comtypes.typeinfo
Expand Down
42 changes: 42 additions & 0 deletions comtypes/test/test_comobject.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import unittest as ut

import comtypes
import comtypes.client
from comtypes import IUnknown

comtypes.client.GetModule("UIAutomationCore.dll")
comtypes.client.GetModule("scrrun.dll")
from comtypes.gen import Scripting as scrrun
from comtypes.gen import UIAutomationClient as uiac


class Test_QueryInterface(ut.TestCase):
def test_custom_interface(self):
iuia = uiac.CUIAutomation().QueryInterface(uiac.IUIAutomation)
self.assertTrue(bool(iuia))
self.assertEqual(iuia.AddRef(), 2)
punk = iuia.QueryInterface(IUnknown)
self.assertEqual(iuia.AddRef(), 4)
self.assertEqual(punk.AddRef(), 5)
self.assertEqual(iuia.Release(), 4)
del iuia
self.assertEqual(punk.Release(), 2)
self.assertEqual(punk.Release(), 1)

def test_dispatch_interface(self):
dic = scrrun.Dictionary().QueryInterface(scrrun.IDictionary)
self.assertTrue(bool(dic))
self.assertEqual(dic.GetTypeInfoCount(), 1)
self.assertEqual(
dic.GetTypeInfo(0).GetTypeAttr().guid,
scrrun.IDictionary._iid_,
)
self.assertEqual(dic.GetIDsOfNames("Add"), [1])


class Test_IPersist_GetClassID(ut.TestCase):
def test(self):
self.assertEqual(
uiac.CUIAutomation().IPersist_GetClassID(),
uiac.CUIAutomation._reg_clsid_,
)

0 comments on commit 2617ff0

Please sign in to comment.