comtypes 1.4.9__zip → 1.4.11__zip

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. {comtypes-1.4.9 → comtypes-1.4.11}/CHANGES.txt +41 -0
  2. {comtypes-1.4.9/comtypes.egg-info → comtypes-1.4.11}/PKG-INFO +4 -2
  3. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/GUID.py +34 -13
  4. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/__init__.py +25 -16
  5. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_comobject.py +92 -39
  6. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_memberspec.py +112 -78
  7. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_meta.py +2 -1
  8. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_post_coinit/_cominterface_meta_patcher.py +3 -6
  9. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_post_coinit/bstr.py +12 -5
  10. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_post_coinit/instancemethod.py +1 -2
  11. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_post_coinit/misc.py +59 -24
  12. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_post_coinit/unknwn.py +30 -25
  13. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_safearray.py +2 -2
  14. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_vtbl.py +52 -55
  15. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/automation.py +19 -14
  16. comtypes-1.4.11/comtypes/client/__init__.py +42 -0
  17. comtypes-1.4.11/comtypes/client/_activeobj.py +46 -0
  18. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/client/_code_cache.py +15 -24
  19. comtypes-1.4.11/comtypes/client/_create.py +147 -0
  20. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/client/_events.py +140 -57
  21. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/client/_generate.py +3 -5
  22. comtypes-1.4.11/comtypes/client/_managing.py +114 -0
  23. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/client/dynamic.py +2 -3
  24. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/client/lazybind.py +10 -11
  25. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/connectionpoints.py +38 -3
  26. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/errorinfo.py +72 -21
  27. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/git.py +4 -3
  28. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/hints.pyi +15 -2
  29. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/hresult.py +16 -6
  30. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/logutil.py +15 -3
  31. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/messageloop.py +15 -13
  32. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/persist.py +3 -5
  33. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/safearray.py +8 -6
  34. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/server/__init__.py +22 -4
  35. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/server/automation.py +1 -2
  36. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/server/connectionpoints.py +71 -70
  37. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/server/inprocserver.py +14 -8
  38. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/server/localserver.py +28 -16
  39. comtypes-1.4.11/comtypes/server/register.py +478 -0
  40. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/shelllink.py +13 -7
  41. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/stream.py +7 -4
  42. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/TestComServer.py +6 -7
  43. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/TestDispServer.py +4 -2
  44. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/__init__.py +1 -1
  45. comtypes-1.4.11/comtypes/test/find_memleak.py +72 -0
  46. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/runtests.py +1 -0
  47. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/setup.py +2 -1
  48. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_BSTR.py +7 -17
  49. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_GUID.py +7 -7
  50. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_QueryService.py +1 -0
  51. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_agilent.py +4 -3
  52. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_basic.py +18 -9
  53. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_clear_cache.py +1 -1
  54. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_client.py +2 -2
  55. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_client_dynamic.py +2 -2
  56. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_client_regenerate_modules.py +2 -2
  57. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_collections.py +7 -4
  58. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_comobject.py +22 -9
  59. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_comserver.py +56 -3
  60. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_dict.py +2 -1
  61. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_dispifc_records.py +1 -1
  62. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_dispifc_safearrays.py +1 -1
  63. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_dyndispatch.py +5 -2
  64. comtypes-1.4.11/comtypes/test/test_errorinfo.py +115 -0
  65. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_findgendir.py +1 -2
  66. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_getactiveobj.py +4 -4
  67. comtypes-1.4.11/comtypes/test/test_hresult.py +48 -0
  68. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_ie.py +19 -6
  69. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_ienum.py +2 -2
  70. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_imfattributes.py +13 -3
  71. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_inout_args.py +10 -3
  72. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_midl_safearray_create.py +6 -4
  73. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_monikers.py +23 -9
  74. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_msscript.py +2 -1
  75. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_npsupport.py +4 -4
  76. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_outparam.py +22 -6
  77. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_persist.py +2 -4
  78. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_recordinfo.py +1 -1
  79. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_safearray.py +2 -1
  80. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_sapi.py +4 -1
  81. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_server_register.py +114 -125
  82. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_shelllink.py +2 -3
  83. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_storage.py +12 -6
  84. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_stream.py +16 -5
  85. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_subinterface.py +4 -2
  86. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_typeannotator.py +1 -2
  87. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_typeinfo.py +36 -7
  88. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_urlhistory.py +7 -4
  89. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_variant.py +5 -3
  90. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_w_getopt.py +4 -4
  91. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_word.py +1 -1
  92. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/codegenerator/codegenerator.py +167 -435
  93. comtypes-1.4.11/comtypes/tools/codegenerator/comments.py +79 -0
  94. comtypes-1.4.11/comtypes/tools/codegenerator/heads.py +192 -0
  95. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/codegenerator/helpers.py +3 -6
  96. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/codegenerator/namespaces.py +13 -5
  97. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/codegenerator/typeannotator.py +13 -3
  98. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/tlbparser.py +25 -25
  99. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/typedesc.py +3 -2
  100. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/typedesc_base.py +2 -2
  101. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/typeinfo.py +163 -51
  102. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/viewobject.py +2 -4
  103. {comtypes-1.4.9 → comtypes-1.4.11/comtypes.egg-info}/PKG-INFO +4 -2
  104. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes.egg-info/SOURCES.txt +7 -0
  105. {comtypes-1.4.9 → comtypes-1.4.11}/pyproject.toml +10 -23
  106. comtypes-1.4.9/comtypes/client/__init__.py +0 -323
  107. comtypes-1.4.9/comtypes/server/register.py +0 -419
  108. comtypes-1.4.9/comtypes/test/find_memleak.py +0 -76
  109. {comtypes-1.4.9 → comtypes-1.4.11}/LICENSE.txt +0 -0
  110. {comtypes-1.4.9 → comtypes-1.4.11}/MANIFEST.in +0 -0
  111. {comtypes-1.4.9 → comtypes-1.4.11}/README.md +0 -0
  112. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_npsupport.py +0 -0
  113. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_post_coinit/__init__.py +0 -0
  114. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_tlib_version_checker.py +0 -0
  115. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/clear_cache.py +0 -0
  116. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/client/_constants.py +0 -0
  117. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/patcher.py +0 -0
  118. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/server/w_getopt.py +0 -0
  119. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/TestComServer.idl +0 -0
  120. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/TestComServer.tlb +0 -0
  121. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/TestDispServer.idl +0 -0
  122. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/TestDispServer.tlb +0 -0
  123. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/mylib.idl +0 -0
  124. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/mylib.tlb +0 -0
  125. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/mytypelib.idl +0 -0
  126. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_DISPPARAMS.py +0 -0
  127. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_avmc.py +0 -0
  128. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_casesensitivity.py +0 -0
  129. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_createwrappers.py +0 -0
  130. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_dispinterface.py +0 -0
  131. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_excel.py +0 -0
  132. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_jscript.js +0 -0
  133. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_pump_events.py +0 -0
  134. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_server.py +0 -0
  135. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_showevents.py +0 -0
  136. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_win32com_interop.py +0 -0
  137. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_wmi.py +0 -0
  138. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/urlhist.tlb +0 -0
  139. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/__init__.py +0 -0
  140. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/codegenerator/__init__.py +0 -0
  141. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/codegenerator/modulenamer.py +0 -0
  142. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/codegenerator/packing.py +0 -0
  143. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/util.py +0 -0
  144. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes.egg-info/dependency_links.txt +0 -0
  145. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes.egg-info/entry_points.txt +0 -0
  146. {comtypes-1.4.9 → comtypes-1.4.11}/comtypes.egg-info/top_level.txt +0 -0
  147. {comtypes-1.4.9 → comtypes-1.4.11}/setup.cfg +0 -0
  148. {comtypes-1.4.9 → comtypes-1.4.11}/setup.py +0 -0
