8000 blacken test · ossdev07/msgpack-python@10e5e39 · GitHub
[go: up one dir, main page]

Skip to content

Commit 10e5e39

Browse files
committed
blacken test
1 parent e557e17 commit 10e5e39

16 files changed

+501
-334
lines changed

test/test_buffer.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,28 @@
66

77
def test_unpack_buffer():
88
from array import array
9-
buf = array('b')
9+
10+
buf = array("b")
1011
try:
11-
buf.frombytes(packb((b'foo', b'bar')))
12+
buf.frombytes(packb((b"foo", b"bar")))
1213
except AttributeError: # PY2
13-
buf.fromstring(packb((b'foo', b'bar')))
14+
buf.fromstring(packb((b"foo", b"bar")))
1415
obj = unpackb(buf, use_list=1)
15-
assert [b'foo', b'bar'] == obj
16+
assert [b"foo", b"bar"] == obj
1617

1718

1819
def test_unpack_bytearray():
19-
buf = bytearray(packb(('foo', 'bar')))
20+
buf = bytearray(packb(("foo", "bar")))
2021
obj = unpackb(buf, use_list=1)
21-
assert [b'foo', b'bar'] == obj
22+
assert [b"foo", b"bar"] == obj
2223
expected_type = bytes
2324
assert all(type(s) == expected_type for s in obj)
2425

2526

2627
def test_unpack_memoryview():
27-
buf = bytearray(packb(('foo', 'bar')))
28+
buf = bytearray(packb(("foo", "bar")))
2829
view = memoryview(buf)
2930
obj = unpackb(view, use_list=1)
30-
assert [b'foo', b'bar'] == obj
31+
assert [b"foo", b"bar"] == obj
3132
expected_type = bytes
3233
assert all(type(s) == expected_type for s in obj)

test/test_case.py

Lines changed: 76 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,97 +6,133 @@
66

77
def check(length, obj):
88
v = packb(obj)
9-
assert len(v) == length, \
10-
"%r length should be %r but get %r" % (obj, length, len(v))
9+
assert len(v) == length, "%r length should be %r but get %r" % (obj, length, len(v))
1110
assert unpackb(v, use_list=0) == obj
1211

12+
1313
def test_1():
14-
for o in [None, True, False, 0, 1, (1 << 6), (1 << 7) - 1, -1,
15-
-((1<<5)-1), -(1<<5)]:
14+
for o in [
15+
None,
16+
True,
17+
False,
18+
0,
19+
1,
20+
(1 << 6),
21+
(1 << 7) - 1,
22+
-1,
23+
-((1 << 5) - 1),
24+
-(1 << 5),
25+
]:
1626
check(1, o)
1727

28+
1829
def test_2():
19-
for o in [1 << 7, (1 << 8) - 1,
20-
-((1<<5)+1), -(1<<7)
21-
]:
30+
for o in [1 << 7, (1 << 8) - 1, -((1 << 5) + 1), -(1 << 7)]:
2231
check(2, o)
2332

33+
2434
def test_3():
25-
for o in [1 << 8, (1 << 16) - 1,
26-
-((1<<7)+1), -(1<<15)]:
35+
for o in [1 << 8, (1 << 16) - 1, -((1 << 7) + 1), -(1 << 15)]:
2736
check(3, o)
2837

38+
2939
def test_5():
30-
for o in [1 << 16, (1 << 32) - 1,
31-
-((1<<15)+1), -(1<<31)]:
40+
for o in [1 << 16, (1 << 32) - 1, -((1 << 15) + 1), -(1 << 31)]:
3241
check(5, o)
3342

43+
3444
def test_9():
35-
for o in [1 << 32, (1 << 64) - 1,
36-
-((1<<31)+1), -(1<<63),
37-
1.0, 0.1, -0.1, -1.0]:
45+
for o in [
46+
1 << 32,
47+
(1 << 64) - 1,
48+
-((1 << 31) + 1),
49+
-(1 << 63),
50+
1.0,
51+
0.1,
52+
-0.1,
53+
-1.0,
54+
]:
3855
check(9, o)
3956

4057

4158
def check_raw(overhead, num):
4259
check(num + overhead, b" " * num)
4360

61+
4462
def test_fixraw():
4563
check_raw(1, 0)
46-
check_raw(1, (1<<5) - 1)
64+
check_raw(1, (1 << 5) - 1)
65+
4766

4867
def test_raw16():
49-
check_raw(3, 1<<5)
50-
check_raw(3, (1<<16) - 1)
68+
check_raw(3, 1 << 5)
69+
check_raw(3, (1 << 16) - 1)
70+
5171

5272
def test_raw32():
53-
check_raw(5, 1<<16)
73+
check_raw(5, 1 << 16)
5474

