def test_parse_varint_too_long(self): # since it's impossible to get > 0xff from a single byte, use mox to verify self.mox.StubOutWithMock(struct, 'unpack') struct.unpack('<B', '\x00').AndReturn((0x100,)) self.mox.ReplayAll() with self.assertRaises(ParseError): protocol.parse_varint('\x00')
def test_parse_varint_short(self): self.assertEquals(protocol.parse_varint('\xfd\xfd\x00'), (0xfd, '')) self.assertEquals(protocol.parse_varint('\xfd\xfe\x00'), (0xfe, '')) self.assertEquals(protocol.parse_varint('\xfd\xff\x00'), (0xff, ''))
def test_parse_varint_long_long(self): self.assertEquals(protocol.parse_varint('\xff\x00\x00\x00\x00\x01\x00\x00\x00'), (0x100000000, ''))
def test_parse_varint_char(self): self.assertEquals(protocol.parse_varint('\xfc'), (0xfc, ''))