mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-28 08:04:12 +00:00
Add refcount check.
This commit is contained in:
parent
38cf835c95
commit
0cab6092e4
2 changed files with 29 additions and 20 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue