comtypes 1.4.8__zip → 1.4.10__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 (154) hide show
  1. {comtypes-1.4.8 → comtypes-1.4.10}/CHANGES.txt +40 -0
  2. {comtypes-1.4.8/comtypes.egg-info → comtypes-1.4.10}/PKG-INFO +4 -3
  3. {comtypes-1.4.8 → comtypes-1.4.10}/README.md +1 -1
  4. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/GUID.py +38 -16
  5. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/__init__.py +36 -16
  6. comtypes-1.4.10/comtypes/_comobject.py +562 -0
  7. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_memberspec.py +93 -13
  8. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_meta.py +1 -0
  9. comtypes-1.4.10/comtypes/_post_coinit/_cominterface_meta_patcher.py +152 -0
  10. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_post_coinit/bstr.py +12 -5
  11. comtypes-1.4.8/comtypes/_py_instance_method.py → comtypes-1.4.10/comtypes/_post_coinit/instancemethod.py +1 -2
  12. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_post_coinit/misc.py +60 -25
  13. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_post_coinit/unknwn.py +26 -176
  14. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_safearray.py +3 -4
  15. comtypes-1.4.10/comtypes/_vtbl.py +448 -0
  16. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/automation.py +46 -49
  17. comtypes-1.4.10/comtypes/client/__init__.py +42 -0
  18. comtypes-1.4.10/comtypes/client/_activeobj.py +46 -0
  19. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/_code_cache.py +10 -5
  20. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/_constants.py +1 -1
  21. comtypes-1.4.10/comtypes/client/_create.py +147 -0
  22. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/_events.py +58 -13
  23. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/_generate.py +7 -11
  24. comtypes-1.4.10/comtypes/client/_managing.py +114 -0
  25. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/dynamic.py +2 -3
  26. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/lazybind.py +12 -13
  27. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/connectionpoints.py +2 -1
  28. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/errorinfo.py +22 -9
  29. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/git.py +5 -5
  30. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/hints.pyi +7 -15
  31. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/logutil.py +15 -3
  32. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/messageloop.py +1 -1
  33. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/persist.py +3 -5
  34. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/safearray.py +17 -5
  35. comtypes-1.4.10/comtypes/server/__init__.py +104 -0
  36. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/server/automation.py +1 -2
  37. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/server/connectionpoints.py +5 -5
  38. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/server/inprocserver.py +25 -17
  39. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/server/localserver.py +49 -19
  40. comtypes-1.4.10/comtypes/server/register.py +478 -0
  41. comtypes-1.4.10/comtypes/server/w_getopt.py +48 -0
  42. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/shelllink.py +16 -33
  43. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/stream.py +7 -4
  44. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestComServer.py +6 -7
  45. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestDispServer.py +4 -2
  46. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/__init__.py +10 -12
  47. comtypes-1.4.10/comtypes/test/find_memleak.py +72 -0
  48. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/runtests.py +1 -0
  49. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/setup.py +2 -1
  50. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_BSTR.py +10 -23
  51. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_GUID.py +1 -0
  52. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_QueryService.py +1 -0
  53. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_agilent.py +4 -3
  54. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_avmc.py +1 -1
  55. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_basic.py +12 -6
  56. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_casesensitivity.py +3 -5
  57. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_clear_cache.py +1 -1
  58. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_client.py +2 -2
  59. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_client_dynamic.py +2 -2
  60. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_client_regenerate_modules.py +2 -2
  61. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_collections.py +4 -4
  62. comtypes-1.4.10/comtypes/test/test_comobject.py +146 -0
  63. comtypes-1.4.10/comtypes/test/test_comserver.py +349 -0
  64. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_createwrappers.py +2 -4
  65. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_dispifc_records.py +1 -1
  66. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_dispifc_safearrays.py +1 -1
  67. comtypes-1.4.10/comtypes/test/test_dispinterface.py +153 -0
  68. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_dyndispatch.py +1 -0
  69. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_excel.py +22 -12
  70. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_findgendir.py +1 -2
  71. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_getactiveobj.py +4 -4
  72. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_ie.py +19 -9
  73. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_ienum.py +2 -2
  74. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_imfattributes.py +13 -3
  75. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_inout_args.py +8 -5
  76. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_midl_safearray_create.py +14 -4
  77. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_monikers.py +23 -9
  78. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_msscript.py +2 -1
  79. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_npsupport.py +4 -4
  80. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_outparam.py +37 -14
  81. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_persist.py +2 -4
  82. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_recordinfo.py +1 -1
  83. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_safearray.py +1 -90
  84. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_sapi.py +4 -1
  85. comtypes-1.4.10/comtypes/test/test_server.py +350 -0
  86. comtypes-1.4.10/comtypes/test/test_server_register.py +524 -0
  87. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_shelllink.py +2 -3
  88. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_showevents.py +7 -17
  89. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_storage.py +12 -6
  90. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_stream.py +16 -5
  91. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_subinterface.py +4 -2
  92. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_typeannotator.py +1 -2
  93. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_typeinfo.py +19 -7
  94. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_urlhistory.py +7 -4
  95. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_variant.py +3 -19
  96. comtypes-1.4.10/comtypes/test/test_w_getopt.py +29 -0
  97. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_win32com_interop.py +80 -36
  98. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_wmi.py +0 -3
  99. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_word.py +1 -1
  100. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/codegenerator.py +166 -440
  101. comtypes-1.4.10/comtypes/tools/codegenerator/comments.py +79 -0
  102. comtypes-1.4.10/comtypes/tools/codegenerator/heads.py +192 -0
  103. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/helpers.py +11 -14
  104. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/namespaces.py +13 -5
  105. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/packing.py +4 -4
  106. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/typeannotator.py +19 -9
  107. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/tlbparser.py +22 -23
  108. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/typedesc.py +4 -8
  109. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/typedesc_base.py +2 -2
  110. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/typeinfo.py +159 -63
  111. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/viewobject.py +3 -9
  112. {comtypes-1.4.8 → comtypes-1.4.10/comtypes.egg-info}/PKG-INFO +4 -3
  113. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes.egg-info/SOURCES.txt +11 -3
  114. {comtypes-1.4.8 → comtypes-1.4.10}/pyproject.toml +12 -19
  115. comtypes-1.4.8/comtypes/_comobject.py +0 -833
  116. comtypes-1.4.8/comtypes/_idl_stuff.py +0 -67
  117. comtypes-1.4.8/comtypes/client/__init__.py +0 -323
  118. comtypes-1.4.8/comtypes/server/__init__.py +0 -70
  119. comtypes-1.4.8/comtypes/server/register.py +0 -431
  120. comtypes-1.4.8/comtypes/server/w_getopt.py +0 -75
  121. comtypes-1.4.8/comtypes/test/find_memleak.py +0 -76
  122. comtypes-1.4.8/comtypes/test/test_comserver.py +0 -239
  123. comtypes-1.4.8/comtypes/test/test_dispinterface.py +0 -137
  124. comtypes-1.4.8/comtypes/test/test_propputref.py +0 -40
  125. comtypes-1.4.8/comtypes/test/test_server.py +0 -354
  126. {comtypes-1.4.8 → comtypes-1.4.10}/LICENSE.txt +0 -0
  127. {comtypes-1.4.8 → comtypes-1.4.10}/MANIFEST.in +0 -0
  128. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_npsupport.py +0 -0
  129. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_post_coinit/__init__.py +0 -0
  130. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_tlib_version_checker.py +0 -0
  131. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/clear_cache.py +0 -0
  132. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/hresult.py +0 -0
  133. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/patcher.py +0 -0
  134. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestComServer.idl +0 -0
  135. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestComServer.tlb +0 -0
  136. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestDispServer.idl +0 -0
  137. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestDispServer.tlb +0 -0
  138. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/mylib.idl +0 -0
  139. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/mylib.tlb +0 -0
  140. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/mytypelib.idl +0 -0
  141. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_DISPPARAMS.py +0 -0
  142. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_dict.py +0 -0
  143. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_jscript.js +0 -0
  144. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_pump_events.py +0 -0
  145. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/urlhist.tlb +0 -0
  146. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/__init__.py +0 -0
  147. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/__init__.py +0 -0
  148. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/modulenamer.py +0 -0
  149. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/util.py +0 -0
  150. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes.egg-info/dependency_links.txt +0 -0
  151. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes.egg-info/entry_points.txt +0 -0
  152. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes.egg-info/top_level.txt +0 -0
  153. {comtypes-1.4.8 → comtypes-1.4.10}/setup.cfg +0 -0
  154. {comtypes-1.4.8 → comtypes-1.4.10}/setup.py +0 -0
