Skip to content

Commit 74b6fba

Browse files
authored
Add VT_I8 ndarray test to npsupport. (#862)
1 parent 6b29d46 commit 74b6fba

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

comtypes/test/test_npsupport.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import importlib
44
import inspect
55
import unittest
6-
from ctypes import POINTER, c_double, c_long, pointer
6+
from ctypes import POINTER, c_double, c_long, c_longlong, pointer
77
from decimal import Decimal
88

99
import comtypes._npsupport
@@ -16,20 +16,23 @@
1616
VT_BSTR,
1717
VT_DATE,
1818
VT_I4,
19+
VT_I8,
1920
VT_VARIANT,
2021
_midlSAFEARRAY,
2122
)
2223
from comtypes.safearray import safearray_as_ndarray
2324

2425
try:
2526
import numpy
27+
28+
IMPORT_NUMPY_FAILED = False
2629
except ImportError:
27-
numpy = None
30+
IMPORT_NUMPY_FAILED = True
2831

2932

3033
def setUpModule():
3134
"""Only run the module if we can import numpy."""
32-
if numpy is None:
35+
if IMPORT_NUMPY_FAILED:
3336
raise unittest.SkipTest("Skipping test_npsupport as numpy not installed.")
3437

3538

@@ -188,6 +191,20 @@ def test_VT_I4_ndarray(self):
188191
self.assertTrue((arr == in_arr).all())
189192
self.assertEqual(SafeArrayGetVartype(sa), VT_I4)
190193

194+
@enabled_disabled(disabled_error=ValueError)
195+
def test_VT_I8_ndarray(self):
196+
t = _midlSAFEARRAY(c_longlong)
197+
198+
in_arr = numpy.array([11, 22, 33], dtype=numpy.int64)
199+
sa = t.from_param(in_arr)
200+
201+
arr = get_ndarray(sa)
202+
203+
self.assertTrue(isinstance(arr, numpy.ndarray))
204+
self.assertEqual(numpy.dtype(int), arr.dtype)
205+
self.assertTrue((arr == in_arr).all())
206+
self.assertEqual(SafeArrayGetVartype(sa), VT_I8)
207+
191208
@enabled_disabled(disabled_error=ValueError)
192209
def test_array(self):
193210
t = _midlSAFEARRAY(c_double)

0 commit comments

Comments
 (0)