-
Notifications
You must be signed in to change notification settings - Fork 10
/
helper.py
executable file
·83 lines (77 loc) · 2.09 KB
/
helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
# This will create golden files in a directory passed to it.
# A Test calls this internally to create the golden files
# So it can process them (so we don't have to checkin the files).
import msgpack, sys, os
def get_test_data_list():
# get list with all primitive types, and a combo type
l = [
-8,
-1616,
-32323232,
-6464646464646464,
8,
1616,
32323232,
6464646464646464,
8,
-3232.0,
-6464646464.0,
3232.0,
6464646464.0,
False,
True,
None,
1328148122000002,
"someday",
"",
"bytestring",
[
-8,
-1616,
-32323232,
-6464646464646464,
8,
1616,
32323232,
6464646464646464,
8,
-3232.0,
-6464646464.0,
3232.0,
6464646464.0,
False,
True,
None,
1328148122000002,
"someday",
"",
"bytestring"
],
{ "true": True,
"false": False },
{ "true": "True",
"false": False,
"int64(0)": 0 },
{ "list": [1616, 32323232, True, -3232.0, {"TRUE":True, "FALSE":False}, [True, False] ],
"int32":32323232, "bool": True,
"LONG STRING": "123456789012345678901234567890123456789012345678901234567890",
"SHORT STRING": "1234567890" },
{ True: "true", 8: False, "false": 0 }
]
return l
def build_test_data(destdir):
l = get_test_data_list()
for i in range(len(l)):
packer = msgpack.Packer()
serialized = packer.pack(l[i])
f = open(os.path.join(destdir, str(i) + '.golden'), 'wb')
f.write(serialized)
f.close()
def doMain(args):
if len(args) == 2 and args[0] == "testdata":
build_test_data(args[1])
else:
print("Usage: build.py [testdata]")
if __name__ == "__main__":
doMain(sys.argv[1:])