5575

5676
def check_array(overhead, num):
5777
check(num + overhead, (None,) * num)
5878

79+
5980
def test_fixarray():
6081
check_array(1, 0)
6182
check_array(1, (1 << 4) - 1)
6283

84+
6385
def test_array16():
6486
check_array(3, 1 << 4)
65-
check_array(3, (1<<16)-1)
87+
check_array(3, (1 << 16) - 1)
88+
6689

6790
def test_array32():
68-
check_array(5, (1<<16))
91+
check_array(5, (1 << 16))
6992

7093

7194
def match(obj, buf):
7295
assert packb(obj) == buf
7396
assert unpackb(buf, use_list=0) == obj
7497

98+
7599
def test_match():
76100
cases = [
77-
(None, b'\xc0'),
78-
(False, b'\xc2'),
79-
(True, b'\xc3'),
80-
(0, b'\x00'),
81-
(127, b'\x7f'),
82-
(128, b'\xcc\x80'),
83-
(256, b'\xcd\x01\x00'),
84-
(-1, b'\xff'),
85-
(-33, b'\xd0\xdf'),
86-
(-129, b'\xd1\xff\x7f'),
87-
({1:1}, b'\x81\x01\x01'),
101+
(None, b"\xc0"),
102+
(False, b"\xc2"),
103+
(True, b"\xc3"),
104+
(0, b"\x00"),
105+
(127, b"\x7f"),
106+
(128, b"\xcc\x80"),
107+
(256, b"\xcd\x01\x00"),
108+
(-1, b"\xff"),
109+
(-33, b"\xd0\xdf"),
110+
(-129, b"\xd1\xff\x7f"),
111+
({1: 1}, b"\x81\x01\x01"),
88112
(1.0, b"\xcb\x3f\xf0\x00\x00\x00\x00\x00\x00"),
89-
((), b'\x90'),
90-
(tuple(range(15)),b"\x9f\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e"),
91-
(tuple(range(16)),b"\xdc\x00\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"),
92-
({}, b'\x80'),
93-
(dict([(x,x) for x in range(15)]), b'\x8f\x00\x00\x01\x01\x02\x02\x03\x03\x04\x04\x05\x05\x06\x06\x07\x07\x08\x08\t\t\n\n\x0b\x0b\x0c\x0c\r\r\x0e\x0e'),
94-
(dict([(x,x) for x in range(16)]), b'\xde\x00\x10\x00\x00\x01\x01\x02\x02\x03\x03\x04\x04\x05\x05\x06\x06\x07\x07\x08\x08\t\t\n\n\x0b\x0b\x0c\x0c\r\r\x0e\x0e\x0f\x0f'),
95-
]
113+
((), b"\x90"),
114+
(
115+
tuple(range(15)),
116+
b"\x9f\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e",
117+
),
118+
(
119+
tuple(range(16)),
120+
b"\xdc\x00\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
121+
),
122+
({}, b"\x80"),
123+
(
124+
dict([(x, x) for x in range(15)]),
125+
b"\x8f\x00\x00\x01\x01\x02\x02\x03\x03\x04\x04\x05\x05\x06\x06\x07\x07\x08\x08\t\t\n\n\x0b\x0b\x0c\x0c\r\r\x0e\x0e",
126+
),
127+
(
128+
dict([(x, x) for x in range(16)]),
129+
b"\xde\x00\x10\x00\x00\x01\x01\x02\x02\x03\x03\x04\x04\x05\x05\x06\x06\x07\x07\x08\x08\t\t\n\n\x0b\x0b\x0c\x0c\r\r\x0e\x0e\x0f\x0f",
130+
),
131+
]
96132

97133
for v, p in cases:
98134
match(v, p)
99135

100-
def test_unicode():
101-
assert unpackb(packb('foobar'), use_list=1) == b'foobar'
102136

137+
def test_unicode():
138+
assert unpackb(packb("foobar"), use_list=1) == b"foobar"

