msgpack-python/test/test_limits.py

61 lines
1.4 KiB
Python
Raw Normal View History

2014-03-26 02:49:03 +09:00
#!/usr/bin/env python
# coding: utf-8
2014-03-26 13:32:28 +09:00
from __future__ import absolute_import, division, print_function, unicode_literals
2014-03-26 02:49:03 +09:00
import pytest
2014-03-26 03:00:47 +09:00
from msgpack import packb, unpackb, Packer
2014-03-26 02:49:03 +09:00
def test_integer():
x = -(2 ** 63)
assert unpackb(packb(x)) == x
with pytest.raises((OverflowError, ValueError)):
2014-03-26 02:49:03 +09:00
packb(x-1)
x = 2 ** 64 - 1
assert unpackb(packb(x)) == x
with pytest.raises((OverflowError, ValueError)):
2014-03-26 02:49:03 +09:00
packb(x+1)
2014-03-26 03:00:47 +09:00
def test_array_header():
packer = Packer()
packer.pack_array_header(2**32-1)
with pytest.raises(ValueError):
packer.pack_array_header(2**32)
def test_map_header():
packer = Packer()
packer.pack_map_header(2**32-1)
with pytest.raises(ValueError):
packer.pack_array_header(2**32)
2014-03-26 11:01:44 +09:00
@pytest.mark.skipif(True, reason="Requires very large memory.")
2014-03-26 02:49:03 +09:00
def test_binary():
x = b'x' * (2**32 - 1)
assert unpackb(packb(x)) == x
2014-03-26 03:00:47 +09:00
del x
x = b'x' * (2**32)
2014-03-26 02:49:03 +09:00
with pytest.raises(ValueError):
packb(x)
2014-03-26 11:01:44 +09:00
@pytest.mark.skipif(True, reason="Requires very large memory.")
2014-03-26 02:49:03 +09:00
def test_string():
2014-03-26 13:32:28 +09:00
x = 'x' * (2**32 - 1)
2014-03-26 02:49:03 +09:00
assert unpackb(packb(x)) == x
2014-03-26 13:32:28 +09:00
x += 'y'
2014-03-26 02:49:03 +09:00
with pytest.raises(ValueError):
packb(x)
2014-03-26 11:01:44 +09:00
@pytest.mark.skipif(True, reason="Requires very large memory.")
2014-03-26 02:49:03 +09:00
def test_array():
x = [0] * (2**32 - 1)
assert unpackb(packb(x)) == x
x.append(0)
with pytest.raises(ValueError):
packb(x)