Skip to content

Commit

Permalink
Move win32com stuff from test_dispinterface to `test_comserver_pywi…
Browse files Browse the repository at this point in the history
…n32`.
  • Loading branch information
junkmd committed Dec 7, 2024
1 parent c06773d commit 7e00588
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 72 deletions.
68 changes: 68 additions & 0 deletions comtypes/test/test_comserver_pywin32.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

try:
from win32com.client import Dispatch
from win32com.client.gencache import EnsureDispatch
except ImportError:
raise unittest.SkipTest("This depends on 'pywin32'.")

Expand Down Expand Up @@ -85,5 +86,72 @@ def create_object(self):
)


class Test_win32com_Dispatch(unittest.TestCase):
def test_win32com_ensure_dispatch(self):
# EnsureDispatch is case-sensitive
d = EnsureDispatch("TestDispServerLib.TestDispServer")

self.assertEqual(d.eval("3.14"), 3.14)
self.assertEqual(d.eval("1 + 2"), 3)
self.assertEqual(d.eval("[1 + 2, 'foo', None]"), (3, "foo", None))

self.assertEqual(d.eval2("3.14"), 3.14)
self.assertEqual(d.eval2("1 + 2"), 3)
self.assertEqual(d.eval2("[1 + 2, 'foo', None]"), (3, "foo", None))

d.eval(
"__import__('comtypes.client').client.CreateObject('Scripting.Dictionary')"
)

server_id = d.eval("id(self)")
self.assertEqual(d.id, server_id)

self.assertEqual(d.name, "spam, spam, spam")

d.SetName("foo bar")
self.assertEqual(d.name, "foo bar")

d.name = "blah"
self.assertEqual(d.name, "blah")

def test_win32com_dynamic_dispatch(self):
# dynamic Dispatch is case-IN-sensitive
d = Dispatch("TestDispServerLib.TestDispServer")

self.assertEqual(d.eval("3.14"), 3.14)
self.assertEqual(d.eval("1 + 2"), 3)
self.assertEqual(d.eval("[1 + 2, 'foo', None]"), (3, "foo", None))

self.assertEqual(d.eval2("3.14"), 3.14)
self.assertEqual(d.eval2("1 + 2"), 3)
self.assertEqual(d.eval2("[1 + 2, 'foo', None]"), (3, "foo", None))

d.eval(
"__import__('comtypes.client').client.CreateObject('Scripting.Dictionary')"
)

self.assertEqual(d.EVAL("3.14"), 3.14)
self.assertEqual(d.EVAL("1 + 2"), 3)
self.assertEqual(d.EVAL("[1 + 2, 'foo', None]"), (3, "foo", None))

self.assertEqual(d.EVAL2("3.14"), 3.14)
self.assertEqual(d.EVAL2("1 + 2"), 3)
self.assertEqual(d.EVAL2("[1 + 2, 'foo', None]"), (3, "foo", None))

server_id = d.eval("id(self)")
self.assertEqual(d.id, server_id)
self.assertEqual(d.ID, server_id)

self.assertEqual(d.Name, "spam, spam, spam")
self.assertEqual(d.nAME, "spam, spam, spam")

d.SetName("foo bar")
self.assertEqual(d.Name, "foo bar")

# fails. Why?
# d.name = "blah"
# self.assertEqual(d.Name, "blah")


if __name__ == "__main__":
unittest.main()
72 changes: 0 additions & 72 deletions comtypes/test/test_dispinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,78 +21,6 @@ def tearDownModule():
unregister(comtypes.test.TestDispServer.TestDispServer)


@unittest.skip("This depends on 'pywin32'.")
class Test_win32com(unittest.TestCase):
def test_win32com(self):
# EnsureDispatch is case-sensitive
from win32com.client.gencache import EnsureDispatch

d = EnsureDispatch("TestDispServerLib.TestDispServer")

self.assertEqual(d.eval("3.14"), 3.14)
self.assertEqual(d.eval("1 + 2"), 3)
self.assertEqual(d.eval("[1 + 2, 'foo', None]"), (3, "foo", None))

self.assertEqual(d.eval2("3.14"), 3.14)
self.assertEqual(d.eval2("1 + 2"), 3)
self.assertEqual(d.eval2("[1 + 2, 'foo', None]"), (3, "foo", None))

d.eval(
"__import__('comtypes.client').client.CreateObject('Scripting.Dictionary')"
)

server_id = d.eval("id(self)")
self.assertEqual(d.id, server_id)

self.assertEqual(d.name, "spam, spam, spam")

d.SetName("foo bar")
self.assertEqual(d.name, "foo bar")

d.name = "blah"
self.assertEqual(d.name, "blah")

def test_win32com_dyndispatch(self):
# dynamic Dispatch is case-IN-sensitive
from win32com.client.dynamic import Dispatch

d = Dispatch("TestDispServerLib.TestDispServer")

self.assertEqual(d.eval("3.14"), 3.14)
self.assertEqual(d.eval("1 + 2"), 3)
self.assertEqual(d.eval("[1 + 2, 'foo', None]"), (3, "foo", None))

self.assertEqual(d.eval2("3.14"), 3.14)
self.assertEqual(d.eval2("1 + 2"), 3)
self.assertEqual(d.eval2("[1 + 2, 'foo', None]"), (3, "foo", None))

d.eval(
"__import__('comtypes.client').client.CreateObject('Scripting.Dictionary')"
)

self.assertEqual(d.EVAL("3.14"), 3.14)
self.assertEqual(d.EVAL("1 + 2"), 3)
self.assertEqual(d.EVAL("[1 + 2, 'foo', None]"), (3, "foo", None))

self.assertEqual(d.EVAL2("3.14"), 3.14)
self.assertEqual(d.EVAL2("1 + 2"), 3)
self.assertEqual(d.EVAL2("[1 + 2, 'foo', None]"), (3, "foo", None))

server_id = d.eval("id(self)")
self.assertEqual(d.id, server_id)
self.assertEqual(d.ID, server_id)

self.assertEqual(d.Name, "spam, spam, spam")
self.assertEqual(d.nAME, "spam, spam, spam")

d.SetName("foo bar")
self.assertEqual(d.Name, "foo bar")

# fails. Why?
# d.name = "blah"
# self.assertEqual(d.Name, "blah")


class Test_comtypes(unittest.TestCase):
def test_comtypes(self):
from comtypes.client import CreateObject
Expand Down

0 comments on commit 7e00588

Please sign in to comment.