msgpack_test.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env python
  2. # This will create golden files in a directory passed to it.
  3. # A Test calls this internally to create the golden files
  4. # So it can process them (so we don't have to checkin the files).
  5. import msgpack, sys, os
  6. def get_test_data_list():
  7. # get list with all primitive types, and a combo type
  8. l0 = [
  9. -8,
  10. -1616,
  11. -32323232,
  12. -6464646464646464,
  13. 192,
  14. 1616,
  15. 32323232,
  16. 6464646464646464,
  17. 192,
  18. -3232.0,
  19. -6464646464.0,
  20. 3232.0,
  21. 6464646464.0,
  22. False,
  23. True,
  24. None,
  25. "someday",
  26. "",
  27. "bytestring",
  28. 1328176922000002000,
  29. -2206187877999998000,
  30. 0,
  31. -6795364578871345152
  32. ]
  33. l1 = [
  34. { "true": True,
  35. "false": False },
  36. { "true": "True",
  37. "false": False,
  38. "uint16(1616)": 1616 },
  39. { "list": [1616, 32323232, True, -3232.0, {"TRUE":True, "FALSE":False}, [True, False] ],
  40. "int32":32323232, "bool": True,
  41. "LONG STRING": "123456789012345678901234567890123456789012345678901234567890",
  42. "SHORT STRING": "1234567890" },
  43. { True: "true", 8: False, "false": 0 }
  44. ]
  45. l = []
  46. l.extend(l0)
  47. l.append(l0)
  48. l.extend(l1)
  49. return l
  50. def build_test_data(destdir):
  51. l = get_test_data_list()
  52. for i in range(len(l)):
  53. packer = msgpack.Packer()
  54. serialized = packer.pack(l[i])
  55. f = open(os.path.join(destdir, str(i) + '.golden'), 'wb')
  56. f.write(serialized)
  57. f.close()
  58. def doMain(args):
  59. if len(args) == 2 and args[0] == "testdata":
  60. build_test_data(args[1])
  61. else:
  62. print("Usage: build.py [testdata]")
  63. if __name__ == "__main__":
  64. doMain(sys.argv[1:])