Ejemplo n.º 1
0
 def test_plain(self):
     testStr = 'Hello world'
     tmp = StringField(testStr, format=StringFmt.ASCII_8BIT)
     self.assertEqual(tmp.bit_size(), 12 * 8)
     ser = tmp.serialize()
     self.assertEqual(ser, b'\xcbHello world')
     ser += b'remainder'
     tmp2 = StringField()
     self.assertEqual(tmp2.deserialize(ser), b'remainder')
     self.assertEqual(tmp2.to_dict(), testStr)
Ejemplo n.º 2
0
 def test_bcd_plus(self):
     testStr = '123.45-67 890'
     tmp = StringField(testStr, format=StringFmt.BCD_PLUS)
     self.assertEqual(tmp.bit_size(), 8 * 8)
     ser = tmp.serialize()
     self.assertEqual(ser, b'\x47\x12\x3c\x45\xb6\x7a\x89\x0a')
     ser += b'remainder'
     tmp2 = StringField()
     self.assertEqual(tmp2.deserialize(ser), b'remainder')
     self.assertEqual(tmp2.to_dict(), testStr + ' ')  # append padding space
Ejemplo n.º 3
0
 def test_ascii_6bit(self):
     testStr = 'IPMI Hello world'
     tmp = StringField(testStr, format=StringFmt.ASCII_6BIT)
     self.assertEqual(tmp.bit_size(), 13 * 8)
     ser = tmp.serialize()
     self.assertEqual(ser,
                      b'\x8c\x29\xdc\xa6\x00Z\xb2\xec\x0b\xdc\xaf\xcc\x92')
     ser += b'remainder'
     tmp2 = StringField()
     self.assertEqual(tmp2.deserialize(ser), b'remainder')
     self.assertEqual(tmp2.to_dict(), 'IPMI HELLO WORLD')
Ejemplo n.º 4
0
 def test_null(self):
     nul = StringField()
     ser = nul.serialize()
     self.assertEqual(ser, b'\xc0')
     ser += b'remainder'
     tmp = StringField()
     self.assertEqual(tmp.deserialize(ser), b'remainder')
     self.assertEqual(tmp.to_dict(), '')