@@ -5,12 +5,11 @@ from comtypes.tools.codegenerator import typeannotator
5
5
  from comtypes.tools.tlbparser import (
6
6
  BSTR_type,
7
7
  HRESULT_type,
8
- VARIANT_type,
9
8
  VARIANT_BOOL_type,
9
+ VARIANT_type,
10
10
  void_type,
11
11
  )
12
12
 
13
-
14
13
  iunknown_type = typedesc.ComInterface(
15
14
  "IUnknown", None, "{00000000-0000-0000-C000-000000000046}", ["hidden"], None
16
15
  )
@@ -1,15 +1,15 @@
1
- import os
1
+ import ctypes
2
+ import sys
2
3
  import unittest
3
- from ctypes import POINTER, byref
4
+
4
5
  from comtypes import GUID, COMError
5
- from comtypes.automation import DISPATCH_METHOD
6
6
  from comtypes.typeinfo import (
7
- LoadTypeLibEx,
7
+ TKIND_DISPATCH,
8
+ TKIND_INTERFACE,
9
+ GetModuleFileName,
8
10
  LoadRegTypeLib,
11
+ LoadTypeLibEx,
9
12
  QueryPathOfRegTypeLib,
10
- TKIND_INTERFACE,
11
- TKIND_DISPATCH,
12
- TKIND_ENUM,
13
13
  )
