1
0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-12-23 00:16:48 +00:00
This commit is contained in:
Odd Stråbø 2024-08-09 14:38:25 +02:00 committed by GitHub
commit 65f35e0d64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 12 deletions

View File

@ -69,10 +69,10 @@ def _file_md5(fn):
return hashlib.md5(f.read()).hexdigest() return hashlib.md5(f.read()).hexdigest()
defs = gettestcases() ie_testcases = gettestcases()
class TestDownload(unittest.TestCase): class BaseDownloadTCase(unittest.TestCase):
# Parallel testing in nosetests. See # Parallel testing in nosetests. See
# http://nose.readthedocs.org/en/latest/doc_tests/test_multiprocess/multiprocess.html # http://nose.readthedocs.org/en/latest/doc_tests/test_multiprocess/multiprocess.html
_multiprocess_shared_ = True _multiprocess_shared_ = True
@ -91,8 +91,9 @@ class TestDownload(unittest.TestCase):
strclass(self.__class__), strclass(self.__class__),
' [%s]' % add_ie if add_ie else '') ' [%s]' % add_ie if add_ie else '')
def setUp(self):
self.defs = defs TestDownload = unittest.TestSuite()
# Dynamically generate tests # Dynamically generate tests
@ -275,20 +276,42 @@ def generator(test_case, tname):
return test_template return test_template
cache = {}
# And add them to TestDownload # And add them to TestDownload
for n, test_case in enumerate(defs): for test_case in ie_testcases:
tname = 'test_' + str(test_case['name']) # Get or create a sub-test for the extractor file
i = 1 module_name = test_case.get('module_name', 'unknown').rsplit('.', 1)[-1] # type: str
while hasattr(TestDownload, tname): extractor_file_name = str('test_%s' % module_name)
tname = 'test_%s_%d' % (test_case['name'], i) extractor_file_suite = getattr(TestDownload, extractor_file_name, None)
if extractor_file_suite is None:
extractor_file_suite = type(extractor_file_name, (unittest.TestSuite,), {})()
setattr(TestDownload, extractor_file_name, extractor_file_suite)
TestDownload.addTest(extractor_file_suite)
# Get or create a sub-test for the info extractor
# This class contains the actual tests
extractor_class_name = str('test_%s' % test_case['name'])
ExtractorClass = getattr(extractor_file_suite, extractor_class_name, None)
if ExtractorClass is None:
ExtractorClass = type(extractor_class_name, (BaseDownloadTCase,), {})
setattr(extractor_file_suite, extractor_class_name, ExtractorClass)
i = 0
tname = 'test_%d' % i
while hasattr(ExtractorClass, tname):
tname = 'test_%d' % i
i += 1 i += 1
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')
test_method.add_ie = ie_list and ','.join(ie_list) test_method.add_ie = ie_list and ','.join(ie_list)
setattr(TestDownload, test_method.__name__, test_method)
del test_method setattr(ExtractorClass, test_method.__name__, test_method)
extractor_file_suite.addTest(ExtractorClass(test_method.__name__))
del test_method, test_case
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main(argv=['TestDownload'])

View File

@ -3263,6 +3263,7 @@ class InfoExtractor(object):
if not include_onlymatching and t.get('only_matching', False): if not include_onlymatching and t.get('only_matching', False):
continue continue
t['name'] = type(self).__name__[:-len('IE')] t['name'] = type(self).__name__[:-len('IE')]
t['module_name'] = type(self).__module__
yield t yield t
def is_suitable(self, age_limit): def is_suitable(self, age_limit):