From 6c0c306f966c5cb1caeb2d6b0712ae3d0edd4d82 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Wed, 26 Mar 2014 02:49:03 +0900 Subject: Add tests for limits. --- test/test_limits.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 test/test_limits.py (limited to 'test') 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) -- cgit v1.2.1 From e7f87d9d41532b0956ebcd9f7be52df979842466 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Wed, 26 Mar 2014 03:00:47 +0900 Subject: More limit check. --- test/test_limits.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/test_limits.py b/test/test_limits.py index 970f722..2879c0a 100644 --- a/test/test_limits.py +++ b/test/test_limits.py @@ -2,7 +2,7 @@ # coding: utf-8 import pytest -from msgpack import packb, unpackb +from msgpack import packb, unpackb, Packer def test_integer(): @@ -16,11 +16,27 @@ def test_integer(): with pytest.raises(OverflowError): 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) + + @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' + del x + x = b'x' * (2**32) with pytest.raises(ValueError): packb(x) -- cgit v1.2.1 From e99331d1ab793105da2e0a4139059169e5c835b3 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Wed, 26 Mar 2014 11:01:44 +0900 Subject: Fix skipif marking. --- test/test_limits.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/test_limits.py b/test/test_limits.py index 2879c0a..5d285e7 100644 --- a/test/test_limits.py +++ b/test/test_limits.py @@ -31,7 +31,7 @@ def test_map_header(): packer.pack_array_header(2**32) -@pytest.mark.skipif(True, "Requires very large memory.") +@pytest.mark.skipif(True, reason="Requires very large memory.") def test_binary(): x = b'x' * (2**32 - 1) assert unpackb(packb(x)) == x @@ -41,7 +41,7 @@ def test_binary(): packb(x) -@pytest.mark.skipif(True, "Requires very large memory.") +@pytest.mark.skipif(True, reason="Requires very large memory.") def test_string(): x = u'x' * (2**32 - 1) assert unpackb(packb(x)) == x @@ -50,7 +50,7 @@ def test_string(): packb(x) -@pytest.mark.skipif(True, "Requires very large memory.") +@pytest.mark.skipif(True, reason="Requires very large memory.") def test_array(): x = [0] * (2**32 - 1) assert unpackb(packb(x)) == x -- cgit v1.2.1 From 7d0e145e91700ee58c5accaeb5dff6a9ec39a18d Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Wed, 26 Mar 2014 12:50:28 +0900 Subject: Allow ValueError for packing integer overs format limit. --- test/test_limits.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/test_limits.py b/test/test_limits.py index 5d285e7..413d651 100644 --- a/test/test_limits.py +++ b/test/test_limits.py @@ -8,12 +8,12 @@ from msgpack import packb, unpackb, Packer def test_integer(): x = -(2 ** 63) assert unpackb(packb(x)) == x - with pytest.raises(OverflowError): + with pytest.raises((OverflowError, ValueError)): packb(x-1) x = 2 ** 64 - 1 assert unpackb(packb(x)) == x - with pytest.raises(OverflowError): + with pytest.raises((OverflowError, ValueError)): packb(x+1) -- cgit v1.2.1 From 5fb9d8a7fd09893afdd1e5844288313bb347856b Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Wed, 26 Mar 2014 13:32:28 +0900 Subject: Fix Python 3.2 --- test/test_limits.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/test_limits.py b/test/test_limits.py index 413d651..7bc8f4c 100644 --- a/test/test_limits.py +++ b/test/test_limits.py @@ -1,5 +1,6 @@ #!/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 @@ -43,9 +44,9 @@ def test_binary(): @pytest.mark.skipif(True, reason="Requires very large memory.") def test_string(): - x = u'x' * (2**32 - 1) + x = 'x' * (2**32 - 1) assert unpackb(packb(x)) == x - x += u'y' + x += 'y' with pytest.raises(ValueError): packb(x) -- cgit v1.2.1 From a72e75d7c81486bc2775b957b22d3b5e13742589 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Wed, 26 Mar 2014 15:12:28 +0900 Subject: Fix PyPy fail. --- test/test_limits.py | 54 +++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) (limited to 'test') diff --git a/test/test_limits.py b/test/test_limits.py index 7bc8f4c..da8cd2b 100644 --- a/test/test_limits.py +++ b/test/test_limits.py @@ -32,29 +32,31 @@ def test_map_header(): packer.pack_array_header(2**32) -@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) +# 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) -- cgit v1.2.1