diff --git a/comtypes/test/test_safearray_pywin32.py b/comtypes/test/test_safearray_pywin32.py deleted file mode 100644 index 44567c5c4..000000000 --- a/comtypes/test/test_safearray_pywin32.py +++ /dev/null @@ -1,73 +0,0 @@ -import unittest -from ctypes import POINTER, PyDLL, byref, py_object -from ctypes.wintypes import BOOL - -from comtypes.automation import VARIANT - -try: - import pythoncom - # 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. -except ImportError: - # pywin32 not installed... - raise unittest.SkipTest("This depends on 'pywin32'.") - - -_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() diff --git a/comtypes/test/test_win32com_interop.py b/comtypes/test/test_win32com_interop.py index 21bbfbb24..cafe2d181 100644 --- a/comtypes/test/test_win32com_interop.py +++ b/comtypes/test/test_win32com_interop.py @@ -3,39 +3,49 @@ from ctypes.wintypes import BOOL from comtypes import IUnknown -from comtypes.automation import IDispatch +from comtypes.automation import IDispatch, VARIANT from comtypes.client import CreateObject try: import pythoncom import win32com.client - - skip = False - # We use the PyCom_PyObjectFromIUnknown function in pythoncom25.dll to - # convert a comtypes COM pointer into a pythoncom COM pointer. - # Fortunately this function is exported by the dll... - # - # This is the C prototype; we must pass 'True' as third argument: - # - # PyObject *PyCom_PyObjectFromIUnknown(IUnknown *punk, REFIID riid, BOOL bAddRef) - - _PyCom_PyObjectFromIUnknown = PyDLL(pythoncom.__file__).PyCom_PyObjectFromIUnknown - _PyCom_PyObjectFromIUnknown.restype = py_object - _PyCom_PyObjectFromIUnknown.argtypes = (POINTER(IUnknown), c_void_p, BOOL) except ImportError: - # this test depends on pythoncom but it is not available. Maybe we should just skip it even - # if it is available since pythoncom is not a project dependency and adding tests depending - # on the vagaries of various testing environments is not deterministic. - # TODO: Evaluate if we should just remove this test or what. - skip = True - - -def setUpModule(): - if skip: - raise unittest.SkipTest( - "This test requires the pythoncom library installed. If this is " - "important tests then we need to add dev dependencies to the project that include pythoncom." - ) + raise unittest.SkipTest( + "This test requires the pythoncom library installed. If this is " + "important tests then we need to add dev dependencies to the project that include pythoncom." + ) + + +_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 + +# We use the PyCom_PyObjectFromIUnknown function in pythoncom25.dll to +# convert a comtypes COM pointer into a pythoncom COM pointer. +# Fortunately this function is exported by the dll... +# +# This is the C prototype; we must pass 'True' as third argument: +# +# PyObject *PyCom_PyObjectFromIUnknown(IUnknown *punk, REFIID riid, BOOL bAddRef) +_PyCom_PyObjectFromIUnknown = PyDLL(pythoncom.__file__).PyCom_PyObjectFromIUnknown +_PyCom_PyObjectFromIUnknown.restype = py_object +_PyCom_PyObjectFromIUnknown.argtypes = (POINTER(IUnknown), c_void_p, BOOL) + + +def pack(obj): + var = VARIANT() + _pack(obj, byref(var)) + return var def comtypes2pywin(ptr, interface=None): @@ -77,7 +87,8 @@ class MyComObject(COMObject): ################################################################ -class Test(unittest.TestCase): +@unittest.skip("This depends on IE.") +class Test_refcount(unittest.TestCase): def tearDown(self): if hasattr(self, "ie"): self.ie.Quit() @@ -112,5 +123,37 @@ def test_ie(self): self.assertEqual(comtypes_get_refcount(ie), 1) +################################################################ + + +class TestSafeArray(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()