Use new libs in Msgpack tests

This commit is contained in:
shortcutme 2019-03-16 00:54:00 +01:00
parent dc32556983
commit c481d20ce8
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -1,24 +1,25 @@
import cStringIO as StringIO import io
import os
import msgpack import msgpack
import pytest import pytest
from Config import config from Config import config
from util import StreamingMsgpack from util import Msgpack
class TestMsgpack: class TestMsgpack:
test_data = {"cmd": "fileGet", "params": {"site": "1Site"}, "utf8": b'\xc3\xa1rv\xc3\xadzt\xc5\xb1r\xc5\x91'.decode("utf8"), "bin": b'p\x81zDhL\xf0O\xd0\xaf', "list": [b'p\x81zDhL\xf0O\xd0\xaf', b'p\x81zDhL\xf0O\xd0\xaf']} test_data = {"cmd": "fileGet", "params": {"site": "1Site"}, "utf8": b'\xc3\xa1rv\xc3\xadzt\xc5\xb1r\xc5\x91'.decode("utf8"), "bin": b'p\x81zDhL\xf0O\xd0\xaf', "list": [b'p\x81zDhL\xf0O\xd0\xaf', b'p\x81zDhL\xf0O\xd0\xaf']}
def testUnpackinkg(self): def testUnpackinkg(self):
assert msgpack.unpackb(msgpack.packb(self.test_data)) == self.test_data assert Msgpack.unpack(Msgpack.pack(self.test_data)) == self.test_data
@pytest.mark.parametrize("unpacker_class", [msgpack.Unpacker, msgpack.fallback.Unpacker]) @pytest.mark.parametrize("unpacker_class", [msgpack.Unpacker, msgpack.fallback.Unpacker])
def testUnpacker(self, unpacker_class): def testUnpacker(self, unpacker_class):
unpacker = unpacker_class() unpacker = unpacker_class(raw=False)
data = msgpack.packb(self.test_data) data = msgpack.packb(self.test_data, use_bin_type=True)
data += msgpack.packb(self.test_data) data += msgpack.packb(self.test_data, use_bin_type=True)
messages = [] messages = []
for char in data: for char in data:
@ -36,8 +37,8 @@ class TestMsgpack:
data = {"cmd": "response", "params": f} data = {"cmd": "response", "params": f}
out_buff = StringIO.StringIO() out_buff = io.BytesIO()
StreamingMsgpack.stream(data, out_buff.write) Msgpack.stream(data, out_buff.write)
out_buff.seek(0) out_buff.seek(0)
data_packb = {"cmd": "response", "params": open("%s/users.json" % config.data_dir).read(10)} data_packb = {"cmd": "response", "params": open("%s/users.json" % config.data_dir).read(10)}