示例#1
0
 def test_float_from_str(self):
     a = self.schema['float']
     v = Sos.Value(a)
     v.from_str('1234.50000')
     self.assertEqual(v.value, 1234.5)
     v.from_str('1.2345e3')
     self.assertEqual(v.value, 1234.5)
     v.from_str('1234.4e-3')
     self.assertEqual(v.value, 1.2344000339508057)
示例#2
0
 def test_double_from_str(self):
     a = self.schema['double']
     v = Sos.Value(a)
     v.from_str('1234.50000')
     self.assertEqual(v.value, 1234.5)
     v.from_str('1.2345e3')
     self.assertEqual(v.value, 1234.5)
     v.from_str('1234.4e-3')
     self.assertEqual(v.value, 1.2344)
示例#3
0
    def test_timestamp_to_str(self):
        a = self.schema['timestamp']
        v = Sos.Value(a)
        v.value = (1511885835, 123450)
        s = v.to_str()
        self.assertEqual(s, '1511885835.123450')

        v.value = (1511885835, 12345)
        s = v.to_str()
        self.assertEqual(s, '1511885835.012345')
示例#4
0
    def test_timestamp_from_str(self):
        a = self.schema['timestamp']
        v = Sos.Value(a)

        v.from_str('1511885835.012345')
        self.assertEqual(v.value, (1511885835, 12345))

        v.from_str('1511885835.12345')
        self.assertEqual(v.value, (1511885835, 12345))

        v.from_str('1511885835.123450')
        self.assertEqual(v.value, (1511885835, 123450))
示例#5
0
 def test_uint16_from_str(self):
     a = self.schema['uint16']
     v = Sos.Value(a)
     # octal
     v.from_str('01234')
     self.assertEqual(v.value, 668)
     # decimal
     v.from_str('1234')
     self.assertEqual(v.value, 1234)
     # hex
     v.from_str('0x1234')
     self.assertEqual(v.value, 4660)
示例#6
0
 def test_int64_from_str(self):
     a = self.schema['int64']
     v = Sos.Value(a)
     # octal
     v.from_str('-0123456789')
     self.assertEqual(v.value, -342391)
     # decimal
     v.from_str('-123456789')
     self.assertEqual(v.value, -123456789)
     # hex
     v.from_str('-0x123456789')
     self.assertEqual(v.value, -4886718345)
示例#7
0
 def test_uint32_from_str(self):
     a = self.schema['uint32']
     v = Sos.Value(a)
     # octal
     v.from_str('012345678')
     self.assertEqual(v.value, 342391)
     # decimal
     v.from_str('12345678')
     self.assertEqual(v.value, 12345678)
     # hex
     v.from_str('0x12345678')
     self.assertEqual(v.value, 305419896)
示例#8
0
 def test_int16_from_str(self):
     a = self.schema['int16']
     v = Sos.Value(a)
     # octal
     v.from_str('-01234')
     self.assertEqual(v.value, -668)
     # decimal
     v.from_str('-1234')
     self.assertEqual(v.value, -1234)
     # hex
     v.from_str('-0x1234')
     self.assertEqual(v.value, -4660)
示例#9
0
 def chk_array_strlen(self, a, av):
     v = Sos.Value(a)
     v.value = av
     s = str(v)
     self.assertGreaterEqual(v.strlen(), len(s))
示例#10
0
 def test_timestamp_strlen(self):
     a = self.schema['timestamp']
     v = Sos.Value(a)
     v.value = (1511885835, 12345)
     self.assertGreaterEqual(v.strlen(), 6)
示例#11
0
 def test_double_to_str(self):
     a = self.schema['double']
     v = Sos.Value(a)
     v.value = 1234.5
     s = v.to_str()
     self.assertEqual(s, '1234.50000')
示例#12
0
 def test_float_to_str(self):
     a = self.schema['float']
     v = Sos.Value(a)
     v.value = 1234.5
     s = v.to_str()
     self.assertEqual(s, '1234.50000')
示例#13
0
 def test_float_strlen(self):
     a = self.schema['float']
     v = Sos.Value(a)
     v.value = 1234.5
     self.assertGreaterEqual(v.strlen(), 6)
示例#14
0
 def test_int64_strlen(self):
     a = self.schema['int64']
     v = Sos.Value(a)
     v.value = -123456789
     self.assertEqual(v.strlen(), 10)
示例#15
0
 def test_uint32_strlen(self):
     a = self.schema['uint32']
     v = Sos.Value(a)
     v.value = 12345678
     self.assertEqual(v.strlen(), 8)
示例#16
0
 def chk_array_to_str(self, a, av, ev):
     v = Sos.Value(a)
     v.value = av
     s = str(v)
     self.assertEqual(s, ev)
示例#17
0
 def test_int16_strlen(self):
     a = self.schema['int16']
     v = Sos.Value(a)
     v.value = -1234
     self.assertEqual(v.strlen(), 5)
示例#18
0
 def test_double_strlen(self):
     a = self.schema['double']
     v = Sos.Value(a)
     v.value = 1234.5
     self.assertGreaterEqual(v.strlen(), 6)