Skip to content

Commit 89e5b79

Browse files
committed
test: Expect AssertionError for IMAPI2 custom event interface.
Add `Test_IMAPI2FS` to `test_eventinterface.py` to verify that `GetEvents` raises an `AssertionError` when used with the `MsftFileSystemImage` object. The default event interface `DFileSystemImageEvents` is a custom `TKIND_INTERFACE` that inherits from `IDispatch`, but is neither a dual nor pure dispatch interface. Its v-table methods, as generated from type info, lack the `dispid` attributes that `GetEvents` requires. This test confirms the expected failure.
1 parent 720cf74 commit 89e5b79

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

comtypes/test/test_eventinterface.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import gc
2+
import tempfile
23
import time
34
import unittest as ut
45
from ctypes import HRESULT, byref
56
from ctypes.wintypes import MSG
7+
from pathlib import Path
68

79
from comtypes import COMMETHOD, GUID, IUnknown
810
from comtypes.automation import DISPID
@@ -122,5 +124,34 @@ def test_retrieved_outgoing_iid_is_guid_null(self):
122124
GetEvents(doc, sink)
123125

124126

127+
class Test_IMAPI2FS(ut.TestCase):
128+
def setUp(self):
129+
CLSID_MsftFileSystemImage = GUID("{2C941FC5-975B-59BE-A960-9A2A262853A5}")
130+
self.image = CreateObject(CLSID_MsftFileSystemImage)
131+
self.image.FileSystemsToCreate = 1 # FsiFileSystemISO9660
132+
td = tempfile.TemporaryDirectory()
133+
self.tmp_dir = Path(td.name)
134+
self.addCleanup(td.cleanup)
135+
136+
def tearDown(self):
137+
del self.image
138+
# Force garbage collection and wait slightly to ensure COM resources
139+
# are released properly between tests.
140+
gc.collect()
141+
time.sleep(2)
142+
143+
def test(self):
144+
sink = object()
145+
# The default event interface for IMAPI2's FileSystemImage is
146+
# `DFileSystemImageEvents`. Although it inherits from `IDispatch`,
147+
# it is a custom interface (`TKIND_INTERFACE`), not a dual or pure
148+
# dispatch interface (`TKIND_DISPATCH`).
149+
# Its methods are v-table bound, and the interface definition
150+
# that comtypes generates from the type info lacks the `dispid`
151+
# attributes that `GetEvents` requires.
152+
with self.assertRaises(AssertionError):
153+
GetEvents(self.image, sink)
154+
155+
125156
if __name__ == "__main__":
126157
ut.main()

0 commit comments

Comments
 (0)