msgpack_test.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. l = [
  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. 1328148122000002,
  26. "someday",
  27. "",
  28. "bytestring",
  29. [
  30. -8,
  31. -1616,
  32. -32323232,
  33. -6464646464646464,
  34. 192,
  35. 1616,
  36. 32323232,
  37. 6464646464646464,
  38. 192,
  39. -3232.0,
  40. -6464646464.0,
  41. 3232.0,
  42. 6464646464.0,
  43. False,
  44. True,
  45. None,
  46. 1328148122000002,
  47. "someday",
  48. "",
  49. "bytestring"
  50. ],
  51. { "true": True,
  52. "false": False },
  53. { "true": "True",
  54. "false": False,
  55. "uint16(1616)": 1616 },
  56. { "list": [1616, 32323232, True, -3232.0, {"TRUE":True, "FALSE":False}, [True, False] ],
  57. "int32":32323232, "bool": True,
  58. "LONG STRING": "123456789012345678901234567890123456789012345678901234567890",
  59. "SHORT STRING": "1234567890" },
  60. { True: "true", 8: False, "false": 0 }
  61. ]
  62. return l
  63. def build_test_data(destdir):
  64. l = get_test_data_list()
  65. for i in range(len(l)):
  66. packer = msgpack.Packer()
  67. serialized = packer.pack(l[i])
  68. f = open(os.path.join(destdir, str(i) + '.golden'), 'wb')
  69. f.write(serialized)
  70. f.close()
  71. def doMain(args):
  72. if len(args) == 2 and args[0] == "testdata":
  73. build_test_data(args[1])
  74. else:
  75. print("Usage: build.py [testdata]")
  76. if __name__ == "__main__":
  77. doMain(sys.argv[1:])