aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_download.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2021-08-06 09:59:41 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2021-08-07 21:17:06 +0530
commit243c57cfe851431172bbf621ecc408afefbf8900 (patch)
tree6f0ba8d60185cb8bd8b1b5929678e17c8129258b /test/test_download.py
parent28f436bad0597f1a471ae6d86a131d9cd24847f9 (diff)
downloadhypervideo-pre-243c57cfe851431172bbf621ecc408afefbf8900.tar.lz
hypervideo-pre-243c57cfe851431172bbf621ecc408afefbf8900.tar.xz
hypervideo-pre-243c57cfe851431172bbf621ecc408afefbf8900.zip
[tests:download] Add batch testing for extractors
Use `test_YourExtractor_all` to invoke them
Diffstat (limited to 'test/test_download.py')
-rw-r--r--test/test_download.py34
1 files changed, 28 insertions, 6 deletions
diff --git a/test/test_download.py b/test/test_download.py
index 546748454..f26fb23c0 100644
--- a/test/test_download.py
+++ b/test/test_download.py
@@ -73,6 +73,8 @@ class TestDownload(unittest.TestCase):
maxDiff = None
+ COMPLETED_TESTS = {}
+
def __str__(self):
"""Identify each test with the `add_ie` attribute, if available."""
@@ -94,6 +96,9 @@ class TestDownload(unittest.TestCase):
def generator(test_case, tname):
def test_template(self):
+ if self.COMPLETED_TESTS.get(tname):
+ return
+ self.COMPLETED_TESTS[tname] = True
ie = yt_dlp.extractor.get_info_extractor(test_case['name'])()
other_ies = [get_info_extractor(ie_key)() for ie_key in test_case.get('add_ie', [])]
is_playlist = any(k.startswith('playlist') for k in test_case)
@@ -255,12 +260,12 @@ def generator(test_case, tname):
# And add them to TestDownload
-for n, test_case in enumerate(defs):
- tname = 'test_' + str(test_case['name'])
- i = 1
- while hasattr(TestDownload, tname):
- tname = 'test_%s_%d' % (test_case['name'], i)
- i += 1
+tests_counter = {}
+for test_case in defs:
+ name = test_case['name']
+ i = tests_counter.get(name, 0)
+ tests_counter[name] = i + 1
+ tname = f'test_{name}_{i}' if i else f'test_{name}'
test_method = generator(test_case, tname)
test_method.__name__ = str(tname)
ie_list = test_case.get('add_ie')
@@ -269,5 +274,22 @@ for n, test_case in enumerate(defs):
del test_method
+def batch_generator(name, num_tests):
+
+ def test_template(self):
+ for i in range(num_tests):
+ getattr(self, f'test_{name}_{i}' if i else f'test_{name}')()
+
+ return test_template
+
+
+for name, num_tests in tests_counter.items():
+ test_method = batch_generator(name, num_tests)
+ test_method.__name__ = f'test_{name}_all'
+ test_method.add_ie = ''
+ setattr(TestDownload, test_method.__name__, test_method)
+ del test_method
+
+
if __name__ == '__main__':
unittest.main()