summaryrefslogtreecommitdiff
path: root/test/test_limits.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_limits.py')
-rw-r--r--test/test_limits.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/test/test_limits.py b/test/test_limits.py
new file mode 100644
index 0000000..da8cd2b
--- /dev/null
+++ b/test/test_limits.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+# coding: utf-8
+from __future__ import absolute_import, division, print_function, unicode_literals
+import pytest
+
+from msgpack import packb, unpackb, Packer
+
+
+def test_integer():
+ x = -(2 ** 63)
+ assert unpackb(packb(x)) == x
+ with pytest.raises((OverflowError, ValueError)):
+ packb(x-1)
+
+ x = 2 ** 64 - 1
+ assert unpackb(packb(x)) == x
+ with pytest.raises((OverflowError, ValueError)):
+ packb(x+1)
+
+
+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)
+
+
+# PyPy fails following tests because of constant folding?
+# https://bugs.pypy.org/issue1721
+#@pytest.mark.skipif(True, reason="Requires very large memory.")
+#def test_binary():
+# x = b'x' * (2**32 - 1)
+# assert unpackb(packb(x)) == x
+# del x
+# x = b'x' * (2**32)
+# with pytest.raises(ValueError):
+# packb(x)
+#
+#
+#@pytest.mark.skipif(True, reason="Requires very large memory.")
+#def test_string():
+# x = 'x' * (2**32 - 1)
+# assert unpackb(packb(x)) == x
+# x += 'y'
+# with pytest.raises(ValueError):
+# packb(x)
+#
+#
+#@pytest.mark.skipif(True, reason="Requires very large memory.")
+#def test_array():
+# x = [0] * (2**32 - 1)
+# assert unpackb(packb(x)) == x
+# x.append(0)
+# with pytest.raises(ValueError):
+# packb(x)