@@ -1,5 +1,6 @@
1
1
  import unittest
2
- from ctypes import WINFUNCTYPE, c_uint, c_void_p, oledll, windll
2
+ from ctypes import WinDLL
3
+ from ctypes.wintypes import UINT
3
4
 
4
5
  from comtypes import BSTR
5
6
  from comtypes.test.find_memleak import find_memleak
@@ -24,23 +25,12 @@ class Test(unittest.TestCase):
24
25
 
25
26
  self.check_leaks(doit)
26
27
 
27
- def test_paramflags(self):
28
- prototype = WINFUNCTYPE(c_void_p, BSTR)
29
- func = prototype(("SysStringLen", oledll.oleaut32))
30
- func.restype = c_void_p
31
- func.argtypes = (BSTR,)
32
-
33
- def doit():
34
- func("abcdef")
35
- func("abc xyz")
36
- func(BSTR("abc def"))
37
-
38
- self.check_leaks(doit)
39
-
40
28
  def test_inargs(self):
41
- SysStringLen = windll.oleaut32.SysStringLen
42
- SysStringLen.argtypes = (BSTR,)
43
- SysStringLen.restype = c_uint
29
+ oleaut32 = WinDLL("oleaut32")
30
+
31
+ SysStringLen = oleaut32.SysStringLen
32
+ SysStringLen.argtypes = [BSTR]
33
+ SysStringLen.restype = UINT
44
34
 
45
35
  self.assertEqual(SysStringLen("abc xyz"), 7)
46
36
 
@@ -1,4 +1,5 @@
1
1
  import unittest
2
+
2
3
  from comtypes import GUID
3
4
 
4
5
 
