summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorINADA Naoki <inada-n@klab.com>2014-03-26 02:49:03 +0900
committerINADA Naoki <inada-n@klab.com>2014-03-26 02:49:03 +0900
commit6c0c306f966c5cb1caeb2d6b0712ae3d0edd4d82 (patch)
treed17099527db8818e76f4de5cbd4ca6eb957fe38f
parente9de6b7f391a4b5e692af37505c959eaf02943e0 (diff)
downloadmsgpack-python-6c0c306f966c5cb1caeb2d6b0712ae3d0edd4d82.tar.gz
Add tests for limits.
-rw-r--r--test/test_limits.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/test_limits.py b/test/test_limits.py
new file mode 100644
index 0000000..970f722
--- /dev/null
+++ b/test/test_limits.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+# coding: utf-8
+import pytest
+
+from msgpack import packb, unpackb
+
+
+def test_integer():
+ x = -(2 ** 63)
+ assert unpackb(packb(x)) == x
+ with pytest.raises(OverflowError):
+ packb(x-1)
+
+ x = 2 ** 64 - 1
+ assert unpackb(packb(x)) == x
+ with pytest.raises(OverflowError):
+ packb(x+1)
+
+@pytest.mark.skipif(True, "Requires very large memory.")
+def test_binary():
+ x = b'x' * (2**32 - 1)
+ assert unpackb(packb(x)) == x
+ x += b'y'
+ with pytest.raises(ValueError):
+ packb(x)
+
+
+@pytest.mark.skipif(True, "Requires very large memory.")
+def test_string():
+ x = u'x' * (2**32 - 1)
+ assert unpackb(packb(x)) == x
+ x += u'y'
+ with pytest.raises(ValueError):
+ packb(x)
+
+
+@pytest.mark.skipif(True, "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)