1
0
mirror of synced 2024-11-12 01:00:46 +01:00
bemaniutils/bemani/tests/test_BaseData.py
2019-12-08 21:43:49 +00:00

49 lines
1.2 KiB
Python

# vim: set fileencoding=utf-8
import unittest
from bemani.data.mysql.base import BaseData
class TestBaseData(unittest.TestCase):
def test_basic_serialize(self) -> None:
data = BaseData({}, None)
testdict = {
'test1': 1,
'test2': '2',
'test3': 3.3,
'test4': [1, 2, 3, 4],
'test5': {
'a': 'b',
},
'testempty': [],
}
self.assertEqual(data.deserialize(data.serialize(testdict)), testdict)
def test_basic_byte_serialize(self) -> None:
data = BaseData({}, None)
testdict = {
'bytes': b'\x01\x02\x03\x04\x05',
}
serialized = data.serialize(testdict)
self.assertEqual(serialized, '{"bytes": ["__bytes__", 1, 2, 3, 4, 5]}')
self.assertEqual(data.deserialize(serialized), testdict)
def test_deep_byte_serialize(self) -> None:
data = BaseData({}, None)
testdict = {
'sentinal': True,
'test': {
'sentinal': False,
'bytes': b'\x01\x02\x03\x04\x05',
'bytes2': b'',
}
}
self.assertEqual(data.deserialize(data.serialize(testdict)), testdict)