@@ -29,25 +30,24 @@ class Test(unittest.TestCase):
29
30
  )
30
31
 
31
32
  def test_invalid_constructor_arg(self):
32
- self.assertRaises(WindowsError, GUID, "abc")
33
+ with self.assertRaises(WindowsError):
34
+ GUID("abc")
33
35
 
34
36
  def test_from_progid(self):
35
37
  self.assertEqual(
36
38
  GUID.from_progid("Scripting.FileSystemObject"),
37
39
  GUID("{0D43FE01-F093-11CF-8940-00A0C9054228}"),
38
40
  )
39
- self.assertRaises(WindowsError, GUID.from_progid, "abc")
41
+ with self.assertRaises(WindowsError):
42
+ GUID.from_progid("abc")
40
43
 
41
44
  def test_as_progid(self):
42
45
  self.assertEqual(
43
46
  GUID("{0D43FE01-F093-11CF-8940-00A0C9054228}").as_progid(),
44
47
  "Scripting.FileSystemObject",
45
48
  )
46
- self.assertRaises(
47
- WindowsError,
48
- lambda guid: guid.as_progid(),
49
- GUID("{00000000-0000-0000-C000-000000000046}"),
50
- )
49
+ with self.assertRaises(WindowsError):
50
+ GUID("{00000000-0000-0000-C000-000000000046}").as_progid()
51
51
 
52
52
  def test_create_new(self):
53
53
  self.assertNotEqual(GUID.create_new(), GUID.create_new())
@@ -1,5 +1,6 @@
1
1
  import unittest
2
2
  from ctypes import POINTER
3
+
3
4
  import comtypes
4
5
  from comtypes.client import CreateObject, GetModule
5
6
 
@@ -3,11 +3,12 @@
3
3
  # connected, the driver is used in simulation mode.
4
4
 
5
5
  import unittest
6
- from comtypes.test import ResourceDenied
7
- from comtypes.client import CreateObject
6
+ from ctypes import POINTER, c_double
7
+
8
8
  from comtypes import GUID
9
+ from comtypes.client import CreateObject
9
10
  from comtypes.safearray import _midlSAFEARRAY
10
- from ctypes import c_double, POINTER
11
+ from comtypes.test import ResourceDenied
11
12
 
12
13
  try:
13
14
  GUID.from_progid("Agilent546XX.Agilent546XX")
@@ -1,7 +1,9 @@
1
1
  ##import ut
2
2
  import unittest as ut
3
- from ctypes import windll, POINTER, byref, HRESULT
4
- from comtypes import IUnknown, STDMETHOD, GUID
3
+ from ctypes import HRESULT, POINTER, byref
4
+
5
+ from comtypes import GUID, STDMETHOD, IUnknown
6
+ from comtypes.typeinfo import ICreateTypeLib2, _CreateTypeLib2
5
7
 
6
8
  # XXX leaks references!
7
9
 
@@ -20,8 +22,10 @@ class BasicTest(ut.TestCase):
20
22
  POINTER(IUnknown)()
21
23
 
22
24
  def test_refcounts(self):
23
- p = POINTER(IUnknown)()
24
- windll.oleaut32.CreateTypeLib2(1, "blabla", byref(p))
25
+ # Since all COM interfaces derive from IUnknown and have the same reference counting behavior, any interface
26
+ # — whether ICreateTypeLib2 or otherwise — could be used for this test.
27
+ p = POINTER(ICreateTypeLib2)()
28
+ _CreateTypeLib2(1, "blabla", byref(p))
25
29
  # initial refcount is 2
26
30
  for i in range(2, 10):
27
31
  self.assertEqual(p.AddRef(), i)
@@ -29,8 +33,10 @@ class BasicTest(ut.TestCase):
29
33
  self.assertEqual(p.Release(), i)
30
34
 
31
35
  def test_qi(self):
32
- p = POINTER(IUnknown)()
33
- windll.oleaut32.CreateTypeLib2(1, "blabla", byref(p))
36
+ # Since all COM interfaces derive from IUnknown and have the same QueryInterface behavior, any interface
37
+ # — whether ICreateTypeLib2 or otherwise — could be used for this test.
38
+ p = POINTER(ICreateTypeLib2)()
39
+ _CreateTypeLib2(1, "blabla", byref(p))
34
40
  self.assertEqual(p.AddRef(), 2)
35
41
  self.assertEqual(p.Release(), 1)
36
42
 
@@ -55,7 +61,8 @@ class BasicTest(ut.TestCase):
55
61
  self.assertEqual(method_count(IMyInterface), 3)
56
62
 
57
63
  # assigning _methods_ does not work until we have an _iid_!
58
- self.assertRaises(AttributeError, setattr, IMyInterface, "_methods_", [])
64
+ with self.assertRaises(AttributeError):
65
+ setattr(IMyInterface, "_methods_", [])
59
66
  IMyInterface._iid_ = GUID.create_new()
60
67
  IMyInterface._methods_ = []
61
68
  self.assertEqual(method_count(IMyInterface), 3)
@@ -90,9 +97,11 @@ class BasicTest(ut.TestCase):
90
97
  _iid_ = GUID.create_new()
91
98
 
92
99
  # We cannot assign _methods_ to IDerived before IBase has it's _methods_:
93
- self.assertRaises(TypeError, lambda: setattr(IDerived, "_methods_", []))
100
+ with self.assertRaises(TypeError):
101
+ setattr(IDerived, "_methods_", [])
94
102
  # Make sure that setting _methods_ failed completely.
95
- self.assertRaises(KeyError, lambda: IDerived.__dict__["_methods_"])
103
+ with self.assertRaises(KeyError):
104
+ IDerived.__dict__["_methods_"]
96
105
  IBase._methods_ = []
97
106
  # Now it works:
98
107
  IDerived._methods_ = []
@@ -4,8 +4,8 @@ Test for the ``comtypes.clear_cache`` module.
4
4
 
5
5
  import contextlib
6
6
  import runpy
7
- from unittest.mock import patch, call
8
7
  from unittest import TestCase
8
+ from unittest.mock import call, patch
9
9
 
10
10
  from comtypes.client import _find_gen_dir
11
11
 
@@ -1,11 +1,11 @@
1
1
  import contextlib
2
- from ctypes import POINTER, byref
3
2
  import os
4
3
  import sys
5
4
  import unittest as ut
5
+ from ctypes import POINTER, byref
6
6
 
7
7
  import comtypes.client
8
- from comtypes import COSERVERINFO, CLSCTX_INPROC_SERVER
8
+ from comtypes import CLSCTX_INPROC_SERVER, COSERVERINFO
9
9
 
10
10
  # create the typelib wrapper and import it
11
11
  comtypes.client.GetModule("scrrun.dll")
@@ -2,8 +2,8 @@ import ctypes
2
2
  import unittest as ut
3
3
  from unittest import mock
4
4
 
5
- from comtypes import automation, COMError, IUnknown
6
- from comtypes.client import CreateObject, dynamic, GetModule, lazybind
5
+ from comtypes import COMError, IUnknown, automation
6
+ from comtypes.client import CreateObject, GetModule, dynamic, lazybind
7
7
 
8
8
 
9
9
  class Test_Dispatch_Function(ut.TestCase):
@@ -1,12 +1,12 @@
1
1
  import contextlib
2
2
  import importlib
3
- from pathlib import Path
4
3
  import shutil
5
4
  import sys
6
5
  import tempfile
7
6
  import types
8
- from typing import Iterator
9
7
  import unittest as ut
8
+ from pathlib import Path
9
+ from typing import Iterator
10
10
  from unittest import mock
11
11
 
12
12
  import comtypes
@@ -1,7 +1,7 @@
1
1
  import unittest
2
- from comtypes.client import CreateObject
3
2
  from ctypes import ArgumentError
4
3
 
4
+ from comtypes.client import CreateObject
5
5
  from comtypes.test.find_memleak import find_memleak
6
6
 
7
7
 
@@ -60,7 +60,8 @@ class Test(unittest.TestCase):
60
60
 
61
61
  # slicing is not (yet?) supported
62
62
  cv.Reset()
63
- self.assertRaises(ArgumentError, lambda: cv[:])
63
+ with self.assertRaises(ArgumentError):
64
+ cv[:]
64
65
 
65
66
  @unittest.skip("This test takes a long time. Do we need it? Can it be rewritten?")
66
67
  def test_leaks_1(self):
@@ -151,10 +152,12 @@ class TestCollectionInterface(unittest.TestCase):
151
152
  self.assertAccessInterface(d)
152
153
 
153
154
  def test_named_property_no_length(self):
154
- self.assertRaises(TypeError, len, self.d.Item)
155
+ with self.assertRaises(TypeError):
156
+ len(self.d.Item)
155
157
 
156
158
  def test_named_property_not_iterable(self):
157
- self.assertRaises(TypeError, list, self.d.Item)
159
+ with self.assertRaises(TypeError):
160
+ list(self.d.Item)
158
161
 
159
162
 
160
163
  if __name__ == "__main__":
@@ -3,10 +3,11 @@ import unittest as ut
3
3
  from ctypes import POINTER, byref, pointer
4
4
  from unittest import mock
5
5
 
6
- import comtypes
7
6
  import comtypes.client
8
- from comtypes import COMObject, IUnknown, hresult
7
+ from comtypes import CLSCTX_SERVER, COMObject, IPersist, IUnknown, hresult
8
+ from comtypes._post_coinit.misc import _CoCreateInstance
9
9
  from comtypes.automation import IDispatch
10
+ from comtypes.typeinfo import GUIDKIND_DEFAULT_SOURCE_DISP_IID
10
11
 
11
12
  comtypes.client.GetModule("UIAutomationCore.dll")
12
13
  comtypes.client.GetModule("scrrun.dll")
@@ -54,10 +55,10 @@ class Test_IUnknown_QueryInterface(ut.TestCase):
54
55
 
55
56
  def test_valid_pointer(self):
56
57
  ptr = ctypes.c_void_p()
57
- ctypes.oledll.ole32.CoCreateInstance(
58
+ _CoCreateInstance(
58
59
  byref(scrrun.Dictionary._reg_clsid_),
59
60
  None,
60
- comtypes.CLSCTX_SERVER,
61
+ CLSCTX_SERVER,
61
62
  byref(scrrun.IDictionary._iid_),
62
63
  byref(ptr),
63
64
  )
@@ -131,11 +132,9 @@ class Test_IProvideClassInfo_GetClassInfo(ut.TestCase):
131
132
 
132
133
  class Test_IProvideClassInfo2_GetGUID(ut.TestCase):
133
134
  def test(self):
134
- # GUIDKIND_DEFAULT_SOURCE_DISP_IID = 1
135
- self.assertEqual(
136
- stdole.StdFont().IProvideClassInfo2_GetGUID(1),
137
- stdole.FontEvents._iid_,
138
- )
135
+ obj = stdole.StdFont()
136
+ actual = obj.IProvideClassInfo2_GetGUID(GUIDKIND_DEFAULT_SOURCE_DISP_IID)
137
+ self.assertEqual(actual, stdole.FontEvents._iid_)
139
138
 
140
139
 
141
140
  class Test_IPersist_GetClassID(ut.TestCase):
@@ -144,3 +143,17 @@ class Test_IPersist_GetClassID(ut.TestCase):
144
143
  uiac.CUIAutomation().IPersist_GetClassID(),
145
144
  uiac.CUIAutomation._reg_clsid_,
146
145
  )
146
+
147
+
148
+ class Test_Vtbl(ut.TestCase):
149
+ def test_com_pointers(self):
150
+ stdpic = stdole.StdPicture()
151
+ cuia = uiac.CUIAutomation()
152
+ self.assertIs(
153
+ type(stdpic._com_pointers_[IPersist._iid_]),
154
+ type(cuia._com_pointers_[IPersist._iid_]),
155
+ )
156
+ self.assertIn(IDispatch._iid_, stdpic._com_pointers_)
157
+ self.assertNotIn(IDispatch._iid_, cuia._com_pointers_)
158
+ self.assertIn(stdole.IPictureDisp._iid_, stdpic._com_pointers_)
159
+ self.assertIn(uiac.IUIAutomation._iid_, cuia._com_pointers_)
@@ -3,10 +3,11 @@ import unittest
3
3
  from ctypes import pointer
4
4
  from typing import Any
5
5
 
6
+ import comtypes.server
6
7
  import comtypes.test.TestComServer
7
- from comtypes import BSTR
8
+ from comtypes import BSTR, errorinfo, hresult, shelllink
8
9
  from comtypes.automation import VARIANT, _midlSAFEARRAY
9
- from comtypes.client import CreateObject
10
+ from comtypes.client import CreateObject, GetActiveObject
10
11
  from comtypes.server.register import register, unregister
11
12
  from comtypes.test.find_memleak import find_memleak
12
13
 
@@ -171,6 +172,55 @@ class TestLocalServer_win32com(BaseServerTest, unittest.TestCase):
171
172
  pass
172
173
 
173
174
 
175
+ class ActiveObjTest(unittest.TestCase):
176
+ def get_active_object(self) -> comtypes.test.TestComServer.ITestComServer:
177
+ return GetActiveObject(
178
+ comtypes.test.TestComServer.TestComServer,
179
+ interface=comtypes.test.TestComServer.ITestComServer,
180
+ )
181
+
182
+ def _doit(self, weak: bool):
183
+ comobj = comtypes.test.TestComServer.TestComServer()
184
+ with self.assertRaises(OSError):
185
+ self.get_active_object()
186
+ handle = comtypes.server.RegisterActiveObject(comobj, weak=weak)
187
+ activeobj = self.get_active_object()
188
+ self.assertEqual(activeobj.MixedInOut(2, 4), (3, 5))
189
+ self.assertEqual(activeobj.AddRef(), 3)
190
+ self.assertEqual(activeobj.Release(), 2)
191
+ punk = comobj.QueryInterface(comtypes.test.TestComServer.ITestComServer)
192
+ self.assertEqual(activeobj, punk)
193
+ comtypes.server.RevokeActiveObject(handle)
194
+ with self.assertRaises(OSError):
195
+ self.get_active_object()
196
+
197
+ def test_activeobj_weak_registration(self):
198
+ self._doit(weak=True)
199
+
200
+ def test_activeobj_strong_registration(self):
201
+ self._doit(weak=False)
202
+
203
+
204
+ class SupportErrorInfoTest(unittest.TestCase):
205
+ def create_object(self):
206
+ return CreateObject(
207
+ comtypes.test.TestComServer.TestComServer,
208
+ interface=comtypes.test.TestComServer.ITestComServer,
209
+ )
210
+
211
+ def test_returns_S_OK(self):
212
+ psei = self.create_object().QueryInterface(errorinfo.ISupportErrorInfo)
213
+ iid = comtypes.test.TestComServer.ITestComServer._iid_
214
+ hr = psei.InterfaceSupportsErrorInfo(iid)
215
+ self.assertEqual(hr, hresult.S_OK)
216
+
217
+ def test_returns_S_FALSE(self):
218
+ psei = self.create_object().QueryInterface(errorinfo.ISupportErrorInfo)
219
+ iid = shelllink.IShellLinkW._iid_
220
+ hr = psei.InterfaceSupportsErrorInfo(iid)
221
+ self.assertEqual(hr, hresult.S_FALSE)
222
+
223
+
174
224
  class VariantTest(unittest.TestCase):
175
225
  def test_UDT(self):
176
226
  from comtypes.gen.TestComServerLib import MYCOLOR
@@ -247,7 +297,10 @@ class TestEvents(unittest.TestCase):
247
297
  import comtypes.test.test_comserver
248
298
 
249
299
  doctest.testmod(
250
- comtypes.test.test_comserver, verbose=False, optionflags=doctest.ELLIPSIS
300
+ comtypes.test.test_comserver,
301
+ verbose=False,
302
+ optionflags=doctest.ELLIPSIS,
303
+ raise_on_error=True,
251
304
  )
252
305
 
253
306
 
@@ -14,7 +14,8 @@ class Test(unittest.TestCase):
14
14
 
15
15
  # Count is a normal propget, no propput
16
16
  self.assertEqual(d.Count, 0)
17
- self.assertRaises(AttributeError, lambda: setattr(d, "Count", -1))
17
+ with self.assertRaises(AttributeError):
18
+ setattr(d, "Count", -1)
18
19
 
19
20
  # HashVal is a 'named' propget, no propput
20
21
  ##d.HashVal
@@ -1,10 +1,10 @@
1
1
  # coding: utf-8
2
2
 
3
3
  import unittest
4
+ from ctypes import byref, pointer
4
5
 
5
6
  from comtypes import CLSCTX_LOCAL_SERVER
6
7
  from comtypes.client import CreateObject, GetModule
7
- from ctypes import byref, pointer
8
8
 
9
9
  ComtypesCppTestSrvLib_GUID = "{07D2AEE5-1DF8-4D2C-953A-554ADFD25F99}"
10
10
 
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
 
3
- from ctypes import byref, c_double, pointer
4
3
  import unittest
4
+ from ctypes import byref, c_double, pointer
5
5
 
6
6
  import comtypes
7
7
  import comtypes.safearray
@@ -1,4 +1,5 @@
1
1
  import unittest
2
+
2
3
  from comtypes.automation import IDispatch
3
4
  from comtypes.client import CreateObject, GetModule
4
5
  from comtypes.client.lazybind import Dispatch
@@ -65,10 +66,12 @@ class Test(unittest.TestCase):
65
66
  self.assertEqual(d3.Item["baz"], 3.14)
66
67
 
67
68
  def test_named_property_no_length(self):
68
- self.assertRaises(TypeError, len, self.d.Item)
69
+ with self.assertRaises(TypeError):
70
+ len(self.d.Item)
69
71
 
70
72
  def test_named_property_not_iterable(self):
71
- self.assertRaises(TypeError, list, self.d.Item)
73
+ with self.assertRaises(TypeError):
74
+ list(self.d.Item)
72
75
 
73
76
  def assertAccessInterface(self, d):
74
77
  """Asserts access via indexing and named property"""
