예제 #1
0
 def test_rejects_numpy_types(self):
     numpy_values = [
         numpy.float16(25),
         numpy.float32(25),
         numpy.float64(25),
     ]
     for numpy_value in numpy_values:
         self.model.percentage = 88
         with self.assertRaises(TraitError):
             self.model.percentage = numpy_value
         self.assertEqual(self.model.percentage, 88)
예제 #2
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)
예제 #3
0
    def test_accepts_numpy_floats(self):
        test_values = [
            numpy.float64(2.3),
            numpy.float32(3.7),
            numpy.float16(1.28),
        ]
        a = self.test_class()
        for test_value in test_values:
            a.value = test_value
            self.assertIs(type(a.value), float)
            self.assertEqual(a.value, test_value)

            a.value_or_none = test_value
            self.assertIs(type(a.value_or_none), float)
            self.assertEqual(a.value_or_none, test_value)
예제 #4
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),
         numpy.float16(25),
         numpy.float32(25),
         numpy.float64(25),
     ]
     for numpy_value in numpy_values:
         self.model.percentage = numpy_value
         self.assertIs(type(self.model.percentage), float)
         self.assertEqual(self.model.percentage, 25.0)