Skip to content

Commit

Permalink
Add SupportErrorInfoTest to test_comserver. (#818)
Browse files Browse the repository at this point in the history
* Add `SupportErrorInfoTest` to `test_comserver`.

* Add type hints to `errorinfo.py` for supressing type errors in `test_comserver`.
  • Loading branch information
junkmd authored Feb 24, 2025
1 parent 2e5d410 commit d9d132d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
7 changes: 7 additions & 0 deletions comtypes/errorinfo.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import sys
from ctypes import POINTER, OleDLL, byref, c_wchar_p
from ctypes.wintypes import DWORD, ULONG
from typing import TYPE_CHECKING

from comtypes import BSTR, COMMETHOD, GUID, HRESULT, IUnknown
from comtypes.hresult import *

if TYPE_CHECKING:
from comtypes import hints # type: ignore

LPCOLESTR = c_wchar_p


Expand Down Expand Up @@ -43,6 +47,9 @@ class ISupportErrorInfo(IUnknown):
[], HRESULT, "InterfaceSupportsErrorInfo", (["in"], POINTER(GUID), "riid")
)
]
if TYPE_CHECKING:

def InterfaceSupportsErrorInfo(self, riid: GUID) -> hints.Hresult: ...


################################################################
Expand Down
22 changes: 21 additions & 1 deletion comtypes/test/test_comserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import comtypes.server
import comtypes.test.TestComServer
from comtypes import BSTR
from comtypes import BSTR, errorinfo, hresult, shelllink
from comtypes.automation import VARIANT, _midlSAFEARRAY
from comtypes.client import CreateObject, GetActiveObject
from comtypes.server.register import register, unregister
Expand Down Expand Up @@ -201,6 +201,26 @@ def test_activeobj_strong_registration(self):
self._doit(weak=False)


class SupportErrorInfoTest(unittest.TestCase):
def create_object(self):
return CreateObject(
comtypes.test.TestComServer.TestComServer,
interface=comtypes.test.TestComServer.ITestComServer,
)

def test_returns_S_OK(self):
psei = self.create_object().QueryInterface(errorinfo.ISupportErrorInfo)
iid = comtypes.test.TestComServer.ITestComServer._iid_
hr = psei.InterfaceSupportsErrorInfo(iid)
self.assertEqual(hr, hresult.S_OK)

def test_returns_S_FALSE(self):
psei = self.create_object().QueryInterface(errorinfo.ISupportErrorInfo)
iid = shelllink.IShellLinkW._iid_
hr = psei.InterfaceSupportsErrorInfo(iid)
self.assertEqual(hr, hresult.S_FALSE)


class VariantTest(unittest.TestCase):
def test_UDT(self):
from comtypes.gen.TestComServerLib import MYCOLOR
Expand Down

0 comments on commit d9d132d

Please sign in to comment.