aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2014-01-20 11:36:47 +0100
committerPhilipp Hagemeister <phihag@phihag.de>2014-01-20 11:36:47 +0100
commitb7ab05908440915c6c5faa541abe00c62a88bc27 (patch)
tree3b7e87361b7dce60ff7bdbe13bd33844fcb7d18e /test
parentc91778f8c0ba120378cb806f694fdc3f94a5634c (diff)
Add infrastructure for paged lists
This commit allows to download pages in playlists as needed instead of all at once. Before this commit, youtube-dl http://www.youtube.com/user/ANNnewsCH/videos --playlist-end 2 --skip-download took quite some time - now it's almost instantaneous. As an example, the youtube:user extractor has been converted. Fixes #2175
Diffstat (limited to 'test')
-rw-r--r--test/test_utils.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/test_utils.py b/test/test_utils.py
index bee355ee0..349c1107f 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -18,6 +18,7 @@ from youtube_dl.utils import (
find_xpath_attr,
get_meta_content,
orderedSet,
+ PagedList,
parse_duration,
sanitize_filename,
shell_quote,
@@ -200,5 +201,26 @@ class TestUtil(unittest.TestCase):
self.assertEqual(parse_duration('9:12:43'), 33163)
self.assertEqual(parse_duration('x:y'), None)
+ def test_paged_list(self):
+ def testPL(size, pagesize, sliceargs, expected):
+ def get_page(pagenum):
+ firstid = pagenum * pagesize
+ upto = min(size, pagenum * pagesize + pagesize)
+ for i in range(firstid, upto):
+ yield i
+
+ pl = PagedList(get_page, pagesize)
+ got = pl.getslice(*sliceargs)
+ self.assertEqual(got, expected)
+
+ testPL(5, 2, (), [0, 1, 2, 3, 4])
+ testPL(5, 2, (1,), [1, 2, 3, 4])
+ testPL(5, 2, (2,), [2, 3, 4])
+ testPL(5, 2, (4,), [4])
+ testPL(5, 2, (0, 3), [0, 1, 2])
+ testPL(5, 2, (1, 4), [1, 2, 3])
+ testPL(5, 2, (2, 99), [2, 3, 4])
+ testPL(5, 2, (20, 99), [])
+
if __name__ == '__main__':
unittest.main()