Skip to content

Commit

Permalink
Remove the pythoncom section from test_safearray.
Browse files Browse the repository at this point in the history
  • Loading branch information
junkmd committed Dec 7, 2024
1 parent a7a7ba4 commit 06ce3b9
Showing 1 changed file with 1 addition and 67 deletions.
68 changes: 1 addition & 67 deletions comtypes/test/test_safearray.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import array
import datetime
import unittest
from ctypes import POINTER, PyDLL, byref, c_long, py_object
from ctypes.wintypes import BOOL
from ctypes import POINTER, c_long
from decimal import Decimal

from comtypes import BSTR, IUnknown
Expand All @@ -19,7 +18,6 @@
_midlSAFEARRAY,
)
from comtypes.safearray import safearray_as_ndarray
from comtypes.test import is_resource_enabled
from comtypes.test.find_memleak import find_memleak


Expand Down Expand Up @@ -247,69 +245,5 @@ def doit():
self.assertFalse(bytes, "Leaks %d bytes" % bytes)


if is_resource_enabled("pythoncom"):
try:
import pythoncom
except ImportError:
# pywin32 not installed...
pass
else:
# pywin32 is available. The pythoncom dll contains two handy
# exported functions that allow to create a VARIANT from a Python
# object, also a function that unpacks a VARIANT into a Python
# object.
#
# This allows us to create und unpack SAFEARRAY instances
# contained in VARIANTs, and check for consistency with the
# comtypes code.

_dll = PyDLL(pythoncom.__file__)

# c:/sf/pywin32/com/win32com/src/oleargs.cpp 213
# PyObject *PyCom_PyObjectFromVariant(const VARIANT *var)
unpack = _dll.PyCom_PyObjectFromVariant
unpack.restype = py_object
unpack.argtypes = (POINTER(VARIANT),)

# c:/sf/pywin32/com/win32com/src/oleargs.cpp 54
# BOOL PyCom_VariantFromPyObject(PyObject *obj, VARIANT *var)
_pack = _dll.PyCom_VariantFromPyObject
_pack.argtypes = py_object, POINTER(VARIANT)
_pack.restype = BOOL

def pack(obj):
var = VARIANT()
_pack(obj, byref(var))
return var

class PyWinTest(unittest.TestCase):
def test_1dim(self):
data = (1, 2, 3)
variant = pack(data)
self.assertEqual(variant.value, data)
self.assertEqual(unpack(variant), data)

def test_2dim(self):
data = ((1, 2, 3), (4, 5, 6), (7, 8, 9))
variant = pack(data)
self.assertEqual(variant.value, data)
self.assertEqual(unpack(variant), data)

def test_3dim(self):
data = (((1, 2), (3, 4), (5, 6)), ((7, 8), (9, 10), (11, 12)))
variant = pack(data)
self.assertEqual(variant.value, data)
self.assertEqual(unpack(variant), data)

def test_4dim(self):
data = (
(((1, 2), (3, 4)), ((5, 6), (7, 8))),
(((9, 10), (11, 12)), ((13, 14), (15, 16))),
)
variant = pack(data)
self.assertEqual(variant.value, data)
self.assertEqual(unpack(variant), data)


if __name__ == "__main__":
unittest.main()

0 comments on commit 06ce3b9

Please sign in to comment.