-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_di.py
44 lines (29 loc) · 808 Bytes
/
test_di.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
#!/usr/bin/vn python
"""
some really simple test code
mostly to assure you that it compiled
"""
from di import di, ref_by_id
def test_di_1():
obj = {'a': 'b', 1: 2}
obj_id = id(obj)
assert di(obj_id) == obj
def test_ref_by_id_1():
obj = ['a', 'list', 'of', 'stuff']
obj_id = id(obj)
assert ref_by_id(obj_id) == 1
def test_ref_by_id_2():
""" does a few more counts """
obj = ['a', 'list', 'of', 'stuff']
obj_id = id(obj)
assert ref_by_id(obj_id) == 1
a = b = c = obj
assert ref_by_id(obj_id) == 4
del obj
assert ref_by_id(obj_id) == 3
del b,c
assert ref_by_id(obj_id) == 1
del a
assert ref_by_id(obj_id) == 0 # note: dangerous!
## if that memory location gets re-used, this will break!
## and could segfault hard.