1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-06-27 17:08:32 +00:00

[fix:update] adding test changes to simplify the implementation

Co-authored-by: grqx <173253225+grqx@users.noreply.github.com>
This commit is contained in:
moonshinerd 2025-06-09 16:18:42 -03:00
parent a5c8eb4c17
commit 92b44663b3

View File

@ -1,13 +1,14 @@
#!/usr/bin/env python3
# Allow direct execution
import io
import os
import sys
import unittest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import contextlib
import io
from test.helper import FakeYDL, report_warning
from yt_dlp.update import UpdateInfo, Updater
@ -76,6 +77,12 @@
'name': 'pr987',
'body': 'Generated from: https://github.com/yt-dlp/yt-dlp/commit/2222222222222222222222222222222222222222',
},
'fork/yt-dlp/tags/broken': {
'tag_name': 'broken',
'target_commitish': '',
'name': 'broken',
'body': 'Irrelevant text',
},
}
TEST_LOCKFILE_COMMENT = '# This file is used for regulating self-update'
@ -237,32 +244,16 @@ def test(lockfile, identifier, input_tag, expect_tag, exact=False, repo='yt-dlp/
def test_query_update(self):
ydl = FakeYDL()
def make_updater(target, *, current_version=None,
current_commit=None, identifier=None,
api_response=None):
upd = FakeUpdater(ydl, target)
if current_version:
upd.current_version = current_version
if current_commit:
upd.current_commit = current_commit
upd._identifier = identifier or 'zip'
if api_response is not None:
upd._call_api = lambda _: api_response
return upd
def test(target, expected, current_version=None, current_commit=None, identifier=None):
updater = make_updater(target, current_version=current_version, current_commit=current_commit, identifier=identifier)
updater = FakeUpdater(ydl, target)
if current_version:
updater.current_version = current_version
if current_commit:
updater.current_commit = current_commit
updater._identifier = identifier or 'zip'
update_info = updater.query_update(_output=True)
self.assertDictEqual(update_info.__dict__ if update_info else {}, expected.__dict__ if expected else {})
def test_version_info_error(api_response, expected_msg):
updater = make_updater('stable', api_response=api_response)
stderr = io.StringIO()
with redirect_stderr(stderr):
version, commit = updater._get_version_info('')
self.assertIsNone(version)
self.assertIsNone(commit)
self.assertIn(expected_msg, stderr.getvalue())
self.assertDictEqual(
update_info.__dict__ if update_info else {}, expected.__dict__ if expected else {})
test('yt-dlp/yt-dlp@latest', UpdateInfo(
'2023.12.31', version='2023.12.31', requested_version='2023.12.31', commit='b' * 40))
@ -290,17 +281,10 @@ def test_version_info_error(api_response, expected_msg):
test('testing', None, current_commit='9' * 40)
test('testing', UpdateInfo('testing', commit='9' * 40))
test_version_info_error(
api_response={
'tag_name': 'v2024.02.01',
'name': 'Release candidate',
'target_commitish': '',
'body': '- Implements extra parameter validation\n'
'- Optimizes performance in date parser\n',
},
expected_msg='One of either version or commit hash must be available on the release',
)
stderr = io.StringIO()
with contextlib.redirect_stderr(stderr):
test('fork/yt-dlp@broken', UpdateInfo('broken'))
self.assertIn('One of either version or commit hash must be available on the release', stderr.getvalue())
if __name__ == '__main__':
unittest.main()