test_format.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # coding: utf-8
  2. from pandas.io.msgpack import unpackb
  3. def check(src, should, use_list=0):
  4. assert unpackb(src, use_list=use_list) == should
  5. def testSimpleValue():
  6. check(b"\x93\xc0\xc2\xc3", (None, False, True, ))
  7. def testFixnum():
  8. check(b"\x92\x93\x00\x40\x7f\x93\xe0\xf0\xff", ((0,
  9. 64,
  10. 127, ),
  11. (-32,
  12. -16,
  13. -1, ), ))
  14. def testFixArray():
  15. check(b"\x92\x90\x91\x91\xc0", ((), ((None, ), ), ), )
  16. def testFixRaw():
  17. check(b"\x94\xa0\xa1a\xa2bc\xa3def", (b"", b"a", b"bc", b"def", ), )
  18. def testFixMap():
  19. check(b"\x82\xc2\x81\xc0\xc0\xc3\x81\xc0\x80",
  20. {False: {None: None},
  21. True: {None: {}}}, )
  22. def testUnsignedInt():
  23. check(b"\x99\xcc\x00\xcc\x80\xcc\xff\xcd\x00\x00\xcd\x80\x00"
  24. b"\xcd\xff\xff\xce\x00\x00\x00\x00\xce\x80\x00\x00\x00"
  25. b"\xce\xff\xff\xff\xff",
  26. (0,
  27. 128,
  28. 255,
  29. 0,
  30. 32768,
  31. 65535,
  32. 0,
  33. 2147483648,
  34. 4294967295, ), )
  35. def testSignedInt():
  36. check(b"\x99\xd0\x00\xd0\x80\xd0\xff\xd1\x00\x00\xd1\x80\x00"
  37. b"\xd1\xff\xff\xd2\x00\x00\x00\x00\xd2\x80\x00\x00\x00"
  38. b"\xd2\xff\xff\xff\xff", (0,
  39. -128,
  40. -1,
  41. 0,
  42. -32768,
  43. -1,
  44. 0,
  45. -2147483648,
  46. -1, ))
  47. def testRaw():
  48. check(b"\x96\xda\x00\x00\xda\x00\x01a\xda\x00\x02ab\xdb\x00\x00"
  49. b"\x00\x00\xdb\x00\x00\x00\x01a\xdb\x00\x00\x00\x02ab",
  50. (b"", b"a", b"ab", b"", b"a", b"ab"))
  51. def testArray():
  52. check(b"\x96\xdc\x00\x00\xdc\x00\x01\xc0\xdc\x00\x02\xc2\xc3\xdd\x00"
  53. b"\x00\x00\x00\xdd\x00\x00\x00\x01\xc0\xdd\x00\x00\x00\x02"
  54. b"\xc2\xc3", ((), (None, ), (False, True), (), (None, ),
  55. (False, True)))
  56. def testMap():
  57. check(b"\x96"
  58. b"\xde\x00\x00"
  59. b"\xde\x00\x01\xc0\xc2"
  60. b"\xde\x00\x02\xc0\xc2\xc3\xc2"
  61. b"\xdf\x00\x00\x00\x00"
  62. b"\xdf\x00\x00\x00\x01\xc0\xc2"
  63. b"\xdf\x00\x00\x00\x02\xc0\xc2\xc3\xc2", ({}, {None: False},
  64. {True: False,
  65. None: False}, {},
  66. {None: False},
  67. {True: False,
  68. None: False}))