A feature-rich command-line audio/video downloader
[test:download] Validate and sort info dict fields (#12299)
Mozi208163447408
diff --git a/test/helper.py b/test/helper.pyindex c776e70b73..1930190196 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 fieldsif 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):