mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-19 20:03:16 +00:00
blacken test
This commit is contained in:
parent
e557e17cbd
commit
10e5e39ff9
16 changed files with 501 additions and 334 deletions
|
@ -5,30 +5,32 @@ from msgpack import packb, unpackb, ExtType
|
|||
|
||||
|
||||
def test_namedtuple():
|
||||
T = namedtuple('T', "foo bar")
|
||||
T = namedtuple("T", "foo bar")
|
||||
|
||||
def default(o):
|
||||
if isinstance(o, T):
|
||||
return dict(o._asdict())
|
||||
raise TypeError('Unsupported type %s' % (type(o),))
|
||||
raise TypeError("Unsupported type %s" % (type(o),))
|
||||
|
||||
packed = packb(T(1, 42), strict_types=True, use_bin_type=True, default=default)
|
||||
unpacked = unpackb(packed, raw=False)
|
||||
assert unpacked == {'foo': 1, 'bar': 42}
|
||||
assert unpacked == {"foo": 1, "bar": 42}
|
||||
|
||||
|
||||
def test_tuple():
|
||||
t = ('one', 2, b'three', (4, ))
|
||||
t = ("one", 2, b"three", (4,))
|
||||
|
||||
def default(o):
|
||||
if isinstance(o, tuple):
|
||||
return {
|
||||
'__type__': 'tuple',
|
||||
'value': list(o),
|
||||
}
|
||||
raise TypeError('Unsupported type %s' % (type(o),))
|
||||
"__type__": "tuple",
|
||||
"value": list(o),
|
||||
}
|
||||
raise TypeError("Unsupported type %s" % (type(o),))
|
||||
|
||||
def convert(o):
|
||||
if o.get('__type__') == 'tuple':
|
||||
return tuple(o['value'])
|
||||
if o.get("__type__") == "tuple":
|
||||
return tuple(o["value"])
|
||||
return o
|
||||
|
||||
data = packb(t, strict_types=True, use_bin_type=True, default=default)
|
||||
|
@ -38,7 +40,7 @@ def test_tuple():
|
|||
|
||||
|
||||
def test_tuple_ext():
|
||||
t = ('one', 2, b'three', (4, ))
|
||||
t = ("one", 2, b"three", (4,))
|
||||
|
||||
MSGPACK_EXT_TYPE_TUPLE = 0
|
||||
|
||||
|
@ -46,7 +48,8 @@ def test_tuple_ext():
|
|||
if isinstance(o, tuple):
|
||||
# Convert to list and pack
|
||||
payload = packb(
|
||||
list(o), strict_types=True, use_bin_type=True, default=default)
|
||||
list(o), strict_types=True, use_bin_type=True, default=default
|
||||
)
|
||||
return ExtType(MSGPACK_EXT_TYPE_TUPLE, payload)
|
||||
raise TypeError(repr(o))
|
||||
|
||||
|
@ -54,7 +57,7 @@ def test_tuple_ext():
|
|||
if code == MSGPACK_EXT_TYPE_TUPLE:
|
||||
# Unpack and convert to tuple
|
||||
return tuple(unpackb(payload, raw=False, ext_hook=convert))
|
||||
raise ValueError('Unknown Ext code {}'.format(code))
|
||||
raise ValueError("Unknown Ext code {}".format(code))
|
||||
|
||||
data = packb(t, strict_types=True, use_bin_type=True, default=default)
|
||||
expected = unpackb(data, raw=False, ext_hook=convert)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue