|
3 | 3 | import importlib |
4 | 4 | import inspect |
5 | 5 | import unittest |
6 | | -from ctypes import POINTER, c_double, c_long, pointer |
| 6 | +from ctypes import POINTER, c_double, c_long, c_longlong, pointer |
7 | 7 | from decimal import Decimal |
8 | 8 |
|
9 | 9 | import comtypes._npsupport |
|
16 | 16 | VT_BSTR, |
17 | 17 | VT_DATE, |
18 | 18 | VT_I4, |
| 19 | + VT_I8, |
19 | 20 | VT_VARIANT, |
20 | 21 | _midlSAFEARRAY, |
21 | 22 | ) |
22 | 23 | from comtypes.safearray import safearray_as_ndarray |
23 | 24 |
|
24 | 25 | try: |
25 | 26 | import numpy |
| 27 | + |
| 28 | + IMPORT_NUMPY_FAILED = False |
26 | 29 | except ImportError: |
27 | | - numpy = None |
| 30 | + IMPORT_NUMPY_FAILED = True |
28 | 31 |
|
29 | 32 |
|
30 | 33 | def setUpModule(): |
31 | 34 | """Only run the module if we can import numpy.""" |
32 | | - if numpy is None: |
| 35 | + if IMPORT_NUMPY_FAILED: |
33 | 36 | raise unittest.SkipTest("Skipping test_npsupport as numpy not installed.") |
34 | 37 |
|
35 | 38 |
|
@@ -188,6 +191,20 @@ def test_VT_I4_ndarray(self): |
188 | 191 | self.assertTrue((arr == in_arr).all()) |
189 | 192 | self.assertEqual(SafeArrayGetVartype(sa), VT_I4) |
190 | 193 |
|
| 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 | + |
191 | 208 | @enabled_disabled(disabled_error=ValueError) |
192 | 209 | def test_array(self): |
193 | 210 | t = _midlSAFEARRAY(c_double) |
|
0 commit comments