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.
- {comtypes-1.4.8 → comtypes-1.4.10}/CHANGES.txt +40 -0
- {comtypes-1.4.8/comtypes.egg-info → comtypes-1.4.10}/PKG-INFO +4 -3
- {comtypes-1.4.8 → comtypes-1.4.10}/README.md +1 -1
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/GUID.py +38 -16
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/__init__.py +36 -16
- comtypes-1.4.10/comtypes/_comobject.py +562 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_memberspec.py +93 -13
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_meta.py +1 -0
- comtypes-1.4.10/comtypes/_post_coinit/_cominterface_meta_patcher.py +152 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_post_coinit/bstr.py +12 -5
- comtypes-1.4.8/comtypes/_py_instance_method.py → comtypes-1.4.10/comtypes/_post_coinit/instancemethod.py +1 -2
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_post_coinit/misc.py +60 -25
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_post_coinit/unknwn.py +26 -176
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_safearray.py +3 -4
- comtypes-1.4.10/comtypes/_vtbl.py +448 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/automation.py +46 -49
- comtypes-1.4.10/comtypes/client/__init__.py +42 -0
- comtypes-1.4.10/comtypes/client/_activeobj.py +46 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/_code_cache.py +10 -5
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/_constants.py +1 -1
- comtypes-1.4.10/comtypes/client/_create.py +147 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/_events.py +58 -13
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/_generate.py +7 -11
- comtypes-1.4.10/comtypes/client/_managing.py +114 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/dynamic.py +2 -3
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/lazybind.py +12 -13
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/connectionpoints.py +2 -1
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/errorinfo.py +22 -9
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/git.py +5 -5
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/hints.pyi +7 -15
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/logutil.py +15 -3
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/messageloop.py +1 -1
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/persist.py +3 -5
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/safearray.py +17 -5
- comtypes-1.4.10/comtypes/server/__init__.py +104 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/server/automation.py +1 -2
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/server/connectionpoints.py +5 -5
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/server/inprocserver.py +25 -17
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/server/localserver.py +49 -19
- comtypes-1.4.10/comtypes/server/register.py +478 -0
- comtypes-1.4.10/comtypes/server/w_getopt.py +48 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/shelllink.py +16 -33
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/stream.py +7 -4
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestComServer.py +6 -7
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestDispServer.py +4 -2
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/__init__.py +10 -12
- comtypes-1.4.10/comtypes/test/find_memleak.py +72 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/runtests.py +1 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/setup.py +2 -1
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_BSTR.py +10 -23
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_GUID.py +1 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_QueryService.py +1 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_agilent.py +4 -3
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_avmc.py +1 -1
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_basic.py +12 -6
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_casesensitivity.py +3 -5
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_clear_cache.py +1 -1
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_client.py +2 -2
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_client_dynamic.py +2 -2
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_client_regenerate_modules.py +2 -2
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_collections.py +4 -4
- comtypes-1.4.10/comtypes/test/test_comobject.py +146 -0
- comtypes-1.4.10/comtypes/test/test_comserver.py +349 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_createwrappers.py +2 -4
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_dispifc_records.py +1 -1
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_dispifc_safearrays.py +1 -1
- comtypes-1.4.10/comtypes/test/test_dispinterface.py +153 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_dyndispatch.py +1 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_excel.py +22 -12
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_findgendir.py +1 -2
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_getactiveobj.py +4 -4
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_ie.py +19 -9
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_ienum.py +2 -2
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_imfattributes.py +13 -3
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_inout_args.py +8 -5
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_midl_safearray_create.py +14 -4
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_monikers.py +23 -9
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_msscript.py +2 -1
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_npsupport.py +4 -4
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_outparam.py +37 -14
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_persist.py +2 -4
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_recordinfo.py +1 -1
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_safearray.py +1 -90
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_sapi.py +4 -1
- comtypes-1.4.10/comtypes/test/test_server.py +350 -0
- comtypes-1.4.10/comtypes/test/test_server_register.py +524 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_shelllink.py +2 -3
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_showevents.py +7 -17
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_storage.py +12 -6
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_stream.py +16 -5
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_subinterface.py +4 -2
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_typeannotator.py +1 -2
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_typeinfo.py +19 -7
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_urlhistory.py +7 -4
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_variant.py +3 -19
- comtypes-1.4.10/comtypes/test/test_w_getopt.py +29 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_win32com_interop.py +80 -36
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_wmi.py +0 -3
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_word.py +1 -1
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/codegenerator.py +166 -440
- comtypes-1.4.10/comtypes/tools/codegenerator/comments.py +79 -0
- comtypes-1.4.10/comtypes/tools/codegenerator/heads.py +192 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/helpers.py +11 -14
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/namespaces.py +13 -5
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/packing.py +4 -4
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/typeannotator.py +19 -9
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/tlbparser.py +22 -23
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/typedesc.py +4 -8
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/typedesc_base.py +2 -2
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/typeinfo.py +159 -63
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/viewobject.py +3 -9
- {comtypes-1.4.8 → comtypes-1.4.10/comtypes.egg-info}/PKG-INFO +4 -3
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes.egg-info/SOURCES.txt +11 -3
- {comtypes-1.4.8 → comtypes-1.4.10}/pyproject.toml +12 -19
- comtypes-1.4.8/comtypes/_comobject.py +0 -833
- comtypes-1.4.8/comtypes/_idl_stuff.py +0 -67
- comtypes-1.4.8/comtypes/client/__init__.py +0 -323
- comtypes-1.4.8/comtypes/server/__init__.py +0 -70
- comtypes-1.4.8/comtypes/server/register.py +0 -431
- comtypes-1.4.8/comtypes/server/w_getopt.py +0 -75
- comtypes-1.4.8/comtypes/test/find_memleak.py +0 -76
- comtypes-1.4.8/comtypes/test/test_comserver.py +0 -239
- comtypes-1.4.8/comtypes/test/test_dispinterface.py +0 -137
- comtypes-1.4.8/comtypes/test/test_propputref.py +0 -40
- comtypes-1.4.8/comtypes/test/test_server.py +0 -354
- {comtypes-1.4.8 → comtypes-1.4.10}/LICENSE.txt +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/MANIFEST.in +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_npsupport.py +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_post_coinit/__init__.py +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_tlib_version_checker.py +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/clear_cache.py +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/hresult.py +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/patcher.py +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestComServer.idl +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestComServer.tlb +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestDispServer.idl +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestDispServer.tlb +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/mylib.idl +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/mylib.tlb +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/mytypelib.idl +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_DISPPARAMS.py +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_dict.py +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_jscript.js +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_pump_events.py +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/urlhist.tlb +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/__init__.py +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/__init__.py +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/modulenamer.py +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/util.py +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes.egg-info/dependency_links.txt +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes.egg-info/entry_points.txt +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/comtypes.egg-info/top_level.txt +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/setup.cfg +0 -0
- {comtypes-1.4.8 → comtypes-1.4.10}/setup.py +0 -0
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
import _ctypes
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
import unittest as ut
|
|
5
|
+
import winreg
|
|
6
|
+
from unittest import mock
|
|
7
|
+
|
|
8
|
+
import comtypes
|
|
9
|
+
import comtypes.server.inprocserver
|
|
10
|
+
from comtypes import GUID
|
|
11
|
+
from comtypes.server import register
|
|
12
|
+
from comtypes.server.register import (
|
|
13
|
+
FrozenRegistryEntries,
|
|
14
|
+
InterpRegistryEntries,
|
|
15
|
+
Registrar,
|
|
16
|
+
_delete_key,
|
|
17
|
+
_get_serverdll,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
HKCR = winreg.HKEY_CLASSES_ROOT
|
|
21
|
+
MULTI_SZ = winreg.REG_MULTI_SZ
|
|
22
|
+
SZ = winreg.REG_SZ
|
|
23
|
+
|
|
24
|
+
ERROR_ACCESS_DENIED = 5
|
|
25
|
+
ERROR_FILE_NOT_FOUND = 2
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@mock.patch.object(register, "SHDeleteKey")
|
|
29
|
+
@mock.patch.object(register, "winreg")
|
|
30
|
+
class Test_delete_key(ut.TestCase):
|
|
31
|
+
def test_calls_sh_deletekey_if_forced(self, _winreg, _sh_deletekey):
|
|
32
|
+
_delete_key(123, "subkey", force=True)
|
|
33
|
+
_winreg.DeleteKey.assert_not_called()
|
|
34
|
+
_sh_deletekey.assert_called_once_with(123, "subkey")
|
|
35
|
+
|
|
36
|
+
def test_calls_winreg_deletekey_if_not_forced(self, _winreg, _sh_deletekey):
|
|
37
|
+
_delete_key(123, "subkey", force=False)
|
|
38
|
+
_winreg.DeleteKey.assert_called_once_with(123, "subkey")
|
|
39
|
+
_sh_deletekey.assert_not_called()
|
|
40
|
+
|
|
41
|
+
def test_ignores_error_on_sh_deletekey(self, _winreg, _sh_deletekey):
|
|
42
|
+
err = OSError(ERROR_FILE_NOT_FOUND, "msg", "filename", ERROR_FILE_NOT_FOUND)
|
|
43
|
+
_sh_deletekey.side_effect = err
|
|
44
|
+
_delete_key(123, "subkey", force=True)
|
|
45
|
+
_winreg.DeleteKey.assert_not_called()
|
|
46
|
+
_sh_deletekey.assert_called_once_with(123, "subkey")
|
|
47
|
+
|
|
48
|
+
def test_ignores_error_on_winreg_deletekey(self, _winreg, _sh_deletekey):
|
|
49
|
+
err = OSError(ERROR_FILE_NOT_FOUND, "msg", "filename", ERROR_FILE_NOT_FOUND)
|
|
50
|
+
_winreg.DeleteKey.side_effect = err
|
|
51
|
+
_delete_key(123, "subkey", force=False)
|
|
52
|
+
_winreg.DeleteKey.assert_called_once_with(123, "subkey")
|
|
53
|
+
_sh_deletekey.assert_not_called()
|
|
54
|
+
|
|
55
|
+
def test_not_ignores_winerror_on_sh_deletekey(self, _winreg, _sh_deletekey):
|
|
56
|
+
err = OSError(ERROR_ACCESS_DENIED, "msg", "filename", ERROR_ACCESS_DENIED)
|
|
57
|
+
_sh_deletekey.side_effect = err
|
|
58
|
+
with self.assertRaises(OSError) as e:
|
|
59
|
+
_delete_key(123, "subkey", force=True)
|
|
60
|
+
self.assertEqual(e.exception.winerror, ERROR_ACCESS_DENIED)
|
|
61
|
+
_winreg.DeleteKey.assert_not_called()
|
|
62
|
+
_sh_deletekey.assert_called_once_with(123, "subkey")
|
|
63
|
+
|
|
64
|
+
def test_not_ignores_winerror_on_winreg_deletekey(self, _winreg, _sh_deletekey):
|
|
65
|
+
err = OSError(ERROR_ACCESS_DENIED, "msg", "filename", ERROR_ACCESS_DENIED)
|
|
66
|
+
_winreg.DeleteKey.side_effect = err
|
|
67
|
+
with self.assertRaises(OSError) as e:
|
|
68
|
+
_delete_key(123, "subkey", force=False)
|
|
69
|
+
self.assertEqual(e.exception.winerror, ERROR_ACCESS_DENIED)
|
|
70
|
+
_winreg.DeleteKey.assert_called_once_with(123, "subkey")
|
|
71
|
+
_sh_deletekey.assert_not_called()
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@mock.patch.object(register, "winreg")
|
|
75
|
+
class Test_Registrar_nodebug(ut.TestCase):
|
|
76
|
+
def test_calls_openkey_and_deletekey(self, _winreg):
|
|
77
|
+
hkey = mock.Mock(spec=winreg.HKEYType)
|
|
78
|
+
_winreg.OpenKey.return_value = hkey
|
|
79
|
+
reg_clsid = GUID.create_new()
|
|
80
|
+
registrar = Registrar()
|
|
81
|
+
|
|
82
|
+
class Cls:
|
|
83
|
+
_reg_clsid_ = reg_clsid
|
|
84
|
+
|
|
85
|
+
registrar.nodebug(Cls)
|
|
86
|
+
_winreg.OpenKey.assert_called_once_with(HKCR, rf"CLSID\{reg_clsid}")
|
|
87
|
+
_winreg.DeleteKey.assert_called_once_with(hkey, "Logging")
|
|
88
|
+
|
|
89
|
+
def test_ignores_winerror(self, _winreg):
|
|
90
|
+
err = OSError(ERROR_FILE_NOT_FOUND, "msg", "filename", ERROR_FILE_NOT_FOUND)
|
|
91
|
+
_winreg.OpenKey.side_effect = err
|
|
92
|
+
reg_clsid = GUID.create_new()
|
|
93
|
+
registrar = Registrar()
|
|
94
|
+
|
|
95
|
+
class Cls:
|
|
96
|
+
_reg_clsid_ = reg_clsid
|
|
97
|
+
|
|
98
|
+
registrar.nodebug(Cls)
|
|
99
|
+
_winreg.OpenKey.assert_called_once_with(HKCR, rf"CLSID\{reg_clsid}")
|
|
100
|
+
_winreg.DeleteKey.assert_not_called()
|
|
101
|
+
|
|
102
|
+
def test_not_ignores_winerror(self, _winreg):
|
|
103
|
+
hkey = mock.Mock(spec=winreg.HKEYType)
|
|
104
|
+
_winreg.OpenKey.return_value = hkey
|
|
105
|
+
err = OSError(ERROR_ACCESS_DENIED, "msg", "filename", ERROR_ACCESS_DENIED)
|
|
106
|
+
_winreg.OpenKey.return_value = hkey
|
|
107
|
+
_winreg.DeleteKey.side_effect = err
|
|
108
|
+
reg_clsid = GUID.create_new()
|
|
109
|
+
registrar = Registrar()
|
|
110
|
+
|
|
111
|
+
class Cls:
|
|
112
|
+
_reg_clsid_ = reg_clsid
|
|
113
|
+
|
|
114
|
+
with self.assertRaises(OSError) as e:
|
|
115
|
+
registrar.nodebug(Cls)
|
|
116
|
+
self.assertEqual(e.exception.winerror, ERROR_ACCESS_DENIED)
|
|
117
|
+
_winreg.OpenKey.assert_called_once_with(HKCR, rf"CLSID\{reg_clsid}")
|
|
118
|
+
_winreg.DeleteKey.assert_called_once_with(hkey, "Logging")
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@mock.patch.object(register, "winreg")
|
|
122
|
+
class Test_Registrar_debug(ut.TestCase):
|
|
123
|
+
def test_calls_createkey_and_sets_format(self, _winreg):
|
|
124
|
+
_winreg.REG_MULTI_SZ = MULTI_SZ
|
|
125
|
+
_winreg.REG_SZ = SZ
|
|
126
|
+
hkey = mock.Mock(spec=winreg.HKEYType)
|
|
127
|
+
_winreg.CreateKey.return_value = hkey
|
|
128
|
+
levels = ["lv=DEBUG"]
|
|
129
|
+
format = "FMT"
|
|
130
|
+
reg_clsid = GUID.create_new()
|
|
131
|
+
registrar = Registrar()
|
|
132
|
+
|
|
133
|
+
class Cls:
|
|
134
|
+
_reg_clsid_ = reg_clsid
|
|
135
|
+
|
|
136
|
+
registrar.debug(Cls, levels, format)
|
|
137
|
+
_winreg.CreateKey.assert_called_once_with(HKCR, rf"CLSID\{reg_clsid}\Logging")
|
|
138
|
+
self.assertEqual(
|
|
139
|
+
_winreg.SetValueEx.call_args_list,
|
|
140
|
+
[
|
|
141
|
+
mock.call(hkey, "levels", None, MULTI_SZ, levels),
|
|
142
|
+
mock.call(hkey, "format", None, SZ, format),
|
|
143
|
+
],
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
def test_calls_createkey_and_deletes_format(self, _winreg):
|
|
147
|
+
_winreg.REG_MULTI_SZ = MULTI_SZ
|
|
148
|
+
hkey = mock.Mock(spec=winreg.HKEYType)
|
|
149
|
+
_winreg.CreateKey.return_value = hkey
|
|
150
|
+
levels = ["lv=DEBUG"]
|
|
151
|
+
reg_clsid = GUID.create_new()
|
|
152
|
+
registrar = Registrar()
|
|
153
|
+
|
|
154
|
+
class Cls:
|
|
155
|
+
_reg_clsid_ = reg_clsid
|
|
156
|
+
|
|
157
|
+
registrar.debug(Cls, levels, None)
|
|
158
|
+
_winreg.CreateKey.assert_called_once_with(HKCR, rf"CLSID\{reg_clsid}\Logging")
|
|
159
|
+
_winreg.SetValueEx.assert_called_once_with(
|
|
160
|
+
hkey, "levels", None, MULTI_SZ, levels
|
|
161
|
+
)
|
|
162
|
+
_winreg.DeleteValue.assert_called_once_with(hkey, "format")
|
|
163
|
+
|
|
164
|
+
def test_calls_createkey_and_ignores_errors_on_deleting(self, _winreg):
|
|
165
|
+
_winreg.REG_MULTI_SZ = MULTI_SZ
|
|
166
|
+
hkey = mock.Mock(spec=winreg.HKEYType)
|
|
167
|
+
_winreg.CreateKey.return_value = hkey
|
|
168
|
+
err = OSError(ERROR_FILE_NOT_FOUND, "msg", "filename", ERROR_FILE_NOT_FOUND)
|
|
169
|
+
_winreg.DeleteValue.side_effect = err
|
|
170
|
+
levels = ["lv=DEBUG"]
|
|
171
|
+
reg_clsid = GUID.create_new()
|
|
172
|
+
registrar = Registrar()
|
|
173
|
+
|
|
174
|
+
class Cls:
|
|
175
|
+
_reg_clsid_ = reg_clsid
|
|
176
|
+
|
|
177
|
+
registrar.debug(Cls, levels, None)
|
|
178
|
+
_winreg.CreateKey.assert_called_once_with(HKCR, rf"CLSID\{reg_clsid}\Logging")
|
|
179
|
+
_winreg.SetValueEx.assert_called_once_with(
|
|
180
|
+
hkey, "levels", None, MULTI_SZ, levels
|
|
181
|
+
)
|
|
182
|
+
_winreg.DeleteValue.assert_called_once_with(hkey, "format")
|
|
183
|
+
|
|
184
|
+
def test_calls_createkey_and_not_ignores_errors_on_deleting(self, _winreg):
|
|
185
|
+
_winreg.REG_MULTI_SZ = MULTI_SZ
|
|
186
|
+
hkey = mock.Mock(spec=winreg.HKEYType)
|
|
187
|
+
_winreg.CreateKey.return_value = hkey
|
|
188
|
+
err = OSError(ERROR_ACCESS_DENIED, "msg", "filename", ERROR_ACCESS_DENIED)
|
|
189
|
+
_winreg.DeleteValue.side_effect = err
|
|
190
|
+
levels = ["lv=DEBUG"]
|
|
191
|
+
reg_clsid = GUID.create_new()
|
|
192
|
+
registrar = Registrar()
|
|
193
|
+
|
|
194
|
+
class Cls:
|
|
195
|
+
_reg_clsid_ = reg_clsid
|
|
196
|
+
|
|
197
|
+
with self.assertRaises(OSError) as e:
|
|
198
|
+
registrar.debug(Cls, levels, None)
|
|
199
|
+
self.assertEqual(e.exception.winerror, ERROR_ACCESS_DENIED)
|
|
200
|
+
_winreg.CreateKey.assert_called_once_with(HKCR, rf"CLSID\{reg_clsid}\Logging")
|
|
201
|
+
_winreg.SetValueEx.assert_called_once_with(
|
|
202
|
+
hkey, "levels", None, MULTI_SZ, levels
|
|
203
|
+
)
|
|
204
|
+
_winreg.DeleteValue.assert_called_once_with(hkey, "format")
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
class Test_Registrar_register(ut.TestCase):
|
|
208
|
+
def test_calls_cls_register(self):
|
|
209
|
+
cls = mock.Mock(spec=["_register"])
|
|
210
|
+
registrar = Registrar()
|
|
211
|
+
registrar.register(cls)
|
|
212
|
+
cls._register.assert_called_once_with(registrar)
|
|
213
|
+
|
|
214
|
+
# The coverage for COM server registration is ensured by the setup
|
|
215
|
+
# of `test_comserver` and `test_dispinterface`, so no additional tests
|
|
216
|
+
# are performed here now.
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
class Test_Registrar_unregister(ut.TestCase):
|
|
220
|
+
def test_calls_cls_unregister(self):
|
|
221
|
+
cls = mock.Mock(spec=["_unregister"])
|
|
222
|
+
registrar = Registrar()
|
|
223
|
+
registrar.unregister(cls)
|
|
224
|
+
cls._unregister.assert_called_once_with(registrar)
|
|
225
|
+
|
|
226
|
+
# The coverage for COM server unregistration is ensured by the teardown
|
|
227
|
+
# of `test_comserver` and `test_dispinterface`, so no additional tests
|
|
228
|
+
# are performed here now.
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
class Test_get_serverdll(ut.TestCase):
|
|
232
|
+
@mock.patch.object(register, "GetModuleFileName")
|
|
233
|
+
def test_frozen(self, GetModuleFileName):
|
|
234
|
+
handle, dll_path = 1234, r"path\to\frozen.dll"
|
|
235
|
+
GetModuleFileName.return_value = dll_path
|
|
236
|
+
self.assertEqual(dll_path, _get_serverdll(handle))
|
|
237
|
+
(((hmodule, maxsize), _),) = GetModuleFileName.call_args_list
|
|
238
|
+
self.assertEqual(handle, hmodule)
|
|
239
|
+
self.assertEqual(260, maxsize)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
class Test_InterpRegistryEntries(ut.TestCase):
|
|
243
|
+
def test_reg_clsid(self):
|
|
244
|
+
reg_clsid = GUID.create_new()
|
|
245
|
+
|
|
246
|
+
class Cls:
|
|
247
|
+
_reg_clsid_ = reg_clsid
|
|
248
|
+
|
|
249
|
+
expected = [(HKCR, rf"CLSID\{reg_clsid}", "", "")]
|
|
250
|
+
self.assertEqual(expected, list(InterpRegistryEntries(Cls)))
|
|
251
|
+
|
|
252
|
+
def test_reg_desc(self):
|
|
253
|
+
reg_clsid = GUID.create_new()
|
|
254
|
+
reg_desc = "description for testing"
|
|
255
|
+
|
|
256
|
+
class Cls:
|
|
257
|
+
_reg_clsid_ = reg_clsid
|
|
258
|
+
_reg_desc_ = reg_desc
|
|
259
|
+
|
|
260
|
+
expected = [(HKCR, rf"CLSID\{reg_clsid}", "", reg_desc)]
|
|
261
|
+
self.assertEqual(expected, list(InterpRegistryEntries(Cls)))
|
|
262
|
+
|
|
263
|
+
def test_reg_novers_progid(self):
|
|
264
|
+
reg_clsid = GUID.create_new()
|
|
265
|
+
reg_novers_progid = "Lib.Server"
|
|
266
|
+
|
|
267
|
+
class Cls:
|
|
268
|
+
_reg_clsid_ = reg_clsid
|
|
269
|
+
_reg_novers_progid_ = reg_novers_progid
|
|
270
|
+
|
|
271
|
+
expected = [(HKCR, rf"CLSID\{reg_clsid}", "", "Lib Server")]
|
|
272
|
+
self.assertEqual(expected, list(InterpRegistryEntries(Cls)))
|
|
273
|
+
|
|
274
|
+
def test_progid(self):
|
|
275
|
+
reg_clsid = GUID.create_new()
|
|
276
|
+
reg_progid = "Lib.Server.1"
|
|
277
|
+
|
|
278
|
+
class Cls:
|
|
279
|
+
_reg_clsid_ = reg_clsid
|
|
280
|
+
_reg_progid_ = reg_progid
|
|
281
|
+
|
|
282
|
+
expected = [
|
|
283
|
+
(HKCR, rf"CLSID\{reg_clsid}", "", "Lib Server 1"),
|
|
284
|
+
(HKCR, rf"CLSID\{reg_clsid}\ProgID", "", reg_progid),
|
|
285
|
+
(HKCR, reg_progid, "", "Lib Server 1"),
|
|
286
|
+
(HKCR, rf"{reg_progid}\CLSID", "", str(reg_clsid)),
|
|
287
|
+
]
|
|
288
|
+
self.assertEqual(expected, list(InterpRegistryEntries(Cls)))
|
|
289
|
+
|
|
290
|
+
def test_reg_progid_reg_desc(self):
|
|
291
|
+
reg_clsid = GUID.create_new()
|
|
292
|
+
reg_progid = "Lib.Server.1"
|
|
293
|
+
reg_desc = "description for testing"
|
|
294
|
+
|
|
295
|
+
class Cls:
|
|
296
|
+
_reg_clsid_ = reg_clsid
|
|
297
|
+
_reg_progid_ = reg_progid
|
|
298
|
+
_reg_desc_ = reg_desc
|
|
299
|
+
|
|
300
|
+
expected = [
|
|
301
|
+
(HKCR, rf"CLSID\{reg_clsid}", "", reg_desc),
|
|
302
|
+
(HKCR, rf"CLSID\{reg_clsid}\ProgID", "", reg_progid),
|
|
303
|
+
(HKCR, reg_progid, "", "description for testing"),
|
|
304
|
+
(HKCR, rf"{reg_progid}\CLSID", "", str(reg_clsid)),
|
|
305
|
+
]
|
|
306
|
+
self.assertEqual(expected, list(InterpRegistryEntries(Cls)))
|
|
307
|
+
|
|
308
|
+
def test_reg_progid_reg_novers_progid(self):
|
|
309
|
+
reg_clsid = GUID.create_new()
|
|
310
|
+
reg_progid = "Lib.Server.1"
|
|
311
|
+
reg_novers_progid = "Lib.Server"
|
|
312
|
+
|
|
313
|
+
class Cls:
|
|
314
|
+
_reg_clsid_ = reg_clsid
|
|
315
|
+
_reg_progid_ = reg_progid
|
|
316
|
+
_reg_novers_progid_ = reg_novers_progid
|
|
317
|
+
|
|
318
|
+
clsid_sub = rf"CLSID\{reg_clsid}"
|
|
319
|
+
expected = [
|
|
320
|
+
(HKCR, clsid_sub, "", "Lib Server"),
|
|
321
|
+
(HKCR, rf"{clsid_sub}\ProgID", "", reg_progid),
|
|
322
|
+
(HKCR, reg_progid, "", "Lib Server"),
|
|
323
|
+
(HKCR, rf"{reg_progid}\CLSID", "", str(reg_clsid)),
|
|
324
|
+
(HKCR, rf"{clsid_sub}\VersionIndependentProgID", "", reg_novers_progid),
|
|
325
|
+
(HKCR, reg_novers_progid, "", "Lib Server"),
|
|
326
|
+
(HKCR, rf"{reg_novers_progid}\CurVer", "", "Lib.Server.1"),
|
|
327
|
+
(HKCR, rf"{reg_novers_progid}\CLSID", "", str(reg_clsid)),
|
|
328
|
+
]
|
|
329
|
+
self.assertEqual(expected, list(InterpRegistryEntries(Cls)))
|
|
330
|
+
|
|
331
|
+
def test_local_server(self):
|
|
332
|
+
reg_clsid = GUID.create_new()
|
|
333
|
+
reg_clsctx = comtypes.CLSCTX_LOCAL_SERVER
|
|
334
|
+
|
|
335
|
+
class Cls:
|
|
336
|
+
_reg_clsid_ = reg_clsid
|
|
337
|
+
_reg_clsctx_ = reg_clsctx
|
|
338
|
+
|
|
339
|
+
clsid_sub = rf"CLSID\{reg_clsid}"
|
|
340
|
+
local_srv_sub = rf"{clsid_sub}\LocalServer32"
|
|
341
|
+
expected = [
|
|
342
|
+
(HKCR, clsid_sub, "", ""),
|
|
343
|
+
(HKCR, local_srv_sub, "", f"{sys.executable} {__file__}"),
|
|
344
|
+
]
|
|
345
|
+
self.assertEqual(expected, list(InterpRegistryEntries(Cls)))
|
|
346
|
+
|
|
347
|
+
def test_inproc_server(self):
|
|
348
|
+
reg_clsid = GUID.create_new()
|
|
349
|
+
reg_clsctx = comtypes.CLSCTX_INPROC_SERVER
|
|
350
|
+
|
|
351
|
+
class Cls:
|
|
352
|
+
_reg_clsid_ = reg_clsid
|
|
353
|
+
_reg_clsctx_ = reg_clsctx
|
|
354
|
+
|
|
355
|
+
clsid_sub = rf"CLSID\{reg_clsid}"
|
|
356
|
+
inproc_srv_sub = rf"{clsid_sub}\InprocServer32"
|
|
357
|
+
full_classname = f"{__name__}.Cls"
|
|
358
|
+
expected = [
|
|
359
|
+
(HKCR, clsid_sub, "", ""),
|
|
360
|
+
(HKCR, inproc_srv_sub, "", _ctypes.__file__),
|
|
361
|
+
(HKCR, inproc_srv_sub, "PythonClass", full_classname),
|
|
362
|
+
(HKCR, inproc_srv_sub, "PythonPath", os.path.dirname(__file__)),
|
|
363
|
+
]
|
|
364
|
+
self.assertEqual(expected, list(InterpRegistryEntries(Cls)))
|
|
365
|
+
|
|
366
|
+
def test_inproc_server_reg_threading(self):
|
|
367
|
+
reg_clsid = GUID.create_new()
|
|
368
|
+
reg_threading = "Both"
|
|
369
|
+
reg_clsctx = comtypes.CLSCTX_INPROC_SERVER
|
|
370
|
+
|
|
371
|
+
class Cls:
|
|
372
|
+
_reg_clsid_ = reg_clsid
|
|
373
|
+
_reg_threading_ = reg_threading
|
|
374
|
+
_reg_clsctx_ = reg_clsctx
|
|
375
|
+
|
|
376
|
+
clsid_sub = rf"CLSID\{reg_clsid}"
|
|
377
|
+
inproc_srv_sub = rf"{clsid_sub}\InprocServer32"
|
|
378
|
+
full_classname = f"{__name__}.Cls"
|
|
379
|
+
expected = [
|
|
380
|
+
(HKCR, clsid_sub, "", ""),
|
|
381
|
+
(HKCR, inproc_srv_sub, "", _ctypes.__file__),
|
|
382
|
+
(HKCR, inproc_srv_sub, "PythonClass", full_classname),
|
|
383
|
+
(HKCR, inproc_srv_sub, "PythonPath", os.path.dirname(__file__)),
|
|
384
|
+
(HKCR, inproc_srv_sub, "ThreadingModel", reg_threading),
|
|
385
|
+
]
|
|
386
|
+
self.assertEqual(expected, list(InterpRegistryEntries(Cls)))
|
|
387
|
+
|
|
388
|
+
def test_reg_typelib(self):
|
|
389
|
+
reg_clsid = GUID.create_new()
|
|
390
|
+
libid = str(GUID.create_new())
|
|
391
|
+
reg_typelib = (libid, 1, 0)
|
|
392
|
+
|
|
393
|
+
class Cls:
|
|
394
|
+
_reg_clsid_ = reg_clsid
|
|
395
|
+
_reg_typelib_ = reg_typelib
|
|
396
|
+
|
|
397
|
+
expected = [
|
|
398
|
+
(HKCR, rf"CLSID\{reg_clsid}", "", ""),
|
|
399
|
+
(HKCR, rf"CLSID\{reg_clsid}\Typelib", "", libid),
|
|
400
|
+
]
|
|
401
|
+
self.assertEqual(expected, list(InterpRegistryEntries(Cls)))
|
|
402
|
+
|
|
403
|
+
def test_all_entries(self):
|
|
404
|
+
reg_clsid = GUID.create_new()
|
|
405
|
+
libid = str(GUID.create_new())
|
|
406
|
+
reg_typelib = (libid, 1, 0)
|
|
407
|
+
reg_threading = "Both"
|
|
408
|
+
reg_progid = "Lib.Server.1"
|
|
409
|
+
reg_novers_progid = "Lib.Server"
|
|
410
|
+
reg_desc = "description for testing"
|
|
411
|
+
reg_clsctx = comtypes.CLSCTX_INPROC_SERVER | comtypes.CLSCTX_LOCAL_SERVER
|
|
412
|
+
|
|
413
|
+
class Cls:
|
|
414
|
+
_reg_clsid_ = reg_clsid
|
|
415
|
+
_reg_typelib_ = reg_typelib
|
|
416
|
+
_reg_threading_ = reg_threading
|
|
417
|
+
_reg_progid_ = reg_progid
|
|
418
|
+
_reg_novers_progid_ = reg_novers_progid
|
|
419
|
+
_reg_desc_ = reg_desc
|
|
420
|
+
_reg_clsctx_ = reg_clsctx
|
|
421
|
+
|
|
422
|
+
clsid_sub = rf"CLSID\{reg_clsid}"
|
|
423
|
+
inproc_srv_sub = rf"{clsid_sub}\InprocServer32"
|
|
424
|
+
local_srv_sub = rf"{clsid_sub}\LocalServer32"
|
|
425
|
+
full_classname = f"{__name__}.Cls"
|
|
426
|
+
expected = [
|
|
427
|
+
(HKCR, clsid_sub, "", reg_desc),
|
|
428
|
+
(HKCR, rf"{clsid_sub}\ProgID", "", reg_progid),
|
|
429
|
+
(HKCR, reg_progid, "", reg_desc),
|
|
430
|
+
(HKCR, rf"{reg_progid}\CLSID", "", str(reg_clsid)),
|
|
431
|
+
(HKCR, rf"{clsid_sub}\VersionIndependentProgID", "", reg_novers_progid),
|
|
432
|
+
(HKCR, reg_novers_progid, "", reg_desc),
|
|
433
|
+
(HKCR, rf"{reg_novers_progid}\CurVer", "", reg_progid),
|
|
434
|
+
(HKCR, rf"{reg_novers_progid}\CLSID", "", str(reg_clsid)),
|
|
435
|
+
(HKCR, local_srv_sub, "", f"{sys.executable} {__file__}"),
|
|
436
|
+
(HKCR, inproc_srv_sub, "", _ctypes.__file__),
|
|
437
|
+
(HKCR, inproc_srv_sub, "PythonClass", full_classname),
|
|
438
|
+
(HKCR, inproc_srv_sub, "PythonPath", os.path.dirname(__file__)),
|
|
439
|
+
(HKCR, inproc_srv_sub, "ThreadingModel", reg_threading),
|
|
440
|
+
(HKCR, rf"{clsid_sub}\Typelib", "", libid),
|
|
441
|
+
]
|
|
442
|
+
self.assertEqual(expected, list(InterpRegistryEntries(Cls)))
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
class Test_FrozenRegistryEntries(ut.TestCase):
|
|
446
|
+
SERVERDLL = r"my\target\server.dll"
|
|
447
|
+
|
|
448
|
+
# We do not test the scenario where `frozen` is `'dll'` but
|
|
449
|
+
# `frozendllhandle` is `None`, as it is not a situation
|
|
450
|
+
# we anticipate.
|
|
451
|
+
|
|
452
|
+
def test_local_dll(self):
|
|
453
|
+
reg_clsid = GUID.create_new()
|
|
454
|
+
reg_clsctx = comtypes.CLSCTX_LOCAL_SERVER
|
|
455
|
+
|
|
456
|
+
class Cls:
|
|
457
|
+
_reg_clsid_ = reg_clsid
|
|
458
|
+
_reg_clsctx_ = reg_clsctx
|
|
459
|
+
|
|
460
|
+
# In such cases, the server does not start because the
|
|
461
|
+
# InprocServer32/LocalServer32 keys are not registered.
|
|
462
|
+
expected = [(HKCR, rf"CLSID\{reg_clsid}", "", "")]
|
|
463
|
+
entries = FrozenRegistryEntries(Cls, frozen="dll", frozendllhandle=1234)
|
|
464
|
+
self.assertEqual(expected, list(entries))
|
|
465
|
+
|
|
466
|
+
def test_local_windows_exe(self):
|
|
467
|
+
reg_clsid = GUID.create_new()
|
|
468
|
+
reg_clsctx = comtypes.CLSCTX_LOCAL_SERVER
|
|
469
|
+
|
|
470
|
+
class Cls:
|
|
471
|
+
_reg_clsid_ = reg_clsid
|
|
472
|
+
_reg_clsctx_ = reg_clsctx
|
|
473
|
+
|
|
474
|
+
expected = [
|
|
475
|
+
(HKCR, rf"CLSID\{reg_clsid}", "", ""),
|
|
476
|
+
(HKCR, rf"CLSID\{reg_clsid}\LocalServer32", "", sys.executable),
|
|
477
|
+
]
|
|
478
|
+
self.assertEqual(
|
|
479
|
+
expected, list(FrozenRegistryEntries(Cls, frozen="windows_exe"))
|
|
480
|
+
)
|
|
481
|
+
|
|
482
|
+
@mock.patch.object(register, "_get_serverdll", return_value=SERVERDLL)
|
|
483
|
+
def test_inproc_dll(self, get_serverdll):
|
|
484
|
+
reg_clsid = GUID.create_new()
|
|
485
|
+
reg_clsctx = comtypes.CLSCTX_INPROC_SERVER
|
|
486
|
+
|
|
487
|
+
class Cls:
|
|
488
|
+
_reg_clsid_ = reg_clsid
|
|
489
|
+
_reg_clsctx_ = reg_clsctx
|
|
490
|
+
|
|
491
|
+
clsid_sub = rf"CLSID\{reg_clsid}"
|
|
492
|
+
inproc_srv_sub = rf"{clsid_sub}\InprocServer32"
|
|
493
|
+
expected = [
|
|
494
|
+
(HKCR, clsid_sub, "", ""),
|
|
495
|
+
(HKCR, inproc_srv_sub, "", self.SERVERDLL),
|
|
496
|
+
]
|
|
497
|
+
|
|
498
|
+
entries = FrozenRegistryEntries(Cls, frozen="dll", frozendllhandle=1234)
|
|
499
|
+
self.assertEqual(expected, list(entries))
|
|
500
|
+
get_serverdll.assert_called_once_with(1234)
|
|
501
|
+
|
|
502
|
+
@mock.patch.object(register, "_get_serverdll", return_value=SERVERDLL)
|
|
503
|
+
def test_inproc_reg_threading(self, get_serverdll):
|
|
504
|
+
reg_clsid = GUID.create_new()
|
|
505
|
+
reg_threading = "Both"
|
|
506
|
+
reg_clsctx = comtypes.CLSCTX_INPROC_SERVER
|
|
507
|
+
|
|
508
|
+
class Cls:
|
|
509
|
+
_reg_clsid_ = reg_clsid
|
|
510
|
+
_reg_threading_ = reg_threading
|
|
511
|
+
_reg_clsctx_ = reg_clsctx
|
|
512
|
+
|
|
513
|
+
clsid_sub = rf"CLSID\{reg_clsid}"
|
|
514
|
+
inproc_srv_sub = rf"{clsid_sub}\InprocServer32"
|
|
515
|
+
expected = [
|
|
516
|
+
(HKCR, clsid_sub, "", ""),
|
|
517
|
+
(HKCR, inproc_srv_sub, "", self.SERVERDLL),
|
|
518
|
+
(HKCR, inproc_srv_sub, "ThreadingModel", reg_threading),
|
|
519
|
+
]
|
|
520
|
+
self.assertEqual(
|
|
521
|
+
expected,
|
|
522
|
+
list(FrozenRegistryEntries(Cls, frozen="dll", frozendllhandle=1234)),
|
|
523
|
+
)
|
|
524
|
+
get_serverdll.assert_called_once_with(1234)
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
from pathlib import Path
|
|
2
1
|
import tempfile
|
|
3
2
|
import unittest as ut
|
|
3
|
+
from pathlib import Path
|
|
4
4
|
|
|
5
|
-
from comtypes import CoCreateInstance, GUID, shelllink
|
|
6
5
|
import comtypes.hresult
|
|
6
|
+
from comtypes import GUID, CoCreateInstance, shelllink
|
|
7
7
|
from comtypes.persist import IPersistFile
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
CLSID_ShellLink = GUID("{00021401-0000-0000-C000-000000000046}")
|
|
11
10
|
|
|
12
11
|
|
|
@@ -1,24 +1,14 @@
|
|
|
1
1
|
import doctest
|
|
2
|
-
import sys
|
|
3
|
-
import re
|
|
4
2
|
import unittest
|
|
3
|
+
from typing import Optional
|
|
5
4
|
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if sys.version_info >= (3, 0):
|
|
11
|
-
want = re.sub(r"u'(.*?)'", r"'\1'", want)
|
|
12
|
-
want = re.sub(r'u"(.*?)"', r'"\1"', want)
|
|
13
|
-
return doctest.OutputChecker.check_output(self, want, got, optionflags)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def load_tests(loader, tests, ignore):
|
|
6
|
+
def load_tests(
|
|
7
|
+
loader: unittest.TestLoader, tests: unittest.TestSuite, pattern: Optional[str]
|
|
8
|
+
) -> unittest.TestSuite:
|
|
17
9
|
import comtypes.test.test_showevents
|
|
18
10
|
|
|
19
|
-
tests.addTests(
|
|
20
|
-
doctest.DocTestSuite(comtypes.test.test_showevents, checker=SixDocChecker())
|
|
21
|
-
)
|
|
11
|
+
tests.addTests(doctest.DocTestSuite(comtypes.test.test_showevents))
|
|
22
12
|
return tests
|
|
23
13
|
|
|
24
14
|
|
|
@@ -32,9 +22,9 @@ class ShowEventsExamples:
|
|
|
32
22
|
>>> conn = ShowEvents(font)
|
|
33
23
|
# event found: FontEvents_FontChanged
|
|
34
24
|
>>> font.Name = 'Arial'
|
|
35
|
-
Event FontEvents_FontChanged(None,
|
|
25
|
+
Event FontEvents_FontChanged(None, 'Name')
|
|
36
26
|
>>> font.Italic = True
|
|
37
|
-
Event FontEvents_FontChanged(None,
|
|
27
|
+
Event FontEvents_FontChanged(None, 'Italic')
|
|
38
28
|
>>> PumpEvents(0.01) # just calling. assertion does in `test_pump_events.py`
|
|
39
29
|
>>> conn.disconnect()
|
|
40
30
|
"""
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
from _ctypes import COMError
|
|
2
|
-
from ctypes import byref, c_ubyte, POINTER
|
|
3
1
|
import contextlib
|
|
4
|
-
from pathlib import Path
|
|
5
2
|
import unittest
|
|
3
|
+
from _ctypes import COMError
|
|
4
|
+
from ctypes import HRESULT, POINTER, OleDLL, byref, c_ubyte
|
|
5
|
+
from ctypes.wintypes import DWORD, PWCHAR
|
|
6
|
+
from pathlib import Path
|
|
6
7
|
|
|
7
8
|
import comtypes
|
|
8
9
|
import comtypes.client
|
|
9
10
|
|
|
10
|
-
|
|
11
11
|
with contextlib.redirect_stdout(None): # supress warnings
|
|
12
12
|
mod = comtypes.client.GetModule("msvidctl.dll")
|
|
13
13
|
|
|
14
14
|
from comtypes.gen.MSVidCtlLib import IStorage
|
|
15
15
|
|
|
16
|
-
|
|
17
16
|
STATFLAG_DEFAULT = 0
|
|
18
17
|
STGC_DEFAULT = 0
|
|
19
18
|
STGM_CREATE = 0x00001000
|
|
@@ -29,6 +28,13 @@ STREAM_SEEK_SET = 0
|
|
|
29
28
|
STG_E_PATHNOTFOUND = -2147287038
|
|
30
29
|
|
|
31
30
|
|
|
31
|
+
_ole32 = OleDLL("ole32")
|
|
32
|
+
|
|
33
|
+
_StgCreateDocfile = _ole32.StgCreateDocfile
|
|
34
|
+
_StgCreateDocfile.argtypes = [PWCHAR, DWORD, DWORD, POINTER(POINTER(IStorage))]
|
|
35
|
+
_StgCreateDocfile.restype = HRESULT
|
|
36
|
+
|
|
37
|
+
|
|
32
38
|
class Test_IStorage(unittest.TestCase):
|
|
33
39
|
CREATE_DOC_FLAG = (
|
|
34
40
|
STGM_DIRECT
|
|
@@ -44,7 +50,7 @@ class Test_IStorage(unittest.TestCase):
|
|
|
44
50
|
|
|
45
51
|
def _create_docfile(self) -> IStorage:
|
|
46
52
|
stg = POINTER(IStorage)()
|
|
47
|
-
|
|
53
|
+
_StgCreateDocfile(None, self.CREATE_DOC_FLAG, 0, byref(stg))
|
|
48
54
|
return stg # type: ignore
|
|
49
55
|
|
|
50
56
|
def test_CreateStream(self):
|
|
@@ -1,23 +1,34 @@
|
|
|
1
1
|
import unittest as ut
|
|
2
|
+
from ctypes import HRESULT, POINTER, OleDLL, byref, c_ubyte, c_ulonglong, pointer
|
|
3
|
+
from ctypes.wintypes import BOOL, HGLOBAL, ULARGE_INTEGER
|
|
2
4
|
|
|
3
|
-
from ctypes import POINTER, byref, c_bool, c_ubyte, c_ulonglong, oledll, pointer
|
|
4
|
-
import comtypes
|
|
5
5
|
import comtypes.client
|
|
6
6
|
|
|
7
7
|
comtypes.client.GetModule("portabledeviceapi.dll")
|
|
8
8
|
from comtypes.gen.PortableDeviceApiLib import IStream
|
|
9
9
|
|
|
10
|
-
|
|
11
10
|
STGC_DEFAULT = 0
|
|
12
11
|
STREAM_SEEK_SET = 0
|
|
13
12
|
STREAM_SEEK_CUR = 1
|
|
14
13
|
STREAM_SEEK_END = 2
|
|
15
14
|
|
|
15
|
+
_ole32 = OleDLL("ole32")
|
|
16
|
+
|
|
17
|
+
_CreateStreamOnHGlobal = _ole32.CreateStreamOnHGlobal
|
|
18
|
+
_CreateStreamOnHGlobal.argtypes = [HGLOBAL, BOOL, POINTER(POINTER(IStream))]
|
|
19
|
+
_CreateStreamOnHGlobal.restype = HRESULT
|
|
20
|
+
|
|
21
|
+
_shlwapi = OleDLL("shlwapi")
|
|
22
|
+
|
|
23
|
+
_IStream_Size = _shlwapi.IStream_Size
|
|
24
|
+
_IStream_Size.argtypes = [POINTER(IStream), POINTER(ULARGE_INTEGER)]
|
|
25
|
+
_IStream_Size.restype = HRESULT
|
|
26
|
+
|
|
16
27
|
|
|
17
28
|
def _create_stream() -> IStream:
|
|
18
29
|
# Create an IStream
|
|
19
30
|
stream = POINTER(IStream)() # type: ignore
|
|
20
|
-
|
|
31
|
+
_CreateStreamOnHGlobal(None, True, byref(stream))
|
|
21
32
|
return stream # type: ignore
|
|
22
33
|
|
|
23
34
|
|
|
@@ -92,7 +103,7 @@ class Test_SetSize(ut.TestCase):
|
|
|
92
103
|
stream = _create_stream()
|
|
93
104
|
stream.SetSize(42)
|
|
94
105
|
pui = pointer(c_ulonglong())
|
|
95
|
-
|
|
106
|
+
_IStream_Size(stream, pui)
|
|
96
107
|
self.assertEqual(pui.contents.value, 42)
|
|
97
108
|
|
|
98
109
|
|