14
14
 
15
15
 
@@ -94,5 +94,17 @@ class Test(unittest.TestCase):
94
94
  self.assertEqual(guid, ti.GetTypeAttr().guid)
95
95
 
96
96
 
97
+ class Test_GetModuleFileName(unittest.TestCase):
98
+ def test_null_handler(self):
99
+ self.assertEqual(GetModuleFileName(None, 260), sys.executable)
100
+
101
+ def test_loaded_module_handle(self):
102
+ import _ctypes
103
+
104
+ dll_path = _ctypes.__file__
105
+ hmodule = ctypes.WinDLL(dll_path)._handle
106
+ self.assertEqual(GetModuleFileName(hmodule, 260), dll_path)
107
+
108
+
97
109
  if __name__ == "__main__":
98
110
  unittest.main()
@@ -1,7 +1,10 @@
1
- import unittest, os
1
+ import os
2
+ import unittest
2
3
  from copy import copy
3
4
  from ctypes import *
4
- from comtypes.client import GetModule, CreateObject
5
+
6
+ from comtypes.client import CreateObject, GetModule
7
+ from comtypes.GUID import _CoTaskMemFree
5
8
  from comtypes.patcher import Patch
6
9
 
7
10
  # ./urlhist.tlb was downloaded somewhere from the internet (?)
@@ -23,8 +26,8 @@ class _(object):
23
26
  for n, _ in self._fields_:
24
27
  setattr(result, n, getattr(self, n))
25
28
  url, title = self.pwcsUrl, self.pwcsTitle
