-
-
Notifications
You must be signed in to change notification settings - Fork 96
/
test_client.py
77 lines (65 loc) · 2.65 KB
/
test_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import sys
import unittest as ut
import comtypes.client
from comtypes import COSERVERINFO
from ctypes import POINTER, byref
# create the typelib wrapper and import it
comtypes.client.GetModule("scrrun.dll")
from comtypes.gen import Scripting
if sys.version_info >= (3, 0):
text_type = str
else:
text_type = unicode
class Test(ut.TestCase):
def test_progid(self):
# create from ProgID
obj = comtypes.client.CreateObject("Scripting.Dictionary")
self.assertTrue(isinstance(obj, POINTER(Scripting.IDictionary)))
def test_clsid(self):
# create from the CoClass' clsid
obj = comtypes.client.CreateObject(Scripting.Dictionary)
self.assertTrue(isinstance(obj, POINTER(Scripting.IDictionary)))
def test_clsid_string(self):
# create from string clsid
comtypes.client.CreateObject(text_type(Scripting.Dictionary._reg_clsid_))
comtypes.client.CreateObject(str(Scripting.Dictionary._reg_clsid_))
def test_GetModule_clsid(self):
clsid = comtypes.GUID.from_progid("MediaPlayer.MediaPlayer")
tlib = comtypes.client.GetModule(clsid)
@ut.skip(
"This test uses IE which is not available on all machines anymore. "
"Find another API to use."
)
def test_remote(self):
ie = comtypes.client.CreateObject("InternetExplorer.Application",
machine="localhost")
self.assertEqual(ie.Visible, False)
ie.Visible = 1
# on a remote machine, this may not work. Probably depends on
# how the server is run.
self.assertEqual(ie.Visible, True)
self.assertEqual(0, ie.Quit()) # 0 == S_OK
@ut.skip(
"This test uses IE which is not available on all machines anymore. "
"Find another API to use."
)
def test_server_info(self):
serverinfo = COSERVERINFO()
serverinfo.pwszName = 'localhost'
pServerInfo = byref(serverinfo)
self.assertRaises(ValueError, comtypes.client.CreateObject,
"InternetExplorer.Application", machine='localhost',
pServerInfo=pServerInfo)
ie = comtypes.client.CreateObject("InternetExplorer.Application",
pServerInfo=pServerInfo)
self.assertEqual(ie.Visible, False)
ie.Visible = 1
# on a remote machine, this may not work. Probably depends on
# how the server is run.
self.assertEqual(ie.Visible, True)
self.assertEqual(0, ie.Quit()) # 0 == S_OK
def test_main():
from test import test_support
test_support.run_unittest(Test)
if __name__ == "__main__":
ut.main()