def test_walk_gc_with_towards_false(self, mock_gc): mock_gc.get_referents.side_effect = [ # Trigger the continue by duplicating entries. [mock.sentinel.second], [mock.sentinel.second] ] first_obj = mock.sentinel.first handler = mock.MagicMock() handler.return_value = True expected = [[mock.sentinel.first], [mock.sentinel.second, mock.sentinel.first]] actual = [] for obj in helpers.walk_gc(first_obj, False, handler): actual.append(obj) self.assertEqual(expected, actual)
def test_walk_gc_with_towards_true(self, mock_gc, autospec=True): mock_gc.get_referrers.side_effect = [ [mock.sentinel.second], [mock.sentinel.third] ] first_obj = mock.sentinel.first handler = lambda i: True expected = [ [mock.sentinel.first], [mock.sentinel.first, mock.sentinel.second], [mock.sentinel.first, mock.sentinel.second, mock.sentinel.third] ] actual = [] for obj in helpers.walk_gc(first_obj, True, handler): actual.append(obj) self.assertEqual(expected, actual)