Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_code.CodeWeakRefTest Class Reference

List of all members.

Public Member Functions

def test_basic

Public Attributes

 called

Detailed Description

Definition at line 136 of file test_code.py.


Member Function Documentation

Definition at line 138 of file test_code.py.

00138 
00139     def test_basic(self):
00140         # Create a code object in a clean environment so that we know we have
00141         # the only reference to it left.
00142         namespace = {}
00143         exec("def f(): pass", globals(), namespace)
00144         f = namespace["f"]
00145         del namespace
00146 
00147         self.called = False
00148         def callback(code):
00149             self.called = True
00150 
00151         # f is now the last reference to the function, and through it, the code
00152         # object.  While we hold it, check that we can create a weakref and
00153         # deref it.  Then delete it, and check that the callback gets called and
00154         # the reference dies.
00155         coderef = weakref.ref(f.__code__, callback)
00156         self.assertTrue(bool(coderef()))
00157         del f
00158         self.assertFalse(bool(coderef()))
00159         self.assertTrue(self.called)
00160 


Member Data Documentation

Definition at line 146 of file test_code.py.


The documentation for this class was generated from the following file: