-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathtest_c_ctxmgr.py
56 lines (44 loc) · 1.86 KB
/
test_c_ctxmgr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import sys
import psutil
import pytest
from cPyExtPatt import cCtxMgr
def test_module_dir():
assert dir(cCtxMgr) == ['BUFFER_LENGTH', 'ContextManager', '__doc__', '__file__', '__loader__', '__name__',
'__package__', '__spec__']
def test_module_BUFFER_LENGTH():
assert cCtxMgr.BUFFER_LENGTH == 128 * 1024**2
def test_very_simple():
print()
with cCtxMgr.ContextManager():
pass
def test_simple():
print()
with cCtxMgr.ContextManager() as context:
assert sys.getrefcount(context) == 3
assert context.len_buffer_lifetime() == cCtxMgr.BUFFER_LENGTH
assert context.len_buffer_context() == cCtxMgr.BUFFER_LENGTH
assert sys.getrefcount(context) == 2
assert context.len_buffer_lifetime() == cCtxMgr.BUFFER_LENGTH
assert context.len_buffer_context() == 0
del context
def test_memory():
proc = psutil.Process()
print()
print(f'RSS START: {proc.memory_info().rss:12,d}')
for i in range(8):
print(f'RSS START {i:5d}: {proc.memory_info().rss:12,d}')
with cCtxMgr.ContextManager() as context:
print(f'RSS START CTX: {proc.memory_info().rss:12,d}')
# Does not work in the debugger due to introspection.
# assert sys.getrefcount(context) == 3
assert context.len_buffer_lifetime() == cCtxMgr.BUFFER_LENGTH
assert context.len_buffer_context() == cCtxMgr.BUFFER_LENGTH
print(f'RSS END CTX: {proc.memory_info().rss:12,d}')
# Does not work in the debugger due to introspection.
# assert sys.getrefcount(context) == 2
assert context.len_buffer_lifetime() == cCtxMgr.BUFFER_LENGTH
assert context.len_buffer_context() == 0
del context
print(f'RSS END {i:5d}: {proc.memory_info().rss:12,d}')
print(f'RSS END: {proc.memory_info().rss:12,d}')
# assert 0