Exemple #1
0
    def test_numpy_types(self):
        a = A()
        a.integral = numpy.int32(23)
        self.assertEqual(a.integral, 23)
        self.assertIn(type(a.integral), six.integer_types)

        a.integral = numpy.uint64(2**63 + 2)
        self.assertEqual(a.integral, 2**63 + 2)
        self.assertIs(type(a.integral), LONG_TYPE)

        with self.assertRaises(TraitError):
            a.integral = numpy.float32(4.0)
        with self.assertRaises(TraitError):
            a.integral = numpy.float64(4.0)
Exemple #2
0
 def test_accepts_numpy_types(self):
     numpy_values = [
         numpy.uint8(25),
         numpy.uint16(25),
         numpy.uint32(25),
         numpy.uint64(25),
         numpy.int8(25),
         numpy.int16(25),
         numpy.int32(25),
         numpy.int64(25),
     ]
     for numpy_value in numpy_values:
         self.model.percentage = numpy_value
         self.assertIs(type(self.model.percentage), int)
         self.assertEqual(self.model.percentage, 25)