def test_garbage_collection_3(self): test = NotifyTestObject() variable = Variable() condition1 = variable.is_true() condition2 = ~condition1 condition2.store(test.simple_handler) condition1 = weakref.ref(condition1) condition2 = weakref.ref(condition2) self.collect_garbage() self.assertNotEqual(condition1(), None) self.assertNotEqual(condition2(), None) self.collect_garbage() variable.value = 10 condition2().changed.disconnect(test.simple_handler) self.collect_garbage() self.assertEqual(condition1(), None) self.assertEqual(condition2(), None) variable = weakref.ref(variable) self.collect_garbage() self.assertEqual(variable(), None) test.assert_results(True, False)
def test_garbage_collection_3 (self): test = NotifyTestObject () variable = Variable () condition1 = variable.is_true () condition2 = ~condition1 condition2.store (test.simple_handler) condition1 = weakref.ref (condition1) condition2 = weakref.ref (condition2) self.collect_garbage () self.assertNotEqual (condition1 (), None) self.assertNotEqual (condition2 (), None) self.collect_garbage () variable.value = 10 condition2 ().changed.disconnect (test.simple_handler) self.collect_garbage () self.assertEqual (condition1 (), None) self.assertEqual (condition2 (), None) variable = weakref.ref (variable) self.collect_garbage () self.assertEqual (variable (), None) test.assert_results (True, False)
def test_is_true (self): variable = Variable (0) is_true = variable.is_true () self.assert_(not is_true) variable.value = 'string' self.assert_(is_true) variable.value = [] self.assert_(not is_true) variable.value = None self.assert_(not is_true) variable.value = 25 self.assert_(is_true)
def test_garbage_collection_1(self): test = NotifyTestObject() variable = Variable() condition = variable.is_true() condition.store(test.simple_handler) condition = weakref.ref(condition) # This must not collect the `is_true' condition, even though it is not directly # referenced at all. self.collect_garbage() self.assertNotEqual(condition(), None) self.collect_garbage() variable.value = 10 # This makes condition `unused' and it must become available to garbage collector # again. del variable self.collect_garbage() self.assertEqual(condition(), None) test.assert_results(False, True)
def test_garbage_collection_1 (self): test = NotifyTestObject () variable = Variable () condition = variable.is_true () condition.store (test.simple_handler) condition = weakref.ref (condition) # This must not collect the `is_true' condition, even though it is not directly # referenced at all. self.collect_garbage () self.assertNotEqual (condition (), None) self.collect_garbage () variable.value = 10 # This makes condition `unused' and it must become available to garbage collector # again. del variable self.collect_garbage () self.assertEqual (condition (), None) test.assert_results (False, True)