0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-16 01:25:06 +00:00

[tests:download] Add batch testing for extractors

Use `test_YourExtractor_all` to invoke them
This commit is contained in:
pukkandan 2021-08-06 09:59:41 +05:30
parent 28f436bad0
commit 243c57cfe8

View file

@ -73,6 +73,8 @@ class TestDownload(unittest.TestCase):
maxDiff = None maxDiff = None
COMPLETED_TESTS = {}
def __str__(self): def __str__(self):
"""Identify each test with the `add_ie` attribute, if available.""" """Identify each test with the `add_ie` attribute, if available."""
@ -94,6 +96,9 @@ def setUp(self):
def generator(test_case, tname): def generator(test_case, tname):
def test_template(self): 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'])() 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', [])] 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) is_playlist = any(k.startswith('playlist') for k in test_case)
@ -255,12 +260,12 @@ def try_rm_tcs_files(tcs=None):
# And add them to TestDownload # And add them to TestDownload
for n, test_case in enumerate(defs): tests_counter = {}
tname = 'test_' + str(test_case['name']) for test_case in defs:
i = 1 name = test_case['name']
while hasattr(TestDownload, tname): i = tests_counter.get(name, 0)
tname = 'test_%s_%d' % (test_case['name'], i) tests_counter[name] = i + 1
i += 1 tname = f'test_{name}_{i}' if i else f'test_{name}'
test_method = generator(test_case, tname) test_method = generator(test_case, tname)
test_method.__name__ = str(tname) test_method.__name__ = str(tname)
ie_list = test_case.get('add_ie') ie_list = test_case.get('add_ie')
@ -269,5 +274,22 @@ def try_rm_tcs_files(tcs=None):
del test_method 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__': if __name__ == '__main__':
unittest.main() unittest.main()