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 1
1
from io import BytesIO
2
+ import sys
2
3
from msgpack import Unpacker , packb , OutOfData
3
- from pytest import raises
4
+ from pytest import raises , mark
4
5
5
6
6
7
def test_unpack_array_header_from_file ():
@@ -15,5 +16,32 @@ def test_unpack_array_header_from_file():
15
16
unpacker .unpack ()
16
17
17
18
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
+
18
45
if __name__ == '__main__' :
19
46
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