@@ -0,0 +1,115 @@
1
+ import unittest as ut
2
+
3
+ from comtypes import errorinfo, shelllink
4
+ from comtypes import hresult as hres
5
+
6
+
7
+ class Test_GetErrorInfo(ut.TestCase):
8
+ def test_error_has_been_set(self):
9
+ self.assertIsNone(errorinfo.GetErrorInfo())
10
+ errmsg = "sample unexpected error message for tests"
11
+ errcode = hres.E_UNEXPECTED
12
+ helpcontext = 123
13
+ hr = errorinfo.ReportError(
14
+ errmsg,
15
+ shelllink.IShellLinkW._iid_,
16
+ str(shelllink.ShellLink._reg_clsid_),
17
+ helpfile="help.chm",
18
+ helpcontext=helpcontext,
19
+ hresult=errcode,
20
+ )
21
+ self.assertEqual(errcode, hr)
22
+ pei = errorinfo.GetErrorInfo()
23
+ self.assertIsNotNone(pei)
24
+ assert pei is not None # for static type guard
25
+ self.assertEqual(shelllink.IShellLinkW._iid_, pei.GetGUID())
26
+ self.assertEqual("lnkfile", pei.GetSource())
27
+ self.assertEqual(errmsg, pei.GetDescription())
28
+ self.assertEqual("help.chm", pei.GetHelpFile())
29
+ self.assertEqual(helpcontext, pei.GetHelpContext())
30
+ # Calling `GetErrorInfo` clears the error state for the thread.
31
+ # Therefore, `None` is returned in the second call.
32
+ self.assertIsNone(errorinfo.GetErrorInfo())
33
+
34
+ def test_without_optional_args(self):
35
+ self.assertIsNone(errorinfo.GetErrorInfo())
36
+ errmsg = "sample unexpected error message for tests"
37
+ hr = errorinfo.ReportError(errmsg, shelllink.IShellLinkW._iid_)
38
+ self.assertEqual(hres.DISP_E_EXCEPTION, hr)
39
+ pei = errorinfo.GetErrorInfo()
40
+ self.assertIsNotNone(pei)
41
+ assert pei is not None # for static type guard
42
+ self.assertEqual(shelllink.IShellLinkW._iid_, pei.GetGUID())
43
+ self.assertIsNone(pei.GetSource())
44
+ self.assertEqual(errmsg, pei.GetDescription())
45
+ self.assertIsNone(pei.GetHelpFile())
46
+ self.assertEqual(0, pei.GetHelpContext())
47
+
48
+ def test_error_has_not_been_set(self):
49
+ self.assertIsNone(errorinfo.GetErrorInfo())
50
+ pei = errorinfo.GetErrorInfo()
51
+ self.assertIsNone(pei)
52
+
53
+
54
+ def raise_runtime_error():
55
+ _raise_runtime_error()
56
+
57
+
58
+ def _raise_runtime_error():
59
+ raise RuntimeError("for testing")
60
+
61
+
62
+ class Test_ReportException(ut.TestCase):
63
+ def test_without_stacklevel(self):
64
+ self.assertIsNone(errorinfo.GetErrorInfo())
65
+ iid = shelllink.IShellLinkW._iid_
66
+ try:
67
+ raise_runtime_error()
68
+ except RuntimeError:
69
+ hr = errorinfo.ReportException(hres.E_UNEXPECTED, iid)
70
+ self.assertEqual(hres.E_UNEXPECTED, hr)
71
+ pei = errorinfo.GetErrorInfo()
72
+ self.assertIsNotNone(pei)
73
+ assert pei is not None # for static type guard
74
+ self.assertEqual(shelllink.IShellLinkW._iid_, pei.GetGUID())
75
+ self.assertIsNone(pei.GetSource())
76
+ self.assertEqual("<class 'RuntimeError'>: for testing", pei.GetDescription())
77
+ self.assertIsNone(pei.GetHelpFile())
78
+ self.assertEqual(0, pei.GetHelpContext())
79
+ self.assertIsNone(errorinfo.GetErrorInfo())
80
+
81
+ def test_with_stacklevel(self):
82
+ self.assertIsNone(errorinfo.GetErrorInfo())
83
+ stem = "<class 'RuntimeError'>: for testing"
84
+ iid = shelllink.IShellLinkW._iid_
85
+ for slv, text in [
86
+ # XXX: If the codebase changes, the line where functions or
87
+ # methods are defined will change, meaning this test is brittle.
88
+ (0, f"{stem} ({__name__}, line 96)"),
89
+ (1, f"{stem} ({__name__}, line 55)"),
90
+ (2, f"{stem} ({__name__}, line 59)"),
91
+ ]:
92
+ with self.subTest(text=text):
93
+ try:
94
+ raise_runtime_error()
95
+ except RuntimeError:
96
+ errorinfo.ReportException(hres.E_UNEXPECTED, iid, stacklevel=slv)
97
+ pei = errorinfo.GetErrorInfo()
98
+ assert pei is not None # for static type guard
99
+ self.assertEqual(text, pei.GetDescription())
100
+ self.assertIsNone(errorinfo.GetErrorInfo())
101
+
102
+ def test_with_over_stacklevel(self):
103
+ self.assertIsNone(errorinfo.GetErrorInfo())
104
+ iid = shelllink.IShellLinkW._iid_
105
+ try:
106
+ raise_runtime_error()
107
+ except RuntimeError:
108
+ with self.assertRaises(ValueError):
109
+ errorinfo.ReportException(hres.E_UNEXPECTED, iid, stacklevel=4)
110
+
111
+ def test_with_no_error_and_zero_stacklevel(self):
112
+ self.assertIsNone(errorinfo.GetErrorInfo())
113
+ iid = shelllink.IShellLinkW._iid_
114
+ with self.assertRaises(ValueError):
115
+ errorinfo.ReportException(hres.E_UNEXPECTED, iid, stacklevel=0)
@@ -4,15 +4,14 @@ import os
4
4
  import sys
