aboutsummaryrefslogtreecommitdiff
path: root/test/helper.py
diff options
context:
space:
mode:
authorMozi <29089388+pzhlkj6612@users.noreply.github.com>2025-02-10 23:22:21 +0000
committerGitHub <noreply@github.com>2025-02-10 23:22:21 +0000
commit208163447408c78673b08c172beafe5c310fb167 (patch)
tree9c3eb75cf3a0356a5972a0abe41e82654f3ac1e7 /test/helper.py
parentc987be0acb6872c6561f28aa28171e803393d851 (diff)
[test:download] Validate and sort info dict fields (#12299)
Authored by: pzhlkj6612, bashonly Co-authored-by: bashonly <88596187+bashonly@users.noreply.github.com>
Diffstat (limited to 'test/helper.py')
-rw-r--r--test/helper.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/test/helper.py b/test/helper.py
index c776e70b7..193019019 100644
--- a/test/helper.py
+++ b/test/helper.py
@@ -237,6 +237,20 @@ def sanitize_got_info_dict(got_dict):
def expect_info_dict(self, got_dict, expected_dict):
+ ALLOWED_KEYS_SORT_ORDER = (
+ # NB: Keep in sync with the docstring of extractor/common.py
+ 'id', 'ext', 'direct', 'display_id', 'title', 'alt_title', 'description', 'media_type',
+ 'uploader', 'uploader_id', 'uploader_url', 'channel', 'channel_id', 'channel_url', 'channel_is_verified',
+ 'channel_follower_count', 'comment_count', 'view_count', 'concurrent_view_count',
+ 'like_count', 'dislike_count', 'repost_count', 'average_rating', 'age_limit', 'duration', 'thumbnail', 'heatmap',
+ 'chapters', 'chapter', 'chapter_number', 'chapter_id', 'start_time', 'end_time', 'section_start', 'section_end',
+ 'categories', 'tags', 'cast', 'composers', 'artists', 'album_artists', 'creators', 'genres',
+ 'track', 'track_number', 'track_id', 'album', 'album_type', 'disc_number',
+ 'series', 'series_id', 'season', 'season_number', 'season_id', 'episode', 'episode_number', 'episode_id',
+ 'timestamp', 'upload_date', 'release_timestamp', 'release_date', 'release_year', 'modified_timestamp', 'modified_date',
+ 'playable_in_embed', 'availability', 'live_status', 'location', 'license', '_old_archive_ids',
+ )
+
expect_dict(self, got_dict, expected_dict)
# Check for the presence of mandatory fields
if got_dict.get('_type') not in ('playlist', 'multi_video'):
@@ -252,7 +266,13 @@ def expect_info_dict(self, got_dict, expected_dict):
test_info_dict = sanitize_got_info_dict(got_dict)
- missing_keys = set(test_info_dict.keys()) - set(expected_dict.keys())
+ # Check for invalid/misspelled field names being returned by the extractor
+ invalid_keys = sorted(test_info_dict.keys() - ALLOWED_KEYS_SORT_ORDER)
+ self.assertFalse(invalid_keys, f'Invalid fields returned by the extractor: {", ".join(invalid_keys)}')
+
+ missing_keys = sorted(
+ test_info_dict.keys() - expected_dict.keys(),
+ key=lambda x: ALLOWED_KEYS_SORT_ORDER.index(x))
if missing_keys:
def _repr(v):
if isinstance(v, str):