test/test_extension.py

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,41 @@ def p(s):
99
packer = msgpack.Packer()
1010
packer.pack_ext_type(0x42, s)
1111
return packer.bytes()
12-
assert p(b'A') == b'\xd4\x42A' # fixext 1
13-
assert p(b'AB') == b'\xd5\x42AB' # fixext 2
14-
assert p(b'ABCD') == b'\xd6\x42ABCD' # fixext 4
15-
assert p(b'ABCDEFGH') == b'\xd7\x42ABCDEFGH' # fixext 8
16-
assert p(b'A'*16) == b'\xd8\x42' + b'A'*16 # fixext 16
17-
assert p(b'ABC') == b'\xc7\x03\x42ABC' # ext 8
18-
assert p(b'A'*0x0123) == b'\xc8\x01\x23\x42' + b'A'*0x0123 # ext 16
19-
assert p(b'A'*0x00012345) == b'\xc9\x00\x01\x23\x45\x42' + b'A'*0x00012345 # ext 32
12+
13+
assert p(b"A") == b"\xd4\x42A" # fixext 1
14+
assert p(b"AB") == b"\xd5\x42AB" # fixext 2
15+
assert p(b"ABCD") == b"\xd6\x42ABCD" # fixext 4
16+
assert p(b"ABCDEFGH") == b"\xd7\x42ABCDEFGH" # fixext 8
17+
assert p(b"A" * 16) == b"\xd8\x42" + b"A" * 16 # fixext 16
18+
assert p(b"ABC") == b"\xc7\x03\x42ABC" # ext 8
19+
assert p(b"A" * 0x0123) == b"\xc8\x01\x23\x42" + b"A" * 0x0123 # ext 16
20+
assert (
21+
p(b"A" * 0x00012345) == b"\xc9\x00\x01\x23\x45\x42" + b"A" * 0x00012345
22+
) # ext 32
2023

2124

2225
def test_unpack_ext_type():
2326
def check(b, expected):
2427
assert msgpack.unpackb(b) == expected
2528

26-
check(b'\xd4\x42A', ExtType(0x42, b'A')) # fixext 1
27-
check(b'\xd5\x42AB', ExtType(0x42, b'AB')) # fixext 2
28-
check(b'\xd6\x42ABCD', ExtType(0x42, b'ABCD')) # fixext 4
29-
check(b'\xd7\x42ABCDEFGH', ExtType(0x42, b'ABCDEFGH')) # fixext 8
30-
check(b'\xd8\x42' + b'A'*16, ExtType(0x42, b'A'*16)) # fixext 16
31-
check(b'\xc7\x03\x42ABC', ExtType(0x42, b'ABC')) # ext 8
32-
check(b'\xc8\x01\x23\x42' + b'A'*0x0123,
33-
ExtType(0x42, b'A'*0x0123)) # ext 16
34-
check(b'\xc9\x00\x01\x23\x45\x42' + b'A'*0x00012345,
35-
ExtType(0x42, b'A'*0x00012345)) # ext 32
29+
check(b"\xd4\x42A", ExtType(0x42, b"A")) # fixext 1
30+
check(b"\xd5\x42AB", ExtType(0x42, b"AB")) # fixext 2
31+
check(b"\xd6\x42ABCD", ExtType(0x42, b"ABCD")) # fixext 4
32+
check(b"\xd7\x42ABCDEFGH", ExtType(0x42, b"ABCDEFGH")) # fixext 8
33+
check(b"\xd8\x42" + b"A" * 16, ExtType(0x42, b"A" * 16)) # fixext 16
34+
check(b"\xc7\x03\x42ABC", ExtType(0x42, b"ABC")) # ext 8
35+
check(b"\xc8\x01\x23\x42" + b"A" * 0x0123, ExtType(0x42, b"A" * 0x0123)) # ext 16
36+
check(
37+
b"\xc9\x00\x01\x23\x45\x42" + b"A" * 0x00012345,
38+
ExtType(0x42, b"A" * 0x00012345),
39+
) # ext 32
3640

3741

3842
def test_extension_type():
3943
def default(obj):
40-
print('default called', obj)
44+
print("default called", obj)
4145
if isinstance(obj, array.array):
42-
typecode = 123 # application specific typecode
46+
typecode = 123 # application specific typecode
4347
try:
4448
data = obj.tobytes()
4549
except AttributeError:
@@ -48,24 +52,27 @@ def default(obj):
4852
raise TypeError("Unknown type object %r" % (obj,))
4953

5054
def ext_hook(code, data):
51-
print('ext_hook called', code, data)
55+
print("ext_hook called", code, data)
5256
assert code == 123
53-
obj = array.array('d')
57+
obj = array.array("d")
5458
try:
5559
obj.frombytes(data)
5660
except AttributeError: # PY2
5761
obj.fromstring(data)
5862
return obj
5963

60-
obj = [42, b'hello', array.array('d', [1.1, 2.2, 3.3])]
64+
obj = [42, b"hello", array.array("d", [1.1, 2.2, 3.3])]
6165
s = msgpack.packb(obj, default=default)
6266
obj2 = msgpack.unpackb(s, ext_hook=ext_hook)
6367
assert obj == obj2
6468

69+
6570
import sys
66-
if sys.version > '3':
71+
72+
if sys.version > "3":
6773
long = int
6874

75+
6976
def test_overriding_hooks():
7077
def default(obj):
7178
if isinstance(obj, long):

0 commit comments

Comments
 (0)
0