5
5
  import tempfile
6
6
  import types
7
- from typing import Iterator
8
7
  import unittest
8
+ from typing import Iterator
9
9
  from unittest import mock
10
10
 
11
11
  import comtypes
12
12
  import comtypes.client
13
13
  import comtypes.gen
14
14
 
15
-
16
15
  IMGBASE = os.path.splitext(os.path.basename(sys.executable))[0]
17
16
 
18
17
 
@@ -8,9 +8,9 @@ import comtypes.test
8
8
  try:
9
9
  # pass Word libUUID
10
10
  comtypes.client.GetModule(("{00020905-0000-0000-C000-000000000046}",))
11
- IMPORT_FAILED = False
11
+ IMPORT_WORD_FAILED = False
12
12
  except (ImportError, OSError):
13
- IMPORT_FAILED = True
13
+ IMPORT_WORD_FAILED = True
14
14
 
15
15
 
16
16
  ################################################################
@@ -24,8 +24,8 @@ except (ImportError, OSError):
24
24
  ################################################################
25
25
 
26
26
 
27
- @unittest.skipIf(IMPORT_FAILED, "This depends on Word.")
28
- class Test(unittest.TestCase):
27
+ @unittest.skipIf(IMPORT_WORD_FAILED, "This depends on Word.")
28
+ class Test_Word(unittest.TestCase):
29
29
  def setUp(self):
30
30
  try:
31
31
  comtypes.client.GetActiveObject("Word.Application")
@@ -0,0 +1,48 @@
1
+ import unittest as ut
2
+
3
+ import comtypes.hresult
4
+
5
+
6
+ class Test_MAKE_HRESULT(ut.TestCase):
7
+ def test(self):
8
+ for sev, fac, code, hr in [
9
+ (0x0000, 0x0000, 0x0000, 0),
10
+ (0x0001, 0x0000, 0x0000, -2147483648),
11
+ (0x0000, 0x0001, 0x0000, 65536),
12
+ (0x0000, 0x0000, 0x0001, 1),
13
+ (0x0001, 0xFFFF, 0xFFFF, -1),
14
+ (0x0000, 0xFFFF, 0xFFFF, -1),
15
+ (0x0001, 0x0000, 0x0001, -2147483647),
16
+ (0x0001, 0x0001, 0x0001, -2147418111),
17
+ (0x0000, 0x0001, 0xFFFF, 131071),
18
+ (0x0001, 0xFFFF, 0x0000, -65536),
19
+ (0x0001, 0x0000, 0xFFFF, -2147418113),
20
+ ]:
21
+ with self.subTest(sev=sev, fac=fac, code=code, hr=hr):
22
+ self.assertEqual(comtypes.hresult.MAKE_HRESULT(sev, fac, code), hr)
23
+
24
+
25
+ ERROR_OUTOFMEMORY = 14 # 0xE
26
+ ERROR_INVALID_PARAMETER = 87 # 0x57
27
+ RPC_S_SERVER_UNAVAILABLE = 1722 # 0x6BA
28
+
29
+
30
+ class Test_HRESULT_FROM_WIN32(ut.TestCase):
31
+ def test(self):
32
+ for w32, hr in [
33
+ (ERROR_OUTOFMEMORY, comtypes.hresult.E_OUTOFMEMORY),
34
+ (ERROR_INVALID_PARAMETER, comtypes.hresult.E_INVALIDARG),
35
+ (RPC_S_SERVER_UNAVAILABLE, comtypes.hresult.RPC_S_SERVER_UNAVAILABLE),
36
+ (-1, -1),
37
+ (0, -2147024896),
38
+ (1, -2147024895),
39
+ (0xFFFF - 3, -2146959364),
40
+ (0xFFFF - 2, -2146959363),
41
+ (0xFFFF - 1, -2146959362),
42
+ (0xFFFF + 0, -2146959361),
43
+ (0xFFFF + 1, -2147024896),
44
+ (0xFFFF + 2, -2147024895),
45
+ (0xFFFF + 3, -2147024894),
46
+ ]:
47
+ with self.subTest(w32=w32, hr=hr):
48
+ self.assertEqual(comtypes.hresult.HRESULT_FROM_WIN32(w32), hr)