aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2014-01-22 20:00:16 +0100
committerPhilipp Hagemeister <phihag@phihag.de>2014-01-22 20:00:16 +0100
commit65697b3bf3bf6eaeb91a34e5308a6d2239118071 (patch)
treee174cfbd658bd57da9d0fa990dc10949065db42b /test
parent50317b111dadccba73bcdd828d9997d1da78a5f1 (diff)
parentb7ab05908440915c6c5faa541abe00c62a88bc27 (diff)
Merge branch 'paged-lists'
Conflicts: test/test_utils.py youtube_dl/extractor/youtube.py
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 a17483ada..c68e0e968 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -19,6 +19,7 @@ from youtube_dl.utils import (
fix_xml_ampersands,
get_meta_content,
orderedSet,
+ PagedList,
parse_duration,
sanitize_filename,
shell_quote,
@@ -214,5 +215,26 @@ class TestUtil(unittest.TestCase):
fix_xml_ampersands('&#1234;&#x1abC;'), '&#1234;&#x1abC;')
self.assertEqual(fix_xml_ampersands('&#&#'), '&amp;#&amp;#')
+ 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()