diff options
author | INADA Naoki <inada-n@klab.com> | 2014-02-13 09:55:17 +0900 |
---|---|---|
committer | INADA Naoki <inada-n@klab.com> | 2014-02-13 09:55:17 +0900 |
commit | 0cab6092e456ffa04834233ffb01acb48d0869c3 (patch) | |
tree | 6d87f1148a6c29097346eee02b588609f7fc52f9 /test/test_unpack.py | |
parent | 38cf835c95273dc20dd6cb3376c11a88b72c7fa9 (diff) | |
download | msgpack-python-0cab6092e456ffa04834233ffb01acb48d0869c3.tar.gz |
Add refcount check.
Diffstat (limited to 'test/test_unpack.py')
-rw-r--r-- | test/test_unpack.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/test/test_unpack.py b/test/test_unpack.py index 1563008..d6ca435 100644 --- a/test/test_unpack.py +++ b/test/test_unpack.py @@ -1,6 +1,7 @@ from io import BytesIO +import sys from msgpack import Unpacker, packb, OutOfData -from pytest import raises +from pytest import raises, mark def test_unpack_array_header_from_file(): @@ -15,5 +16,32 @@ def test_unpack_array_header_from_file(): unpacker.unpack() +@mark.skipif(not hasattr(sys, 'getrefcount'), + reason='sys.getrefcount() is needed to pass this test') +def test_unpacker_hook_refcnt(): + result = [] + + def hook(x): + result.append(x) + return x + + basecnt = sys.getrefcount(hook) + + up = Unpacker(object_pairs_hook=hook, list_hook=hook) + + assert sys.getrefcount(hook) >= basecnt + 2 + + up.feed(packb([{}])) + up.feed(packb([{}])) + assert up.unpack() == [{}] + assert up.unpack() == [{}] + assert result == [[{}], [{}]] + + del up + + assert sys.getrefcount(hook) == basecnt + + if __name__ == '__main__': test_unpack_array_header_from_file() + test_unpacker_hook_refcnt() |