From 5ab2dbeced73252395396ae0cb9b5ced1649074c Mon Sep 17 00:00:00 2001 From: df Date: Sat, 11 Sep 2021 12:13:09 +0100 Subject: [PATCH] Add a TestSuite named 'test_%(ie_key)s_all' for each extractor So TestDownload.test_XXX_all runs all the download test cases for the XXX extractor. --- test/test_download.py | 55 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/test/test_download.py b/test/test_download.py index c4e6c8697..468901ca4 100644 --- a/test/test_download.py +++ b/test/test_download.py @@ -23,6 +23,7 @@ import hashlib import io import json import socket +import re import youtube_dl.YoutubeDL from youtube_dl.compat import ( @@ -86,6 +87,13 @@ class TestDownload(unittest.TestCase): strclass(self.__class__), ' [%s]' % add_ie if add_ie else '') + @classmethod + def addTest(cls, test_method, test_method_name, add_ie): + test_method.__name__ = str(test_method_name) + test_method.add_ie = add_ie + setattr(TestDownload, test_method.__name__, test_method) + del test_method + def setUp(self): self.defs = defs @@ -268,12 +276,49 @@ for n, test_case in enumerate(defs): tname = 'test_%s_%d' % (test_case['name'], i) i += 1 test_method = generator(test_case, tname) - test_method.__name__ = str(tname) - ie_list = test_case.get('add_ie') - test_method.add_ie = ie_list and ','.join(ie_list) - setattr(TestDownload, test_method.__name__, test_method) - del test_method + ie_list = ','.join(test_case.get('add_ie', [])) + TestDownload.addTest(test_method, tname, ie_list) +# Py2 compat (should be in compat.py?) +try: + from itertools import (ifilter as filter, imap as map) +except ImportError: + pass + + +def tests_for_ie(ie_key): + return filter( + lambda a: callable(getattr(TestDownload, a, None)), + filter(lambda a: re.match(r'test_%s(?:_\d+)?$' % ie_key, a), + dir(TestDownload))) + + +def gen_test_suite(ie_key): + def test_all(self): + print(self) + suite = unittest.TestSuite( + map(TestDownload, tests_for_ie(ie_key))) + result = self.defaultTestResult() + suite.run(result) + print('Errors: %d\t Failures: %d\tSkipped: %d' % + tuple(map(len, (result.errors, result.failures, result.skipped)))) + print('Expected failures: %d\tUnexpected successes: %d' % + tuple(map(len, (result.expectedFailures, result.unexpectedSuccesses)))) + return result + + return test_all + + +for ie_key in set( + map(lambda x: x[0], + filter( + lambda x: callable(x[1]), + map(lambda a: (a[5:], getattr(TestDownload, a, None)), + filter(lambda t: + re.match(r'test_.+(?