Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move some tests to test_comserver. #695

Merged
merged 6 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions comtypes/test/test_comserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import comtypes.test.TestComServer
from comtypes import BSTR
from comtypes.automation import VARIANT, _midlSAFEARRAY
from comtypes.client import CreateObject
from comtypes.server.register import register, unregister
from comtypes.test.find_memleak import find_memleak
Expand Down Expand Up @@ -170,6 +171,77 @@ def test_mixedinout(self):
pass


class VariantTest(unittest.TestCase):
def test_UDT(self):
from comtypes.gen.TestComServerLib import MYCOLOR

v = VARIANT(MYCOLOR(red=1.0, green=2.0, blue=3.0))
value = v.value
self.assertEqual(1.0, value.red) # type: ignore
self.assertEqual(2.0, value.green) # type: ignore
self.assertEqual(3.0, value.blue) # type: ignore

def func():
v = VARIANT(MYCOLOR(red=1.0, green=2.0, blue=3.0))
return v.value

bytes = find_memleak(func)
self.assertFalse(bytes, "Leaks %d bytes" % bytes)


class SafeArrayTest(unittest.TestCase):
def test_UDT(self):
from comtypes.gen.TestComServerLib import MYCOLOR

t = _midlSAFEARRAY(MYCOLOR)
self.assertTrue(t is _midlSAFEARRAY(MYCOLOR))

sa = t.from_param([MYCOLOR(0, 0, 0), MYCOLOR(1, 2, 3)])

self.assertEqual(
[(x.red, x.green, x.blue) for x in sa[0]],
[(0.0, 0.0, 0.0), (1.0, 2.0, 3.0)],
)

def doit():
t.from_param([MYCOLOR(0, 0, 0), MYCOLOR(1, 2, 3)])

bytes = find_memleak(doit)
self.assertFalse(bytes, "Leaks %d bytes" % bytes)


class PropPutRefTest(unittest.TestCase):
def doit(self, dynamic: bool):
d = CreateObject("Scripting.Dictionary", dynamic=dynamic)
s = CreateObject("TestComServerLib.TestComServer", dynamic=dynamic)
s.name = "the value"

# This calls propputref, since we assign an Object
d.Item["object"] = s
# This calls propput, since we assing a Value
d.Item["value"] = s.name

self.assertEqual(d.Item["object"], s)
self.assertEqual(d.Item["object"].name, "the value")
self.assertEqual(d.Item["value"], "the value")

# Changing the default property of the object
s.name = "foo bar"
self.assertEqual(d.Item["object"], s)
self.assertEqual(d.Item["object"].name, "foo bar")
self.assertEqual(d.Item["value"], "the value")

# This also calls propputref since we assign an Object
d.Item["var"] = VARIANT(s)
self.assertEqual(d.Item["var"], s)

def test_earlybind(self):
self.doit(dynamic=False)

def test_latebind(self):
self.doit(dynamic=True)


class TestEvents(unittest.TestCase):
def test(self):
import comtypes.test.test_comserver
Expand Down
40 changes: 0 additions & 40 deletions comtypes/test/test_propputref.py

This file was deleted.

23 changes: 0 additions & 23 deletions comtypes/test/test_safearray.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,29 +221,6 @@ def test_VT_UNKNOWN_multi(self):
del sa
self.assertEqual((a, b), (com_refcnt(plib), com_refcnt(punk)))

@unittest.skip(
"This fails with a 'library not registered' error. Need to figure out how to "
"register TestComServerLib (without admin if possible)."
)
def test_UDT(self):
from comtypes.gen.TestComServerLib import MYCOLOR

t = _midlSAFEARRAY(MYCOLOR)
self.assertTrue(t is _midlSAFEARRAY(MYCOLOR))

sa = t.from_param([MYCOLOR(0, 0, 0), MYCOLOR(1, 2, 3)])

self.assertEqual(
[(x.red, x.green, x.blue) for x in sa[0]],
[(0.0, 0.0, 0.0), (1.0, 2.0, 3.0)],
)

def doit():
t.from_param([MYCOLOR(0, 0, 0), MYCOLOR(1, 2, 3)])

bytes = find_memleak(doit)
self.assertFalse(bytes, "Leaks %d bytes" % bytes)


if __name__ == "__main__":
unittest.main()
17 changes: 0 additions & 17 deletions comtypes/test/test_variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,23 +194,6 @@ def test_empty_BSTR(self):
v.value = ""
self.assertEqual(v.vt, VT_BSTR)

@unittest.skip(
"Fails on creating `TestComServerLib.TestComServer`. Library not registered."
)
def test_UDT(self):
from comtypes.gen.TestComServerLib import MYCOLOR

v = VARIANT(MYCOLOR(red=1.0, green=2.0, blue=3.0))
value = v.value
self.assertEqual((1.0, 2.0, 3.0), (value.red, value.green, value.blue))

def func():
v = VARIANT(MYCOLOR(red=1.0, green=2.0, blue=3.0))
return v.value

bytes = find_memleak(func)
self.assertFalse(bytes, "Leaks %d bytes" % bytes)

def test_ctypes_in_variant(self):
v = VARIANT()
objs = [
Expand Down