diff options
-rw-r--r-- | test/test_pack.py | 16 | ||||
-rw-r--r-- | test/test_seq.py | 19 | ||||
-rw-r--r-- | test/test_sequnpack.py | 14 | ||||
-rw-r--r-- | tox.ini | 1 |
4 files changed, 26 insertions, 24 deletions
diff --git a/test/test_pack.py b/test/test_pack.py index 480af28..88b6dac 100644 --- a/test/test_pack.py +++ b/test/test_pack.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # coding: utf-8 +import six from nose import main from nose.tools import * from nose.plugins.skip import SkipTest @@ -29,7 +30,7 @@ def testPack(): def testPackUnicode(): test_data = [ - "", "abcd", ("defgh",), "Русский текст", + six.u(""), six.u("abcd"), (six.u("defgh"),), six.u("Русский текст"), ] for td in test_data: re = unpacks(packs(td, encoding='utf-8'), encoding='utf-8') @@ -42,7 +43,10 @@ def testPackUnicode(): def testPackUTF32(): try: test_data = [ - "", "abcd", ("defgh",), "Русский текст", + six.u(""), + six.u("abcd"), + (six.u("defgh"),), + six.u("Русский текст"), ] for td in test_data: re = unpacks(packs(td, encoding='utf-32'), encoding='utf-32') @@ -68,15 +72,15 @@ def testStrictUnicodeUnpack(): @raises(UnicodeEncodeError) def testStrictUnicodePack(): - packs("abc\xeddef", encoding='ascii', unicode_errors='strict') + packs(six.u("abc\xeddef"), encoding='ascii', unicode_errors='strict') def testIgnoreErrorsPack(): - re = unpacks(packs("abcФФФdef", encoding='ascii', unicode_errors='ignore'), encoding='utf-8') - assert_equal(re, "abcdef") + re = unpacks(packs(six.u("abcФФФdef"), encoding='ascii', unicode_errors='ignore'), encoding='utf-8') + assert_equal(re, six.u("abcdef")) @raises(TypeError) def testNoEncoding(): - packs("abc", encoding=None) + packs(six.u("abc"), encoding=None) def testDecodeBinary(): re = unpacks(packs("abc"), encoding=None) diff --git a/test/test_seq.py b/test/test_seq.py index 993a59e..d0f9ccc 100644 --- a/test/test_seq.py +++ b/test/test_seq.py @@ -1,21 +1,22 @@ #!/usr/bin/env python # coding: utf-8 +import six from nose import main from nose.tools import * -import StringIO +import io import msgpack -binarydata = [chr(i) for i in xrange(256)] -binarydata = "".join(binarydata) +binarydata = [chr(i) for i in range(256)] +binarydata = six.b("".join(binarydata)) def gen_binary_data(idx): data = binarydata[:idx % 300] return data def test_exceeding_unpacker_read_size(): - dumpf = StringIO.StringIO() + dumpf = io.BytesIO() packer = msgpack.Packer() @@ -26,18 +27,18 @@ def test_exceeding_unpacker_read_size(): # 40 ok for read_size=1024, while 50 introduces errors # 7000 ok for read_size=1024*1024, while 8000 leads to glibc detected *** python: double free or corruption (!prev): - for idx in xrange(NUMBER_OF_STRINGS): + for idx in range(NUMBER_OF_STRINGS): data = gen_binary_data(idx) dumpf.write(packer.pack(data)) - f = StringIO.StringIO(dumpf.getvalue()) + f = io.BytesIO(dumpf.getvalue()) dumpf.close() unpacker = msgpack.Unpacker(f, read_size=read_size) read_count = 0 for idx, o in enumerate(unpacker): - assert_equal(type(o), str) + assert_equal(type(o), bytes) assert_equal(o, gen_binary_data(idx)) read_count += 1 @@ -45,5 +46,5 @@ def test_exceeding_unpacker_read_size(): if __name__ == '__main__': - # main() - test_exceeding_unpacker_read_size() + main() + #test_exceeding_unpacker_read_size() diff --git a/test/test_sequnpack.py b/test/test_sequnpack.py index 5fd377c..774fe1b 100644 --- a/test/test_sequnpack.py +++ b/test/test_sequnpack.py @@ -1,8 +1,6 @@ #!/usr/bin/env python # coding: utf-8 - - from msgpack import Unpacker def test_foobar(): @@ -16,18 +14,16 @@ def test_foobar(): assert unpacker.unpack() == ord(b'r') try: o = unpacker.unpack() - print(("Oops!", o)) - assert 0 + assert 0, "should raise exception" except StopIteration: - assert 1 - else: - assert 0 + assert 1, "ok" + unpacker.feed(b'foo') unpacker.feed(b'bar') k = 0 - for o, e in zip(unpacker, b'foobarbaz'): - assert o == e + for o, e in zip(unpacker, 'foobarbaz'): + assert o == ord(e) k += 1 assert k == len(b'foobar') @@ -3,5 +3,6 @@ envlist = py26,py27,py32 [testenv] deps= nose + six commands=nosetests -w test |