test_ints.py 771 B

123456789101112131415161718192021222324252627
  1. from erlpack import pack
  2. from pytest import raises
  3. def test_smallint():
  4. for i in xrange(256):
  5. assert pack(i) == '\x83a%s' % chr(i)
  6. def test_int():
  7. assert pack(1024) == '\x83b\x00\x00\x04\x00'
  8. assert pack(-2147483648) == '\x83b\x80\x00\x00\x00'
  9. assert pack(2147483647) == '\x83b\x7f\xff\xff\xff'
  10. def test_unsigned_long_long():
  11. assert pack(2147483648) == '\x83n\x04\x00\x00\x00\x00\x80'
  12. assert pack(1230941823049123411) == '\x83n\x08\x00S\xc6\x03\xf6\x10/\x15\x11'
  13. def test_long_long():
  14. assert pack(-2147483649) == '\x83n\x04\x01\x01\x00\x00\x80'
  15. assert pack(-123094182304912341) == '\x83n\x08\x01\xd5\x933\xb2\x81Q\xb5\x01'
  16. def test_really_big_ints():
  17. with raises(OverflowError):
  18. pack(123094182304912341123414)