From e7dd0b7205608cd764f83b83639f0fd83cfc34d8 Mon Sep 17 00:00:00 2001 From: junkmd Date: Sun, 29 Mar 2026 15:52:00 +0900 Subject: [PATCH 1/6] refactor: Move `CreateTypeLib` import to top-level in `test_basic.py`. Relocate `CreateTypeLib` from `BasicTest.test_guid` to the top level of `test/test_basic.py` to follow project conventions. --- comtypes/test/test_basic.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/comtypes/test/test_basic.py b/comtypes/test/test_basic.py index 6c702123..edb37cdd 100644 --- a/comtypes/test/test_basic.py +++ b/comtypes/test/test_basic.py @@ -3,7 +3,7 @@ from ctypes import HRESULT, POINTER, byref from comtypes import GUID, STDMETHOD, IUnknown -from comtypes.typeinfo import ICreateTypeLib2, _CreateTypeLib2 +from comtypes.typeinfo import CreateTypeLib, ICreateTypeLib2, _CreateTypeLib2 # XXX leaks references! @@ -115,8 +115,6 @@ def test_identity(self): self.assertEqual(a, b) self.assertEqual(hash(a), hash(b)) - from comtypes.typeinfo import CreateTypeLib - # we do not save the lib, so no file will be created. # these should NOT be identical a = CreateTypeLib("blahblah") From 1900392b933c26411dbf8496a6a2d5d1a3378f5e Mon Sep 17 00:00:00 2001 From: junkmd Date: Sun, 29 Mar 2026 15:52:00 +0900 Subject: [PATCH 2/6] refactor: Use `SYS_WIN32` constant in `test_basic.py`. Replace magic number `1` with `SYS_WIN32` in `_CreateTypeLib2` calls. --- comtypes/test/test_basic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/comtypes/test/test_basic.py b/comtypes/test/test_basic.py index edb37cdd..d9d7d2fe 100644 --- a/comtypes/test/test_basic.py +++ b/comtypes/test/test_basic.py @@ -3,7 +3,7 @@ from ctypes import HRESULT, POINTER, byref from comtypes import GUID, STDMETHOD, IUnknown -from comtypes.typeinfo import CreateTypeLib, ICreateTypeLib2, _CreateTypeLib2 +from comtypes.typeinfo import SYS_WIN32, CreateTypeLib, ICreateTypeLib2, _CreateTypeLib2 # XXX leaks references! @@ -25,7 +25,7 @@ def test_refcounts(self): # Since all COM interfaces derive from IUnknown and have the same reference counting behavior, any interface # — whether ICreateTypeLib2 or otherwise — could be used for this test. p = POINTER(ICreateTypeLib2)() - _CreateTypeLib2(1, "blabla", byref(p)) + _CreateTypeLib2(SYS_WIN32, "blabla", byref(p)) # initial refcount is 2 for i in range(2, 10): self.assertEqual(p.AddRef(), i) @@ -36,7 +36,7 @@ def test_qi(self): # Since all COM interfaces derive from IUnknown and have the same QueryInterface behavior, any interface # — whether ICreateTypeLib2 or otherwise — could be used for this test. p = POINTER(ICreateTypeLib2)() - _CreateTypeLib2(1, "blabla", byref(p)) + _CreateTypeLib2(SYS_WIN32, "blabla", byref(p)) self.assertEqual(p.AddRef(), 2) self.assertEqual(p.Release(), 1) From e1c93f16aeb879f8d6a97e1e169886e0cedff580 Mon Sep 17 00:00:00 2001 From: junkmd Date: Sun, 29 Mar 2026 15:52:00 +0900 Subject: [PATCH 3/6] refactor: Use public `CreateTypeLib` in `test_basic.py`. Replace internal `_CreateTypeLib2` calls with public `CreateTypeLib`. The primary goal of these tests is to verify the basic mechanics of COM pointers, such as reference counting and `QueryInterface` behavior, which are common to all COM interfaces. Testing low-level, private functions like `_CreateTypeLib2` is not the objective here. --- comtypes/test/test_basic.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/comtypes/test/test_basic.py b/comtypes/test/test_basic.py index d9d7d2fe..9a7cd830 100644 --- a/comtypes/test/test_basic.py +++ b/comtypes/test/test_basic.py @@ -1,9 +1,9 @@ ##import ut import unittest as ut -from ctypes import HRESULT, POINTER, byref +from ctypes import HRESULT, POINTER from comtypes import GUID, STDMETHOD, IUnknown -from comtypes.typeinfo import SYS_WIN32, CreateTypeLib, ICreateTypeLib2, _CreateTypeLib2 +from comtypes.typeinfo import SYS_WIN32, CreateTypeLib, ICreateTypeLib2 # XXX leaks references! @@ -24,8 +24,8 @@ def test_release(self): def test_refcounts(self): # Since all COM interfaces derive from IUnknown and have the same reference counting behavior, any interface # — whether ICreateTypeLib2 or otherwise — could be used for this test. - p = POINTER(ICreateTypeLib2)() - _CreateTypeLib2(SYS_WIN32, "blabla", byref(p)) + p = CreateTypeLib("blabla", syskind=SYS_WIN32) + self.assertIsInstance(p, ICreateTypeLib2) # initial refcount is 2 for i in range(2, 10): self.assertEqual(p.AddRef(), i) @@ -35,8 +35,8 @@ def test_refcounts(self): def test_qi(self): # Since all COM interfaces derive from IUnknown and have the same QueryInterface behavior, any interface # — whether ICreateTypeLib2 or otherwise — could be used for this test. - p = POINTER(ICreateTypeLib2)() - _CreateTypeLib2(SYS_WIN32, "blabla", byref(p)) + p = CreateTypeLib("blabla", syskind=SYS_WIN32) + self.assertIsInstance(p, ICreateTypeLib2) self.assertEqual(p.AddRef(), 2) self.assertEqual(p.Release(), 1) From 09dced22a36fcf58b2019071a0a5f08013dea098 Mon Sep 17 00:00:00 2001 From: junkmd Date: Sun, 29 Mar 2026 15:52:00 +0900 Subject: [PATCH 4/6] refactor: Remove redundant `IUnknown` import in `test_basic.py`. Remove the redundant inline import of `IUnknown` from the `test_IUnknown` method, as it is already imported at the top level of `test/test_basic.py`. --- comtypes/test/test_basic.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/comtypes/test/test_basic.py b/comtypes/test/test_basic.py index 9a7cd830..607cc0e5 100644 --- a/comtypes/test/test_basic.py +++ b/comtypes/test/test_basic.py @@ -14,8 +14,6 @@ def method_count(interface): class BasicTest(ut.TestCase): def test_IUnknown(self): - from comtypes import IUnknown - self.assertEqual(method_count(IUnknown), 3) def test_release(self): From 37b0c608b71c817a3c652b2f1e27254fa5542e94 Mon Sep 17 00:00:00 2001 From: junkmd Date: Sun, 29 Mar 2026 15:52:00 +0900 Subject: [PATCH 5/6] refactor: Remove commented-out code in `test_basic.py`. Remove a redundant commented-out `import` statement from the top of `test/test_basic.py`. --- comtypes/test/test_basic.py | 1 - 1 file changed, 1 deletion(-) diff --git a/comtypes/test/test_basic.py b/comtypes/test/test_basic.py index 607cc0e5..974a92a3 100644 --- a/comtypes/test/test_basic.py +++ b/comtypes/test/test_basic.py @@ -1,4 +1,3 @@ -##import ut import unittest as ut from ctypes import HRESULT, POINTER From bbdf3c883ba04f245806ee33d008c818db228e5e Mon Sep 17 00:00:00 2001 From: junkmd Date: Sun, 29 Mar 2026 15:52:00 +0900 Subject: [PATCH 6/6] test: Verify `IUnknown` instance in `test_basic.py`. Add assertions to `BasicTest.test_refcounts` and `BasicTest.test_qi` to verify that the object returned by `CreateTypeLib` is an instance of `IUnknown`. --- comtypes/test/test_basic.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/comtypes/test/test_basic.py b/comtypes/test/test_basic.py index 974a92a3..9a582fab 100644 --- a/comtypes/test/test_basic.py +++ b/comtypes/test/test_basic.py @@ -23,6 +23,7 @@ def test_refcounts(self): # — whether ICreateTypeLib2 or otherwise — could be used for this test. p = CreateTypeLib("blabla", syskind=SYS_WIN32) self.assertIsInstance(p, ICreateTypeLib2) + self.assertIsInstance(p, IUnknown) # initial refcount is 2 for i in range(2, 10): self.assertEqual(p.AddRef(), i) @@ -34,6 +35,7 @@ def test_qi(self): # — whether ICreateTypeLib2 or otherwise — could be used for this test. p = CreateTypeLib("blabla", syskind=SYS_WIN32) self.assertIsInstance(p, ICreateTypeLib2) + self.assertIsInstance(p, IUnknown) self.assertEqual(p.AddRef(), 2) self.assertEqual(p.Release(), 1)