File tree Expand file tree Collapse file tree 2 files changed +29
-20
lines changed
Expand file tree Collapse file tree 2 files changed +29
-20
lines changed Original file line number Diff line number Diff line change 11from io import BytesIO
2+ import sys
23from msgpack import Unpacker , packb , OutOfData
3- from pytest import raises
4+ from pytest import raises , mark
45
56
67def test_unpack_array_header_from_file ():
@@ -15,5 +16,32 @@ def test_unpack_array_header_from_file():
1516 unpacker .unpack ()
1617
1718
19+ @mark .skipif (not hasattr (sys , 'getrefcount' ),
20+ reason = 'sys.getrefcount() is needed to pass this test' )
21+ def test_unpacker_hook_refcnt ():
22+ result = []
23+
24+ def hook (x ):
25+ result .append (x )
26+ return x
27+
28+ basecnt = sys .getrefcount (hook )
29+
30+ up = Unpacker (object_pairs_hook = hook , list_hook = hook )
31+
32+ assert sys .getrefcount (hook ) >= basecnt + 2
33+
34+ up .feed (packb ([{}]))
35+ up .feed (packb ([{}]))
36+ assert up .unpack () == [{}]
37+ assert up .unpack () == [{}]
38+ assert result == [[{}], [{}]]
39+
40+ del up
41+
42+ assert sys .getrefcount (hook ) == basecnt
43+
44+
1845if __name__ == '__main__' :
1946 test_unpack_array_header_from_file ()
47+ test_unpacker_hook_refcnt ()
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments