Beispiel #1
0
 def test_Optional(self):
     u = types.Optional(types.Uint16(10))
     self.assertEqual(py23_bytes(u), b"\x01\n\x00")
     self.assertEqual(str(u), '10')
     self.assertFalse(u.isempty())
     u = types.Optional(None)
     self.assertEqual(py23_bytes(u), b"\x00")
     self.assertEqual(str(u), 'None')
     self.assertTrue(u.isempty())
Beispiel #2
0
 def test_array(self):
     u = types.Array([types.Uint8(10) for x in range(2)] + [11])
     self.assertEqual(py23_bytes(u), b'\x03\n\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
     self.assertEqual(str(u), "[10, 10, 11]")
     u = types.Set([types.Uint16(10) for x in range(10)])
     self.assertEqual(py23_bytes(u), b"\n\n\x00\n\x00\n\x00\n\x00\n\x00\n\x00\n\x00\n\x00\n\x00\n\x00")
     self.assertEqual(str(u), "[10, 10, 10, 10, 10, 10, 10, 10, 10, 10]")
     u = types.Array(["Foobar"])
     # We do not support py23_bytes of Array containing String only!
     # self.assertEqual(py23_bytes(u), b'')
     self.assertEqual(str(u), '["Foobar"]')
Beispiel #3
0
 def test_uint16(self):
     u = types.Uint16(2**16 - 1)
     self.assertEqual(py23_bytes(u), b"\xff\xff")
     self.assertEqual(str(u), str(2**16 - 1))
Beispiel #4
0
 def test_Map(self):
     u = types.Map([[types.Uint16(10), types.Uint16(11)]])
     self.assertEqual(py23_bytes(u), b"\x01\n\x00\x0b\x00")
     self.assertEqual(str(u), '[["10", "11"]]')