1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-12-19 06:28:52 +00:00
This commit is contained in:
c-basalt
2025-03-01 17:00:05 -05:00
parent d0956644d8
commit 5d36f8789b
5 changed files with 33 additions and 20 deletions

View File

@@ -25,13 +25,14 @@ from test.helper import (
import yt_dlp.YoutubeDL # isort: split
from yt_dlp.extractor import get_info_extractor
from yt_dlp.jsinterp.common import filter_jsi_feature, filter_jsi_include
from yt_dlp.jsinterp.common import filter_jsi_keys
from yt_dlp.networking.exceptions import HTTPError, TransportError
from yt_dlp.utils import (
DownloadError,
ExtractorError,
UnavailableVideoError,
YoutubeDLError,
filter_dict,
format_bytes,
join_nonempty,
)
@@ -83,24 +84,26 @@ class TestDownload(unittest.TestCase):
# Dynamically generate tests
def generator(test_case, tname):
def generate_sub_case(jsi_key):
sub_case = {k: v for k, v in test_case.items() if not k.startswith('jsi_matrix')}
sub_case['params'] = {**test_case.get('params', {}), 'jsi_preference': [jsi_key]}
return generator(sub_case, f'{tname}_{jsi_key}')
# setting `jsi_matrix` to True, `jsi_matrix_features` to list, or
# setting `jsi_matrix_only_include` or `jsi_matrix_exclude` to non-empty
# to trigger matrix behavior
# setting `jsi_matrix_only_include` or `jsi_matrix_exclude` to non-empty list
# to trigger matrix behavior for JSI
if isinstance(test_case.get('jsi_matrix_features'), list) or any(test_case.get(key) for key in [
'jsi_matrix', 'jsi_matrix_only_include', 'jsi_matrix_exclude',
]):
jsi_keys = filter_jsi_feature(test_case.get('jsi_matrix_features', []), filter_jsi_include(
test_case.get('jsi_matrix_only_include', None), test_case.get('jsi_matrix_exclude', None)))
jsi_keys = filter_jsi_keys(
test_case.get('jsi_matrix_features'), test_case.get('jsi_matrix_only_include'),
test_case.get('jsi_matrix_exclude'))
def generate_jsi_sub_case(jsi_key):
sub_case = filter_dict(test_case, lambda k, _: not k.startswith('jsi_matrix'))
sub_case['params'] = {**test_case.get('params', {}), 'jsi_preference': [jsi_key]}
return generator(sub_case, f'{tname}_{jsi_key}')
def run_sub_cases(self):
for i, jsi_key in enumerate(jsi_keys):
print(f'Running case {tname} using JSI: {jsi_key} ({i + 1}/{len(jsi_keys)})')
generate_sub_case(jsi_key)(self)
generate_jsi_sub_case(jsi_key)(self)
return run_sub_cases
def test_template(self):