def run_test(): mytuple = tuple([1, 2, 3]) rfc = getrefptr(mytuple) self.assertTrue(gc.is_tracked(mytuple)) self.assertEqual(rfc.value, 1) b = mytuple self.assertEqual(rfc.value, 2) del b self.assertEqual(rfc.value, 1) _tuple_set_item(mytuple, 1, mytuple) self.assertEqual(rfc.value, 1) mytuple = None del mytuple return rfc
def test_dirwalk(self): # Optimizing a recursive function to have a reference to itself, # when a global name is not defined but added to the function through make_constants # causes a NameError to occur, because the 'constant' self-reference actually # refers to the old function. from pysrc.test.test_optimize_constants.test_input.fix_dirwalk import dirwalk from os import listdir dirwalk = make_constants(dirwalk=dirwalk, listdir=listdir, OSError=OSError, join='\\'.join)(dirwalk) dirwalk = make_constants(dirwalk=dirwalk)(dirwalk) dirwalk(curdir) rc = getrefptr(dirwalk) self.assertEqual(rc.value, 1) import gc del dirwalk gc.collect() self.assertEqual(rc.value, 0)