def test_deserializing_java_output_2(self): try: byte_stream = _get_java_output_stream(self.wd) # read integers self.assertEqual(42, srl.deserialize_vint(byte_stream)) self.assertEqual(4242, srl.deserialize_vint(byte_stream)) self.assertEqual(424242, srl.deserialize_vint(byte_stream)) self.assertEqual(42424242, srl.deserialize_vint(byte_stream)) self.assertEqual(-42, srl.deserialize_vint(byte_stream)) # longs self.assertEqual(42, srl.deserialize_vint(byte_stream)) self.assertEqual(424242, srl.deserialize_vint(byte_stream)) self.assertEqual(4242424242, srl.deserialize_vint(byte_stream)) # strings # first one is plain ASCII self.assertEqual(u"hello world", wu.readString(byte_stream)) # second has accented characters self.assertEqual(u"oggi è giovedì", wu.readString(byte_stream)) # final piece is an encoded Text object self.assertEqual( u"à Text object", srl.deserialize_text(byte_stream) ) finally: pass
def test_serialize_to_string(self): numbers = random.sample(xrange(-18999289888, 18999289888), 10000) for n in numbers: s = srl.serialize_to_string(n) stream = StringIO(s) x = srl.deserialize_vint(stream) self.assertEqual(n, x)
def test_int(self): stream = self.stream for i in xrange(-16782, 16782): srl.serialize_vint(i, stream) stream.seek(0) for i in xrange(-16782, 16782): x = srl.deserialize_vint(stream) self.assertEqual(i, x)
def test_int_big(self): stream = self.stream numbers = random.sample(xrange(-18999289888, 18999289888), 10000) for i in numbers: srl.serialize_vint(i, stream) stream.seek(0) for i in numbers: x = srl.deserialize_vint(stream) self.assertEqual(i, x)
def readVLong(stream): return pser.deserialize_vint(stream)