26
- windll.ole32.CoTaskMemFree(cast_field(self, "pwcsUrl", c_void_p))
27
- windll.ole32.CoTaskMemFree(cast_field(self, "pwcsTitle", c_void_p))
29
+ _CoTaskMemFree(cast_field(self, "pwcsUrl", c_void_p))
30
+ _CoTaskMemFree(cast_field(self, "pwcsTitle", c_void_p))
28
31
  return result
29
32
 
30
33
 
@@ -194,23 +194,6 @@ class VariantTestCase(unittest.TestCase):
194
194
  v.value = ""
195
195
  self.assertEqual(v.vt, VT_BSTR)
196
196
 
197
- @unittest.skip(
198
- "Fails on creating `TestComServerLib.TestComServer`. Library not registered."
199
- )
200
- def test_UDT(self):
201
- from comtypes.gen.TestComServerLib import MYCOLOR
202
-
203
- v = VARIANT(MYCOLOR(red=1.0, green=2.0, blue=3.0))
204
- value = v.value
205
- self.assertEqual((1.0, 2.0, 3.0), (value.red, value.green, value.blue))
206
-
207
- def func():
208
- v = VARIANT(MYCOLOR(red=1.0, green=2.0, blue=3.0))
209
- return v.value
210
-
211
- bytes = find_memleak(func)
212
- self.assertFalse(bytes, "Leaks %d bytes" % bytes)
213
-
214
197
  def test_ctypes_in_variant(self):
215
198
  v = VARIANT()
