forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_tracing_region.py
More file actions
76 lines (60 loc) · 1.69 KB
/
Copy pathtest_tracing_region.py
File metadata and controls
76 lines (60 loc) · 1.69 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import sys
import unittest
from immutable import freeze, is_frozen, freezable
from immutable import TracingRegion as Region
class TestTraceRefs(unittest.TestCase):
def test_trace(self):
@freezable
class A:
pass
r = Region()
r.a = A()
r.b = A()
r.c = A()
_, base_refs = r.trace()
a = r.a
_, ref_count = r.trace()
self.assertEqual(ref_count, base_refs + 1)
b = r.b
c = r.c
_, ref_count = r.trace()
self.assertEqual(ref_count, base_refs + 3)
class TestImplicitFreeze(unittest.TestCase):
def test_implicit_freeze_func(self):
@freezable
def some_func():
pass
r = Region()
r.obj = some_func
self.assertFalse(is_frozen(r.obj))
r.trace()
self.assertTrue(is_frozen(r.obj))
def test_implicit_freeze_type(self):
@freezable
class A:
pass
r = Region()
r.obj = A
self.assertFalse(is_frozen(r.obj))
r.trace()
self.assertTrue(is_frozen(r.obj))
def test_implicit_freeze_module(self):
import random;
r = Region()
r.obj = random
self.assertFalse(is_frozen(r.obj))
r.trace()
self.assertTrue(is_frozen(r.obj))
# Unimport module
sys.modules.pop("random", None)
sys.mut_modules.pop("random", None)
def test_implicit_freeze_str(self):
r = Region()
r.obj = "Ducks are cool"
r.trace()
self.assertTrue(is_frozen(r.obj))
def test_implicit_freeze_int(self):
r = Region()
r.obj = 17
r.trace()
self.assertTrue(is_frozen(r.obj))