comtypes 1.4.7__zip → 1.4.9__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.
- {comtypes-1.4.7 → comtypes-1.4.9}/CHANGES.txt +39 -0
- {comtypes-1.4.7/comtypes.egg-info → comtypes-1.4.9}/PKG-INFO +6 -4
- {comtypes-1.4.7 → comtypes-1.4.9}/README.md +5 -3
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/GUID.py +6 -5
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/__init__.py +16 -5
- comtypes-1.4.9/comtypes/_comobject.py +507 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/_memberspec.py +81 -9
- comtypes-1.4.9/comtypes/_meta.py +95 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/_npsupport.py +2 -1
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/_post_coinit/__init__.py +1 -0
- comtypes-1.4.9/comtypes/_post_coinit/_cominterface_meta_patcher.py +153 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/_post_coinit/misc.py +21 -40
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/_post_coinit/unknwn.py +88 -209
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/_safearray.py +1 -2
- comtypes-1.4.9/comtypes/_vtbl.py +448 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/automation.py +36 -45
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/client/__init__.py +21 -31
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/client/_code_cache.py +5 -4
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/client/_constants.py +1 -1
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/client/_events.py +1 -2
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/client/_generate.py +9 -13
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/client/lazybind.py +2 -7
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/errorinfo.py +3 -3
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/git.py +2 -2
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/hints.pyi +11 -19
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/persist.py +7 -7
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/safearray.py +12 -6
- comtypes-1.4.9/comtypes/server/__init__.py +86 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/server/inprocserver.py +22 -17
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/server/localserver.py +28 -16
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/server/register.py +62 -73
- comtypes-1.4.9/comtypes/server/w_getopt.py +48 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/shelllink.py +49 -67
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/TestComServer.py +1 -1
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/TestDispServer.py +1 -1
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/__init__.py +9 -12
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/find_memleak.py +0 -1
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_BSTR.py +4 -7
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_agilent.py +0 -1
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_avmc.py +1 -1
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_casesensitivity.py +3 -5
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_clear_cache.py +1 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_collections.py +3 -3
- comtypes-1.4.9/comtypes/test/test_comobject.py +146 -0
- comtypes-1.4.9/comtypes/test/test_comserver.py +319 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_createwrappers.py +2 -6
- comtypes-1.4.9/comtypes/test/test_dispinterface.py +153 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_excel.py +22 -13
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_ie.py +2 -5
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_inout_args.py +8 -5
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_midl_safearray_create.py +9 -1
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_outparam.py +17 -10
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_safearray.py +1 -90
- comtypes-1.4.9/comtypes/test/test_server.py +350 -0
- comtypes-1.4.9/comtypes/test/test_server_register.py +536 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_shelllink.py +10 -14
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_showevents.py +7 -17
- comtypes-1.4.9/comtypes/test/test_stream.py +131 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_typeannotator.py +1 -1
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_urlhistory.py +1 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_variant.py +0 -19
- comtypes-1.4.9/comtypes/test/test_w_getopt.py +29 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_win32com_interop.py +80 -36
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_wmi.py +0 -3
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/codegenerator/codegenerator.py +62 -68
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/codegenerator/helpers.py +8 -8
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/codegenerator/namespaces.py +97 -27
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/codegenerator/packing.py +4 -4
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/codegenerator/typeannotator.py +9 -11
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/tlbparser.py +33 -32
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/typedesc.py +3 -8
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/typeinfo.py +32 -47
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/util.py +1 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/viewobject.py +1 -5
- {comtypes-1.4.7 → comtypes-1.4.9/comtypes.egg-info}/PKG-INFO +6 -4
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes.egg-info/SOURCES.txt +6 -3
- comtypes-1.4.9/pyproject.toml +55 -0
- comtypes-1.4.7/comtypes/_comobject.py +0 -834
- comtypes-1.4.7/comtypes/_idl_stuff.py +0 -67
- comtypes-1.4.7/comtypes/_meta.py +0 -70
- comtypes-1.4.7/comtypes/server/__init__.py +0 -69
- comtypes-1.4.7/comtypes/server/w_getopt.py +0 -75
- comtypes-1.4.7/comtypes/test/test_comserver.py +0 -239
- comtypes-1.4.7/comtypes/test/test_dispinterface.py +0 -138
- comtypes-1.4.7/comtypes/test/test_propputref.py +0 -40
- comtypes-1.4.7/comtypes/test/test_server.py +0 -348
- comtypes-1.4.7/comtypes/test/test_stream.py +0 -53
- comtypes-1.4.7/pyproject.toml +0 -3
- {comtypes-1.4.7 → comtypes-1.4.9}/LICENSE.txt +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/MANIFEST.in +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/_post_coinit/bstr.py +0 -0
- /comtypes-1.4.7/comtypes/_py_instance_method.py → /comtypes-1.4.9/comtypes/_post_coinit/instancemethod.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/_tlib_version_checker.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/clear_cache.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/client/dynamic.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/connectionpoints.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/hresult.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/logutil.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/messageloop.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/patcher.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/server/automation.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/server/connectionpoints.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/stream.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/TestComServer.idl +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/TestComServer.tlb +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/TestDispServer.idl +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/TestDispServer.tlb +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/mylib.idl +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/mylib.tlb +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/mytypelib.idl +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/runtests.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/setup.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_DISPPARAMS.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_GUID.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_QueryService.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_basic.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_client.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_client_dynamic.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_client_regenerate_modules.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_dict.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_dispifc_records.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_dispifc_safearrays.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_dyndispatch.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_findgendir.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_getactiveobj.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_ienum.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_imfattributes.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_jscript.js +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_monikers.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_msscript.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_npsupport.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_persist.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_pump_events.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_recordinfo.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_sapi.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_storage.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_subinterface.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_typeinfo.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/test_word.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/test/urlhist.tlb +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/__init__.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/codegenerator/__init__.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/codegenerator/modulenamer.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes/tools/typedesc_base.py +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes.egg-info/dependency_links.txt +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes.egg-info/entry_points.txt +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/comtypes.egg-info/top_level.txt +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/setup.cfg +0 -0
- {comtypes-1.4.7 → comtypes-1.4.9}/setup.py +0 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import unittest
|
|
3
|
+
|
|
4
|
+
import comtypes.test.TestDispServer
|
|
5
|
+
from comtypes.server.register import register, unregister
|
|
6
|
+
|
|
7
|
+
try:
|
|
8
|
+
from win32com.client import Dispatch
|
|
9
|
+
from win32com.client.gencache import EnsureDispatch
|
|
10
|
+
|
|
11
|
+
IMPORT_PYWIN32_FAILED = False
|
|
12
|
+
except ImportError:
|
|
13
|
+
IMPORT_PYWIN32_FAILED = True
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def setUpModule():
|
|
17
|
+
try:
|
|
18
|
+
register(comtypes.test.TestDispServer.TestDispServer)
|
|
19
|
+
except WindowsError as e:
|
|
20
|
+
if e.winerror != 5: # [Error 5] Access is denied
|
|
21
|
+
raise e
|
|
22
|
+
raise unittest.SkipTest(
|
|
23
|
+
"This test requires the tests to be run as admin since it tries to "
|
|
24
|
+
"register the test COM server."
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def tearDownModule():
|
|
29
|
+
unregister(comtypes.test.TestDispServer.TestDispServer)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@unittest.skipIf(IMPORT_PYWIN32_FAILED, "This depends on 'pywin32'.")
|
|
33
|
+
class Test_win32com(unittest.TestCase):
|
|
34
|
+
@unittest.skip(
|
|
35
|
+
"It likely fails due to bugs in `GenerateChildFromTypeLibSpec` "
|
|
36
|
+
"or `GetModuleForCLSID`."
|
|
37
|
+
)
|
|
38
|
+
def test_win32com_ensure_dispatch(self):
|
|
39
|
+
# EnsureDispatch is case-sensitive
|
|
40
|
+
d = EnsureDispatch("TestDispServerLib.TestDispServer")
|
|
41
|
+
|
|
42
|
+
self.assertEqual(d.eval("3.14"), 3.14)
|
|
43
|
+
self.assertEqual(d.eval("1 + 2"), 3)
|
|
44
|
+
self.assertEqual(d.eval("[1 + 2, 'foo', None]"), (3, "foo", None))
|
|
45
|
+
|
|
46
|
+
self.assertEqual(d.eval2("3.14"), 3.14)
|
|
47
|
+
self.assertEqual(d.eval2("1 + 2"), 3)
|
|
48
|
+
self.assertEqual(d.eval2("[1 + 2, 'foo', None]"), (3, "foo", None))
|
|
49
|
+
|
|
50
|
+
d.eval(
|
|
51
|
+
"__import__('comtypes.client').client.CreateObject('Scripting.Dictionary')"
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
server_id = d.eval("id(self)")
|
|
55
|
+
self.assertEqual(d.id, server_id)
|
|
56
|
+
|
|
57
|
+
self.assertEqual(d.name, "spam, spam, spam")
|
|
58
|
+
|
|
59
|
+
d.SetName("foo bar")
|
|
60
|
+
self.assertEqual(d.name, "foo bar")
|
|
61
|
+
|
|
62
|
+
d.name = "blah"
|
|
63
|
+
self.assertEqual(d.name, "blah")
|
|
64
|
+
|
|
65
|
+
def test_win32com_dynamic_dispatch(self):
|
|
66
|
+
# dynamic Dispatch is case-IN-sensitive
|
|
67
|
+
d = Dispatch("TestDispServerLib.TestDispServer")
|
|
68
|
+
|
|
69
|
+
self.assertEqual(d.eval("3.14"), 3.14)
|
|
70
|
+
self.assertEqual(d.eval("1 + 2"), 3)
|
|
71
|
+
self.assertEqual(d.eval("[1 + 2, 'foo', None]"), (3, "foo", None))
|
|
72
|
+
|
|
73
|
+
self.assertEqual(d.eval2("3.14"), 3.14)
|
|
74
|
+
self.assertEqual(d.eval2("1 + 2"), 3)
|
|
75
|
+
self.assertEqual(d.eval2("[1 + 2, 'foo', None]"), (3, "foo", None))
|
|
76
|
+
|
|
77
|
+
d.eval(
|
|
78
|
+
"__import__('comtypes.client').client.CreateObject('Scripting.Dictionary')"
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
self.assertEqual(d.EVAL("3.14"), 3.14)
|
|
82
|
+
self.assertEqual(d.EVAL("1 + 2"), 3)
|
|
83
|
+
self.assertEqual(d.EVAL("[1 + 2, 'foo', None]"), (3, "foo", None))
|
|
84
|
+
|
|
85
|
+
self.assertEqual(d.EVAL2("3.14"), 3.14)
|
|
86
|
+
self.assertEqual(d.EVAL2("1 + 2"), 3)
|
|
87
|
+
self.assertEqual(d.EVAL2("[1 + 2, 'foo', None]"), (3, "foo", None))
|
|
88
|
+
|
|
89
|
+
server_id = d.eval("id(self)")
|
|
90
|
+
self.assertEqual(d.id, server_id)
|
|
91
|
+
self.assertEqual(d.ID, server_id)
|
|
92
|
+
|
|
93
|
+
self.assertEqual(d.Name, "spam, spam, spam")
|
|
94
|
+
self.assertEqual(d.nAME, "spam, spam, spam")
|
|
95
|
+
|
|
96
|
+
d.SetName("foo bar")
|
|
97
|
+
self.assertEqual(d.Name, "foo bar")
|
|
98
|
+
|
|
99
|
+
# fails. Why?
|
|
100
|
+
# d.name = "blah"
|
|
101
|
+
# self.assertEqual(d.Name, "blah")
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class Test_comtypes(unittest.TestCase):
|
|
105
|
+
def test_comtypes(self):
|
|
106
|
+
from comtypes.client import CreateObject
|
|
107
|
+
|
|
108
|
+
d = CreateObject("TestDispServerLib.TestDispServer")
|
|
109
|
+
|
|
110
|
+
self.assertEqual(d.eval("3.14"), 3.14)
|
|
111
|
+
self.assertEqual(d.eval("1 + 2"), 3)
|
|
112
|
+
self.assertEqual(d.eval("[1 + 2, 'foo', None]"), (3, "foo", None))
|
|
113
|
+
|
|
114
|
+
self.assertEqual(d.eval2("3.14"), 3.14)
|
|
115
|
+
self.assertEqual(d.eval2("1 + 2"), 3)
|
|
116
|
+
self.assertEqual(d.eval2("[1 + 2, 'foo', None]"), (3, "foo", None))
|
|
117
|
+
|
|
118
|
+
d.eval(
|
|
119
|
+
"__import__('comtypes.client').client.CreateObject('Scripting.Dictionary')"
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
self.assertEqual(d.EVAL("3.14"), 3.14)
|
|
123
|
+
self.assertEqual(d.EVAL("1 + 2"), 3)
|
|
124
|
+
self.assertEqual(d.EVAL("[1 + 2, 'foo', None]"), (3, "foo", None))
|
|
125
|
+
|
|
126
|
+
self.assertEqual(d.EVAL2("3.14"), 3.14)
|
|
127
|
+
self.assertEqual(d.EVAL2("1 + 2"), 3)
|
|
128
|
+
self.assertEqual(d.EVAL2("[1 + 2, 'foo', None]"), (3, "foo", None))
|
|
129
|
+
|
|
130
|
+
server_id = d.eval("id(self)")
|
|
131
|
+
self.assertEqual(d.id, server_id)
|
|
132
|
+
self.assertEqual(d.ID, server_id)
|
|
133
|
+
|
|
134
|
+
self.assertEqual(d.Name, "spam, spam, spam")
|
|
135
|
+
self.assertEqual(d.nAME, "spam, spam, spam")
|
|
136
|
+
|
|
137
|
+
d.SetName("foo bar")
|
|
138
|
+
self.assertEqual(d.Name, "foo bar")
|
|
139
|
+
|
|
140
|
+
d.name = "blah"
|
|
141
|
+
self.assertEqual(d.Name, "blah")
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
@unittest.skip("This raises 'ClassFactory cannot supply requested class'. Why?")
|
|
145
|
+
class Test_jscript(unittest.TestCase):
|
|
146
|
+
def test_withjscript(self):
|
|
147
|
+
jscript = os.path.join(os.path.dirname(__file__), "test_jscript.js")
|
|
148
|
+
errcode = os.system("cscript -nologo %s" % jscript)
|
|
149
|
+
self.assertEqual(errcode, 0)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
if __name__ == "__main__":
|
|
153
|
+
unittest.main()
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- coding: latin-1 -*-
|
|
2
|
-
from __future__ import print_function
|
|
3
2
|
|
|
4
3
|
import datetime
|
|
5
4
|
import sys
|
|
6
5
|
import unittest
|
|
6
|
+
from typing import ClassVar
|
|
7
7
|
|
|
8
8
|
from comtypes.client import CreateObject, GetModule
|
|
9
9
|
|
|
@@ -28,6 +28,7 @@ except (ImportError, OSError):
|
|
|
28
28
|
|
|
29
29
|
class BaseBindTest(object):
|
|
30
30
|
# `dynamic = True/False` must be defined in subclasses!
|
|
31
|
+
dynamic: ClassVar[bool]
|
|
31
32
|
|
|
32
33
|
def setUp(self):
|
|
33
34
|
self.xl = CreateObject("Excel.Application", dynamic=self.dynamic)
|
|
@@ -63,17 +64,21 @@ class BaseBindTest(object):
|
|
|
63
64
|
# call property to retrieve value
|
|
64
65
|
expected_values = ((10.0, 20.0, 31.4), ("x", "y", "z"), (3.0, 2.0, 1.0))
|
|
65
66
|
# XXX: in Python >= 3.8.x, fails below
|
|
66
|
-
self.assertEqual(xl.Range["A1:C3"].Value(), expected_values)
|
|
67
|
+
self.assertEqual(xl.Range["A1:C3"].Value(), expected_values) # type: ignore
|
|
67
68
|
# index with empty tuple
|
|
68
|
-
self.assertEqual(xl.Range["A1:C3"].Value[()], expected_values)
|
|
69
|
+
self.assertEqual(xl.Range["A1:C3"].Value[()], expected_values) # type: ignore
|
|
69
70
|
# index with empty slice
|
|
70
|
-
self.assertEqual(xl.Range["A1:C3"].Value[:], expected_values)
|
|
71
|
-
self.assertEqual(
|
|
72
|
-
|
|
71
|
+
self.assertEqual(xl.Range["A1:C3"].Value[:], expected_values) # type: ignore
|
|
72
|
+
self.assertEqual( # type: ignore
|
|
73
|
+
xl.Range["A1:C3"].Value[xlRangeValueDefault], expected_values
|
|
74
|
+
)
|
|
75
|
+
self.assertEqual( # type: ignore
|
|
76
|
+
xl.Range["A1", "C3"].Value[()], expected_values
|
|
77
|
+
)
|
|
73
78
|
|
|
74
79
|
# Test for iteration support in "Range" interface
|
|
75
80
|
iter(xl.Range["A1:C3"])
|
|
76
|
-
self.assertEqual(
|
|
81
|
+
self.assertEqual( # type: ignore
|
|
77
82
|
[c.Value() for c in xl.Range["A1:C3"]],
|
|
78
83
|
[10.0, 20.0, 31.4, "x", "y", "z", 3.0, 2.0, 1.0],
|
|
79
84
|
)
|
|
@@ -84,25 +89,29 @@ class BaseBindTest(object):
|
|
|
84
89
|
for i in range(20):
|
|
85
90
|
val = "Hi %d" % i
|
|
86
91
|
xl.Cells.Item[i + 1, i + 1].Value[()] = val
|
|
87
|
-
self.assertEqual(
|
|
92
|
+
self.assertEqual( # type: ignore
|
|
93
|
+
xl.Cells.Item[i + 1, i + 1].Value[()], val
|
|
94
|
+
)
|
|
88
95
|
|
|
89
96
|
for i in range(20):
|
|
90
97
|
val = "Hi %d" % i
|
|
91
98
|
xl.Cells(i + 1, i + 1).Value[()] = val
|
|
92
|
-
self.assertEqual(xl.Cells(i + 1, i + 1).Value[()], val)
|
|
99
|
+
self.assertEqual(xl.Cells(i + 1, i + 1).Value[()], val) # type: ignore
|
|
93
100
|
|
|
94
101
|
# test dates out with Excel
|
|
95
102
|
xl.Range["A5"].Value[()] = "Excel time"
|
|
96
103
|
xl.Range["B5"].Formula = "=Now()"
|
|
97
|
-
self.assertEqual(xl.Cells.Item[5, 2].Formula, "=NOW()")
|
|
104
|
+
self.assertEqual(xl.Cells.Item[5, 2].Formula, "=NOW()") # type: ignore
|
|
98
105
|
|
|
99
106
|
xl.Range["A6"].Calculate()
|
|
100
107
|
excel_time = xl.Range["B5"].Value[()]
|
|
101
|
-
self.assertEqual(type(excel_time), datetime.datetime)
|
|
108
|
+
self.assertEqual(type(excel_time), datetime.datetime) # type: ignore
|
|
102
109
|
python_time = datetime.datetime.now()
|
|
103
110
|
|
|
104
|
-
self.assertTrue(python_time >= excel_time)
|
|
105
|
-
self.assertTrue(
|
|
111
|
+
self.assertTrue(python_time >= excel_time) # type: ignore
|
|
112
|
+
self.assertTrue( # type: ignore
|
|
113
|
+
python_time - excel_time < datetime.timedelta(seconds=1)
|
|
114
|
+
)
|
|
106
115
|
|
|
107
116
|
# some random code, grabbed from c.l.p
|
|
108
117
|
sh = wb.Worksheets[1]
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import unittest as ut
|
|
2
|
-
from ctypes import
|
|
2
|
+
from ctypes import Structure, c_long, c_uint, c_ulong
|
|
3
3
|
|
|
4
|
-
import comtypes.test
|
|
5
4
|
from comtypes.client import CreateObject, GetEvents
|
|
6
5
|
|
|
7
|
-
comtypes.test.requires("ui")
|
|
8
|
-
|
|
9
6
|
|
|
10
7
|
def setUpModule():
|
|
11
8
|
raise ut.SkipTest(
|
|
@@ -61,7 +58,7 @@ class MSG(Structure):
|
|
|
61
58
|
|
|
62
59
|
|
|
63
60
|
def PumpWaitingMessages():
|
|
64
|
-
from ctypes import
|
|
61
|
+
from ctypes import byref, windll
|
|
65
62
|
|
|
66
63
|
user32 = windll.user32
|
|
67
64
|
msg = MSG()
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
from typing import Any, Callable, List, NamedTuple, Tuple, Type
|
|
2
|
-
from ctypes import POINTER, pointer, Structure, HRESULT, c_ulong, c_wchar_p, c_int
|
|
3
1
|
import unittest as ut
|
|
2
|
+
from ctypes import HRESULT, POINTER, Structure, c_int, c_ulong, c_wchar_p, pointer
|
|
3
|
+
from typing import TYPE_CHECKING, Any, Callable, List, NamedTuple, Tuple, Type
|
|
4
4
|
from unittest.mock import MagicMock
|
|
5
5
|
|
|
6
6
|
import comtypes
|
|
7
|
+
from comtypes._memberspec import _fix_inout_args
|
|
7
8
|
from comtypes.client import IUnknown
|
|
8
|
-
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from comtypes._memberspec import _ArgSpecElmType
|
|
9
12
|
|
|
10
13
|
WSTRING = c_wchar_p
|
|
11
14
|
|
|
@@ -256,7 +259,7 @@ class Test_ArgsKwargsCombinations(ut.TestCase):
|
|
|
256
259
|
|
|
257
260
|
|
|
258
261
|
class PermutedArgspecTestingParams(NamedTuple):
|
|
259
|
-
argspec: Tuple[_ArgSpecElmType, _ArgSpecElmType, _ArgSpecElmType, _ArgSpecElmType]
|
|
262
|
+
argspec: "Tuple[_ArgSpecElmType, _ArgSpecElmType, _ArgSpecElmType, _ArgSpecElmType]"
|
|
260
263
|
args: Tuple[Any, Any, Any]
|
|
261
264
|
orig_ret_val: Tuple[Any, Any, Any]
|
|
262
265
|
fixed_ret_val: List[Any]
|
|
@@ -278,7 +281,7 @@ class Test_ArgspecPermutations(ut.TestCase):
|
|
|
278
281
|
(orig_0th, *orig_call_args), orig_kw = orig.call_args
|
|
279
282
|
self.assertEqual(orig_kw, {})
|
|
280
283
|
self.assertIs(orig_0th, self_)
|
|
281
|
-
for (
|
|
284
|
+
for (typ, f, val), orig in zip(
|
|
282
285
|
testing_params.call_args_validators, orig_call_args
|
|
283
286
|
):
|
|
284
287
|
self.assertIsInstance(orig, typ)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
|
|
3
|
-
from ctypes import c_int, pointer, POINTER
|
|
3
|
+
from ctypes import c_int, pointer, HRESULT, POINTER
|
|
4
4
|
import unittest
|
|
5
5
|
|
|
6
6
|
import comtypes
|
|
@@ -82,6 +82,14 @@ class Test_midlSAFEARRAY_create(unittest.TestCase):
|
|
|
82
82
|
self.assertEqual(unpacked.answer, 42)
|
|
83
83
|
self.assertEqual(unpacked.needs_clarification, True)
|
|
84
84
|
|
|
85
|
+
def test_HRESULT(self):
|
|
86
|
+
hr = HRESULT(1)
|
|
87
|
+
sa_type = comtypes.safearray._midlSAFEARRAY(HRESULT)
|
|
88
|
+
with self.assertRaises(TypeError):
|
|
89
|
+
sa_type.create([hr], extra=None)
|
|
90
|
+
with self.assertRaises(TypeError):
|
|
91
|
+
sa_type.create([hr])
|
|
92
|
+
|
|
85
93
|
def test_ctype(self):
|
|
86
94
|
extra = None
|
|
87
95
|
cdata = c_int(1)
|
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
import sys
|
|
2
1
|
import unittest
|
|
3
|
-
from ctypes import
|
|
2
|
+
from ctypes import (
|
|
3
|
+
POINTER,
|
|
4
|
+
byref,
|
|
5
|
+
c_int,
|
|
6
|
+
c_ulong,
|
|
7
|
+
c_void_p,
|
|
8
|
+
c_wchar,
|
|
9
|
+
c_wchar_p,
|
|
10
|
+
cast,
|
|
11
|
+
memmove,
|
|
12
|
+
oledll,
|
|
13
|
+
sizeof,
|
|
14
|
+
windll,
|
|
15
|
+
wstring_at,
|
|
16
|
+
)
|
|
4
17
|
from unittest.mock import patch
|
|
5
18
|
|
|
6
|
-
import
|
|
19
|
+
from comtypes import COMMETHOD, GUID, IUnknown
|
|
7
20
|
|
|
8
|
-
comtypes.test.requires("devel")
|
|
9
21
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if sys.version_info >= (3, 0):
|
|
13
|
-
text_type = str
|
|
14
|
-
else:
|
|
15
|
-
text_type = unicode
|
|
22
|
+
text_type = str
|
|
16
23
|
|
|
17
24
|
|
|
18
25
|
class IMalloc(IUnknown):
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import array
|
|
2
2
|
import datetime
|
|
3
3
|
import unittest
|
|
4
|
-
from ctypes import POINTER,
|
|
5
|
-
from ctypes.wintypes import BOOL
|
|
4
|
+
from ctypes import POINTER, c_long
|
|
6
5
|
from decimal import Decimal
|
|
7
6
|
|
|
8
7
|
from comtypes import BSTR, IUnknown
|
|
@@ -19,7 +18,6 @@ from comtypes.automation import (
|
|
|
19
18
|
_midlSAFEARRAY,
|
|
20
19
|
)
|
|
21
20
|
from comtypes.safearray import safearray_as_ndarray
|
|
22
|
-
from comtypes.test import is_resource_enabled
|
|
23
21
|
from comtypes.test.find_memleak import find_memleak
|
|
24
22
|
|
|
25
23
|
|
|
@@ -223,93 +221,6 @@ class SafeArrayTestCase(unittest.TestCase):
|
|
|
223
221
|
del sa
|
|
224
222
|
self.assertEqual((a, b), (com_refcnt(plib), com_refcnt(punk)))
|
|
225
223
|
|
|
226
|
-
@unittest.skip(
|
|
227
|
-
"This fails with a 'library not registered' error. Need to figure out how to "
|
|
228
|
-
"register TestComServerLib (without admin if possible)."
|
|
229
|
-
)
|
|
230
|
-
def test_UDT(self):
|
|
231
|
-
from comtypes.gen.TestComServerLib import MYCOLOR
|
|
232
|
-
|
|
233
|
-
t = _midlSAFEARRAY(MYCOLOR)
|
|
234
|
-
self.assertTrue(t is _midlSAFEARRAY(MYCOLOR))
|
|
235
|
-
|
|
236
|
-
sa = t.from_param([MYCOLOR(0, 0, 0), MYCOLOR(1, 2, 3)])
|
|
237
|
-
|
|
238
|
-
self.assertEqual(
|
|
239
|
-
[(x.red, x.green, x.blue) for x in sa[0]],
|
|
240
|
-
[(0.0, 0.0, 0.0), (1.0, 2.0, 3.0)],
|
|
241
|
-
)
|
|
242
|
-
|
|
243
|
-
def doit():
|
|
244
|
-
t.from_param([MYCOLOR(0, 0, 0), MYCOLOR(1, 2, 3)])
|
|
245
|
-
|
|
246
|
-
bytes = find_memleak(doit)
|
|
247
|
-
self.assertFalse(bytes, "Leaks %d bytes" % bytes)
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if is_resource_enabled("pythoncom"):
|
|
251
|
-
try:
|
|
252
|
-
import pythoncom
|
|
253
|
-
except ImportError:
|
|
254
|
-
# pywin32 not installed...
|
|
255
|
-
pass
|
|
256
|
-
else:
|
|
257
|
-
# pywin32 is available. The pythoncom dll contains two handy
|
|
258
|
-
# exported functions that allow to create a VARIANT from a Python
|
|
259
|
-
# object, also a function that unpacks a VARIANT into a Python
|
|
260
|
-
# object.
|
|
261
|
-
#
|
|
262
|
-
# This allows us to create und unpack SAFEARRAY instances
|
|
263
|
-
# contained in VARIANTs, and check for consistency with the
|
|
264
|
-
# comtypes code.
|
|
265
|
-
|
|
266
|
-
_dll = PyDLL(pythoncom.__file__)
|
|
267
|
-
|
|
268
|
-
# c:/sf/pywin32/com/win32com/src/oleargs.cpp 213
|
|
269
|
-
# PyObject *PyCom_PyObjectFromVariant(const VARIANT *var)
|
|
270
|
-
unpack = _dll.PyCom_PyObjectFromVariant
|
|
271
|
-
unpack.restype = py_object
|
|
272
|
-
unpack.argtypes = (POINTER(VARIANT),)
|
|
273
|
-
|
|
274
|
-
# c:/sf/pywin32/com/win32com/src/oleargs.cpp 54
|
|
275
|
-
# BOOL PyCom_VariantFromPyObject(PyObject *obj, VARIANT *var)
|
|
276
|
-
_pack = _dll.PyCom_VariantFromPyObject
|
|
277
|
-
_pack.argtypes = py_object, POINTER(VARIANT)
|
|
278
|
-
_pack.restype = BOOL
|
|
279
|
-
|
|
280
|
-
def pack(obj):
|
|
281
|
-
var = VARIANT()
|
|
282
|
-
_pack(obj, byref(var))
|
|
283
|
-
return var
|
|
284
|
-
|
|
285
|
-
class PyWinTest(unittest.TestCase):
|
|
286
|
-
def test_1dim(self):
|
|
287
|
-
data = (1, 2, 3)
|
|
288
|
-
variant = pack(data)
|
|
289
|
-
self.assertEqual(variant.value, data)
|
|
290
|
-
self.assertEqual(unpack(variant), data)
|
|
291
|
-
|
|
292
|
-
def test_2dim(self):
|
|
293
|
-
data = ((1, 2, 3), (4, 5, 6), (7, 8, 9))
|
|
294
|
-
variant = pack(data)
|
|
295
|
-
self.assertEqual(variant.value, data)
|
|
296
|
-
self.assertEqual(unpack(variant), data)
|
|
297
|
-
|
|
298
|
-
def test_3dim(self):
|
|
299
|
-
data = (((1, 2), (3, 4), (5, 6)), ((7, 8), (9, 10), (11, 12)))
|
|
300
|
-
variant = pack(data)
|
|
301
|
-
self.assertEqual(variant.value, data)
|
|
302
|
-
self.assertEqual(unpack(variant), data)
|
|
303
|
-
|
|
304
|
-
def test_4dim(self):
|
|
305
|
-
data = (
|
|
306
|
-
(((1, 2), (3, 4)), ((5, 6), (7, 8))),
|
|
307
|
-
(((9, 10), (11, 12)), ((13, 14), (15, 16))),
|
|
308
|
-
)
|
|
309
|
-
variant = pack(data)
|
|
310
|
-
self.assertEqual(variant.value, data)
|
|
311
|
-
self.assertEqual(unpack(variant), data)
|
|
312
|
-
|
|
313
224
|
|
|
314
225
|
if __name__ == "__main__":
|
|
315
226
|
unittest.main()
|