diff --git a/tests/test_dlist.py b/tests/test_dlist.py index 0d5eec8..884b69a 100644 --- a/tests/test_dlist.py +++ b/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): diff --git a/youtube_dl_gui/downloadmanager.py b/youtube_dl_gui/downloadmanager.py index e24ca99..857dfaf 100644 --- a/youtube_dl_gui/downloadmanager.py +++ b/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. """