Browse Source

Add clear() method on DownloadList

doc-issue-template
MrS0m30n3 8 years ago
parent
commit
8711d1cf37
2 changed files with 18 additions and 0 deletions
  1. 12
      tests/test_dlist.py
  2. 6
      youtube_dl_gui/downloadmanager.py

12
tests/test_dlist.py

@ -208,6 +208,18 @@ class TestGetItems(unittest.TestCase):
self.assertEqual(dlist.get_items(), [])
class TestClear(unittest.TestCase):
"""Test case for the DownloadList clear method."""
def test_clear(self):
dlist = DownloadList([mock.Mock() for _ in range(3)])
self.assertEqual(len(dlist), 3)
dlist.clear()
self.assertEqual(len(dlist), 0)
class TestSynchronizeDecorator(unittest.TestCase):
def test_synchronize(self):

6
youtube_dl_gui/downloadmanager.py

@ -182,6 +182,12 @@ class DownloadList(object):
self._items_list = [item.object_id for item in items]
self._items_dict = {item.object_id: item for item in items}
@synchronized(_SYNC_LOCK)
def clear(self):
"""Removes all the items from the list even the 'Active' ones."""
self._items_list = []
self._items_dict = {}
@synchronized(_SYNC_LOCK)
def insert(self, item):
"""Inserts the given item to the list. Does not check for duplicates. """

Loading…
Cancel
Save