Skip to content

Commit

Permalink
Add a TestSuite named 'test_%(ie_key)s_all' for each extractor
Browse files Browse the repository at this point in the history
So TestDownload.test_XXX_all runs all the download test cases for
the XXX extractor.
  • Loading branch information
dirkf committed Sep 11, 2021
1 parent 0c8f7a5 commit aeb9db4
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions test/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io
import json
import socket
import re

import youtube_dl.YoutubeDL
from youtube_dl.compat import (
Expand Down Expand Up @@ -86,6 +87,13 @@ def strclass(cls):
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

Expand Down Expand Up @@ -268,12 +276,45 @@ def try_rm_tcs_files(tcs=None):
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)
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_.+(?<!(?:_all|.._\d|._\d\d|_\d\d\d))$', t),
dir(TestDownload)))))):
test_all = gen_test_suite(ie_key)
TestDownload.addTest(test_all, 'test_%s_all' % ie_key, 'Test all: %s' % ie_key)

if __name__ == '__main__':
unittest.main()

0 comments on commit aeb9db4

Please sign in to comment.