# Path: supplement/utils.py
# class WeakedList(object):
#     def __init__(self):
#         self.list = []
# 
#     def __iter__(self):
#         for r in self.list:
#             yield r()
# 
#     def __len__(self):
#         return len(self.list)
# 
#     def append(self, value):
#         self.list.append(ref(value, self.on_delete))
# 
#     def on_delete(self, ref):
#         self.list.remove(ref)


from supplement.utils import WeakedList

def test_weaked_list():
    class A(object): pass

    wl = WeakedList()

    holder1 = [A(), A()]
    holder2 = [A()]
    holder3 = {'key':A()}

    wl.append(holder1[0])
    wl.append(holder1[1])
    wl.append(holder2[0])
    wl.append(holder3['key'])

    assert [holder1[0], holder1[1], holder2[0], holder3['key']] == list(wl)

    holder1[:] = []
    assert [holder2[0], holder3['key']] == list(wl)


# Path: supplement/utils.py
# class WeakedList(object):
#     def __init__(self):
#         self.list = []
# 
#     def __iter__(self):
#         for r in self.list:
#             yield r()
# 
#     def __len__(self):
#         return len(self.list)
# 
#     def append(self, value):
#         self.list.append(ref(value, self.on_delete))
# 
#     def on_delete(self, ref):
#         self.list.remove(ref)


# Path: tests/test_utils.py
from supplement.utils import WeakedList


def test_weaked_list():
    class A(object): pass

    wl = WeakedList()

    holder1 = [A(), A()]
    holder2 = [A()]
    holder3 = {'key':A()}

    wl.append(holder1[0])
    wl.append(holder1[1])
    wl.append(holder2[0])
    wl.append(holder3['key'])

    assert [holder1[0], holder1[1], holder2[0], holder3['key']] == list(wl)

    holder1[:] = []
    assert [holder2[0], holder3['key']] == list(wl)


    del holder3['key']