11#!/usr/bin/env python
22# coding: utf-8
33
4-
54from array import array
65from msgpack import packb , unpackb
76import sys
@@ -33,7 +32,7 @@ def get_data(a):
3332 return a .tobytes ()
3433
3534
36- def __run_test (format , nbytes , expected_header , expected_prefix , use_bin_type ):
35+ def _runtest (format , nbytes , expected_header , expected_prefix , use_bin_type ):
3736 # create a new array
3837 original_array = array (format )
3938 original_array .fromlist ([255 ] * (nbytes // original_array .itemsize ))
@@ -58,56 +57,56 @@ def __run_test(format, nbytes, expected_header, expected_prefix, use_bin_type):
5857
5958
6059def test_fixstr_from_byte ():
61- __run_test ('B' , 1 , b'\xa1 ' , b'' , False )
62- __run_test ('B' , 31 , b'\xbf ' , b'' , False )
60+ _runtest ('B' , 1 , b'\xa1 ' , b'' , False )
61+ _runtest ('B' , 31 , b'\xbf ' , b'' , False )
6362
6463
6564def test_fixstr_from_float ():
66- __run_test ('f' , 4 , b'\xa4 ' , b'' , False )
67- __run_test ('f' , 28 , b'\xbc ' , b'' , False )
65+ _runtest ('f' , 4 , b'\xa4 ' , b'' , False )
66+ _runtest ('f' , 28 , b'\xbc ' , b'' , False )
6867
6968
7069def test_str16_from_byte ():
71- __run_test ('B' , 2 ** 8 , b'\xda ' , b'\x01 \x00 ' , False )
72- __run_test ('B' , 2 ** 16 - 1 , b'\xda ' , b'\xff \xff ' , False )
70+ _runtest ('B' , 2 ** 8 , b'\xda ' , b'\x01 \x00 ' , False )
71+ _runtest ('B' , 2 ** 16 - 1 , b'\xda ' , b'\xff \xff ' , False )
7372
7473
7574def test_str16_from_float ():
76- __run_test ('f' , 2 ** 8 , b'\xda ' , b'\x01 \x00 ' , False )
77- __run_test ('f' , 2 ** 16 - 4 , b'\xda ' , b'\xff \xfc ' , False )
75+ _runtest ('f' , 2 ** 8 , b'\xda ' , b'\x01 \x00 ' , False )
76+ _runtest ('f' , 2 ** 16 - 4 , b'\xda ' , b'\xff \xfc ' , False )
7877
7978
8079def test_str32_from_byte ():
81- __run_test ('B' , 2 ** 16 , b'\xdb ' , b'\x00 \x01 \x00 \x00 ' , False )
80+ _runtest ('B' , 2 ** 16 , b'\xdb ' , b'\x00 \x01 \x00 \x00 ' , False )
8281
8382
8483def test_str32_from_float ():
85- __run_test ('f' , 2 ** 16 , b'\xdb ' , b'\x00 \x01 \x00 \x00 ' , False )
84+ _runtest ('f' , 2 ** 16 , b'\xdb ' , b'\x00 \x01 \x00 \x00 ' , False )
8685
8786
8887def test_bin8_from_byte ():
89- __run_test ('B' , 1 , b'\xc4 ' , b'\x01 ' , True )
90- __run_test ('B' , 2 ** 8 - 1 , b'\xc4 ' , b'\xff ' , True )
88+ _runtest ('B' , 1 , b'\xc4 ' , b'\x01 ' , True )
89+ _runtest ('B' , 2 ** 8 - 1 , b'\xc4 ' , b'\xff ' , True )
9190
9291
9392def test_bin8_from_float ():
94- __run_test ('f' , 4 , b'\xc4 ' , b'\x04 ' , True )
95- __run_test ('f' , 2 ** 8 - 4 , b'\xc4 ' , b'\xfc ' , True )
93+ _runtest ('f' , 4 , b'\xc4 ' , b'\x04 ' , True )
94+ _runtest ('f' , 2 ** 8 - 4 , b'\xc4 ' , b'\xfc ' , True )
9695
9796
9897def test_bin16_from_byte ():
99- __run_test ('B' , 2 ** 8 , b'\xc5 ' , b'\x01 \x00 ' , True )
100- __run_test ('B' , 2 ** 16 - 1 , b'\xc5 ' , b'\xff \xff ' , True )
98+ _runtest ('B' , 2 ** 8 , b'\xc5 ' , b'\x01 \x00 ' , True )
99+ _runtest ('B' , 2 ** 16 - 1 , b'\xc5 ' , b'\xff \xff ' , True )
101100
102101
103102def test_bin16_from_float ():
104- __run_test ('f' , 2 ** 8 , b'\xc5 ' , b'\x01 \x00 ' , True )
105- __run_test ('f' , 2 ** 16 - 4 , b'\xc5 ' , b'\xff \xfc ' , True )
103+ _runtest ('f' , 2 ** 8 , b'\xc5 ' , b'\x01 \x00 ' , True )
104+ _runtest ('f' , 2 ** 16 - 4 , b'\xc5 ' , b'\xff \xfc ' , True )
106105
107106
108107def test_bin32_from_byte ():
109- __run_test ('B' , 2 ** 16 , b'\xc6 ' , b'\x00 \x01 \x00 \x00 ' , True )
108+ _runtest ('B' , 2 ** 16 , b'\xc6 ' , b'\x00 \x01 \x00 \x00 ' , True )
110109
111110
112111def test_bin32_from_float ():
113- __run_test ('f' , 2 ** 16 , b'\xc6 ' , b'\x00 \x01 \x00 \x00 ' , True )
112+ _runtest ('f' , 2 ** 16 , b'\xc6 ' , b'\x00 \x01 \x00 \x00 ' , True )
0 commit comments