216
199
  objs = [
@@ -310,9 +293,10 @@ def run_test(rep, msg, func=None, previous={}, results={}):
310
293
 
311
294
 
312
295
  def check_perf(rep=20000):
313
- from ctypes import c_int, byref
314
- from comtypes.automation import VARIANT
296
+ from ctypes import byref, c_int
297
+
315
298
  import comtypes.automation
299
+ from comtypes.automation import VARIANT
316
300
 
317
301
  print(comtypes.automation)
318
302
  variable = c_int()
@@ -0,0 +1,29 @@
1
+ import unittest
2
+
3
+ from comtypes.server.w_getopt import GetoptError, w_getopt
4
+
5
+
6
+ class TestCase(unittest.TestCase):
7
+ def test_1(self):
8
+ args = "-embedding spam /RegServer foo /UnregSERVER blabla".split()
9
+ opts, args = w_getopt(args, "regserver unregserver embedding".split())
10
+ self.assertEqual(
11
+ opts, [("embedding", ""), ("regserver", ""), ("unregserver", "")]
12
+ )
13
+ self.assertEqual(args, ["spam", "foo", "blabla"])
14
+
15
+ def test_2(self):
16
+ args = "/TLB Hello.Tlb HELLO.idl".split()
17
+ opts, args = w_getopt(args, ["tlb:"])
18
+ self.assertEqual(opts, [("tlb", "Hello.Tlb")])
19
+ self.assertEqual(args, ["HELLO.idl"])
20
+
21
+ def test_3(self):
22
+ # Invalid option
23
+ self.assertRaises(
24
+ GetoptError, w_getopt, "/TLIB hello.tlb hello.idl".split(), ["tlb:"]
25
+ )
26
+
27
+ def test_4(self):
28
+ # Missing argument
29
+ self.assertRaises(GetoptError, w_getopt, "/TLB".split(), ["tlb:"])
@@ -1,19 +1,37 @@
1
1
  import unittest
2
-
3
- from ctypes import PyDLL, py_object, c_void_p, byref, POINTER
2
+ from ctypes import POINTER, PyDLL, byref, c_void_p, py_object
4
3
  from ctypes.wintypes import BOOL
5
4
 
6
- from comtypes import IUnknown
5
+ from comtypes import COMObject, IUnknown
6
+ from comtypes.automation import VARIANT, IDispatch
7
7
  from comtypes.client import CreateObject
8
- from comtypes.automation import IDispatch
9
- from comtypes.test import requires
10
8
 
11
- requires("pythoncom")
12
9
  try:
13
10
  import pythoncom
14
11
  import win32com.client
15
12
 
16
- skip = False
13
+ IMPORT_FAILED = False
14
+ # pywin32 is available. The pythoncom dll contains two handy
15
+ # exported functions that allow to create a VARIANT from a Python
16
+ # object, also a function that unpacks a VARIANT into a Python
17
+ # object.
18
+ #
19
+ # This allows us to create und unpack SAFEARRAY instances
20
+ # contained in VARIANTs, and check for consistency with the
21
+ # comtypes code.
22
+ _dll = PyDLL(pythoncom.__file__)
23
+
24
+ # c:/sf/pywin32/com/win32com/src/oleargs.cpp 213
25
+ # PyObject *PyCom_PyObjectFromVariant(const VARIANT *var)
26
+ unpack = _dll.PyCom_PyObjectFromVariant
27
+ unpack.restype = py_object
28
+ unpack.argtypes = (POINTER(VARIANT),)
29
+
30
+ # c:/sf/pywin32/com/win32com/src/oleargs.cpp 54
31
+ # BOOL PyCom_VariantFromPyObject(PyObject *obj, VARIANT *var)
32
+ _pack = _dll.PyCom_VariantFromPyObject
33
+ _pack.argtypes = py_object, POINTER(VARIANT)
34
+ _pack.restype = BOOL
17
35
  # We use the PyCom_PyObjectFromIUnknown function in pythoncom25.dll to
18
36
  # convert a comtypes COM pointer into a pythoncom COM pointer.
19
37
  # Fortunately this function is exported by the dll...
@@ -30,17 +48,58 @@ except ImportError:
30
48
  # if it is available since pythoncom is not a project dependency and adding tests depending
31
49
  # on the vagaries of various testing environments is not deterministic.
32
50
  # TODO: Evaluate if we should just remove this test or what.
33
- skip = True
51
+ IMPORT_FAILED = True
34
52
 
35
53
 
36
54
  def setUpModule():
37
- if skip:
55
+ if IMPORT_FAILED:
38
56
  raise unittest.SkipTest(
39
57
  "This test requires the pythoncom library installed. If this is "
40
58
  "important tests then we need to add dev dependencies to the project that include pythoncom."
41
59
  )
42
60
 
43
61
 
62
+ ################################################################
63
+
64
+
65
+ def pack(obj):
66
+ var = VARIANT()
67
+ _pack(obj, byref(var))
68
+ return var
69
+
70
+
71
+ class PyWinSafeArrayTest(unittest.TestCase):
72
+ def test_1dim(self):
73
+ data = (1, 2, 3)
74
+ variant = pack(data)
75
+ self.assertEqual(variant.value, data)
76
+ self.assertEqual(unpack(variant), data)
77
+
78
+ def test_2dim(self):
79
+ data = ((1, 2, 3), (4, 5, 6), (7, 8, 9))
80
+ variant = pack(data)
81
+ self.assertEqual(variant.value, data)
82
+ self.assertEqual(unpack(variant), data)
83
+
84
+ def test_3dim(self):
85
+ data = (((1, 2), (3, 4), (5, 6)), ((7, 8), (9, 10), (11, 12)))
86
+ variant = pack(data)
87
+ self.assertEqual(variant.value, data)
88
+ self.assertEqual(unpack(variant), data)
89
+
90
+ def test_4dim(self):
91
+ data = (
92
+ (((1, 2), (3, 4)), ((5, 6), (7, 8))),
93
+ (((9, 10), (11, 12)), ((13, 14), (15, 16))),
94
+ )
95
+ variant = pack(data)
96
+ self.assertEqual(variant.value, data)
97
+ self.assertEqual(unpack(variant), data)
98
+
99
+
100
+ ################################################################
101
+
102
+
44
103
  def comtypes2pywin(ptr, interface=None):
45
104
  """Convert a comtypes pointer 'ptr' into a pythoncom
46
105
  PyI<interface> object.
@@ -56,9 +115,6 @@ def comtypes2pywin(ptr, interface=None):
56
115
  return _PyCom_PyObjectFromIUnknown(ptr, byref(interface._iid_), True)
57
116
 
58
117
 
59
- ################################################################
60
-
61
-
62
118
  def comtypes_get_refcount(ptr):
63
119
  """Helper function for testing: return the COM reference count of
64
120
  a comtypes COM object"""
@@ -66,9 +122,6 @@ def comtypes_get_refcount(ptr):
66
122
  return ptr.Release()
67
123
 
68
124
 
69
- from comtypes import COMObject
70
-
71
-
72
125
  class MyComObject(COMObject):
73
126
  """A completely trivial COM object implementing IDispatch. Calling
74
127
  any methods will return the error code E_NOTIMPL (except the
@@ -77,42 +130,33 @@ class MyComObject(COMObject):
77
130
  _com_interfaces_ = [IDispatch]
78
131
 
79
132
 
80
- ################################################################
81
-
82
-
83
- class Test(unittest.TestCase):
84
- def tearDown(self):
85
- if hasattr(self, "ie"):
86
- self.ie.Quit()
87
- del self.ie
88
-
133
+ class ConvertComtypesPtrToPythonComObjTest(unittest.TestCase):
89
134
  def test_mycomobject(self):
90
135
  o = MyComObject()
91
136
  p = comtypes2pywin(o, IDispatch)
92
137
  disp = win32com.client.Dispatch(p)
93
138
  self.assertEqual(repr(disp), "<COMObject <unknown>>")
94
139
 
95
- def test_ie(self):
96
- # Convert a comtypes COM interface pointer into a win32com COM
97
- # pointer.
98
- ie = self.ie = CreateObject("InternetExplorer.Application")
140
+ def test_refcount(self):
141
+ # Convert a comtypes COM interface pointer into a win32com COM pointer.
142
+ dic = CreateObject("Scripting.Dictionary")
99
143
  # The COM refcount of the created object is 1:
100
- self.assertEqual(comtypes_get_refcount(ie), 1)
101
- # IE starts invisible:
102
- self.assertEqual(ie.Visible, False)
144
+ self.assertEqual(comtypes_get_refcount(dic), 1)
145
+ dic["foo"] = "bar"
146
+ self.assertEqual(dic.Item("foo"), "bar")
103
147
 
104
148
  # Create a pythoncom PyIDispatch object from it:
105
- p = comtypes2pywin(ie, interface=IDispatch)
106
- self.assertEqual(comtypes_get_refcount(ie), 2)
149
+ p = comtypes2pywin(dic, interface=IDispatch)
150
+ self.assertEqual(comtypes_get_refcount(dic), 2)
107
151
 
108
152
  # Make it usable...
109
153
  disp = win32com.client.Dispatch(p)
110
- self.assertEqual(comtypes_get_refcount(ie), 2)
111
- self.assertEqual(disp.Visible, False)
154
+ self.assertEqual(comtypes_get_refcount(dic), 2)
155
+ self.assertEqual(disp.Item("foo"), "bar")
112
156
 
113
157
  # Cleanup and make sure that the COM refcounts are correct
114
158
  del p, disp
115
- self.assertEqual(comtypes_get_refcount(ie), 1)
159
+ self.assertEqual(comtypes_get_refcount(dic), 1)
116
160
 
117
161
 
118
162
  if __name__ == "__main__":
@@ -1,9 +1,6 @@
1
1
  import unittest as ut
2
2
 
3
3
  from comtypes.client import CoGetObject
4
- from comtypes.test import requires
5
-
6
- requires("time")
7
4
 
8
5
 
9
6
  # WMI has dual interfaces.
@@ -1,8 +1,8 @@
1
1
  import time
2
2
  import unittest
3
3
 
4
- from comtypes import COMError
5
4
  import comtypes.client
5
+ from comtypes import COMError
6
6
 
7
7
  try:
8
8
  comtypes.client.GetModule(