Esempio n. 1
0
    def test_VT_VARIANT(self):
        t = _midlSAFEARRAY(VARIANT)

        now = datetime.datetime.now()
        sa = t.from_param([11, "22", None, True, now, Decimal("3.14")])
        self.assertEqual(sa[0], (11, "22", None, True, now, Decimal("3.14")))

        self.assertEqual(SafeArrayGetVartype(sa), VT_VARIANT)
    def test_VT_I4(self):
        t = _midlSAFEARRAY(c_long)

        sa = t.from_param([11, 22, 33])

        self.failUnlessEqual(sa[0], (11, 22, 33))

        self.failUnlessEqual(SafeArrayGetVartype(sa), VT_I4)

        # TypeError: len() of unsized object
        self.assertRaises(TypeError, lambda: t.from_param(object()))
Esempio n. 3
0
    def test_VT_BSTR_ndarray(self):
        np = get_numpy()
        if np is None:
            return

        t = _midlSAFEARRAY(BSTR)

        sa = t.from_param(["a", "b", "c"])
        arr = get_array(sa)

        self.failUnless(isinstance(arr, np.ndarray))
        self.failUnlessEqual(np.dtype('<U1'), arr.dtype)
        self.failUnless((arr == ("a", "b", "c")).all())
        self.failUnlessEqual(SafeArrayGetVartype(sa), VT_BSTR)
Esempio n. 4
0
    def test_VT_VARIANT_ndarray(self):
        np = get_numpy()
        if np is None:
            return

        t = _midlSAFEARRAY(VARIANT)

        now = datetime.datetime.now()
        sa = t.from_param([11, "22", None, True, now, Decimal("3.14")])
        arr = get_array(sa)
        self.failUnlessEqual(np.dtype(object), arr.dtype)
        self.failUnless(isinstance(arr, np.ndarray))
        self.failUnless(
            (arr == (11, "22", None, True, now, Decimal("3.14"))).all())
        self.failUnlessEqual(SafeArrayGetVartype(sa), VT_VARIANT)
Esempio n. 5
0
    def test_VT_I4_ndarray(self):
        np = get_numpy()
        if np is None:
            return

        t = _midlSAFEARRAY(c_long)

        sa = t.from_param([11, 22, 33])

        arr = get_array(sa)

        self.failUnless(isinstance(arr, np.ndarray))
        self.failUnlessEqual(np.dtype(np.int), arr.dtype)
        self.failUnless((arr == (11, 22, 33)).all())
        self.failUnlessEqual(SafeArrayGetVartype(sa), VT_I4)
Esempio n. 6
0
    def test_VT_I4_ndarray(self):
        np = get_numpy()
        if np is None:
            return

        t = _midlSAFEARRAY(c_long)

        inarr = np.array([11, 22, 33])
        sa = t.from_param(inarr)

        arr = get_array(sa)

        self.assertTrue(isinstance(arr, np.ndarray))
        self.assertEqual(np.dtype(np.int), arr.dtype)
        self.assertTrue((arr == inarr).all())
        self.assertEqual(SafeArrayGetVartype(sa), VT_I4)
Esempio n. 7
0
    def test_VT_VARIANT_ndarray(self):
        np = get_numpy()
        if np is None:
            return

        t = _midlSAFEARRAY(VARIANT)

        now = datetime.datetime.now()
        inarr = np.array(
            [11, "22", "33", 44.0, None, True, now,
             Decimal("3.14")]).reshape(2, 4)
        sa = t.from_param(inarr)
        arr = get_array(sa)
        self.assertEqual(np.dtype(object), arr.dtype)
        self.assertTrue(isinstance(arr, np.ndarray))
        self.assertTrue((arr == inarr).all())
        self.assertEqual(SafeArrayGetVartype(sa), VT_VARIANT)
    def test_VT_BSTR(self):
        t = _midlSAFEARRAY(BSTR)

        sa = t.from_param(["a", "b", "c"])
        self.failUnlessEqual(sa[0], ("a", "b", "c"))
        self.failUnlessEqual(SafeArrayGetVartype(sa), VT_BSTR)