mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-06-28 09:28:33 +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:
parent
a5c8eb4c17
commit
92b44663b3
@ -1,13 +1,14 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
# Allow direct execution
|
# Allow direct execution
|
||||||
import io
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
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 test.helper import FakeYDL, report_warning
|
||||||
from yt_dlp.update import UpdateInfo, Updater
|
from yt_dlp.update import UpdateInfo, Updater
|
||||||
@ -76,6 +77,12 @@
|
|||||||
'name': 'pr987',
|
'name': 'pr987',
|
||||||
'body': 'Generated from: https://github.com/yt-dlp/yt-dlp/commit/2222222222222222222222222222222222222222',
|
'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'
|
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):
|
def test_query_update(self):
|
||||||
ydl = FakeYDL()
|
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):
|
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)
|
update_info = updater.query_update(_output=True)
|
||||||
self.assertDictEqual(update_info.__dict__ if update_info else {}, expected.__dict__ if expected else {})
|
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())
|
|
||||||
|
|
||||||
test('yt-dlp/yt-dlp@latest', UpdateInfo(
|
test('yt-dlp/yt-dlp@latest', UpdateInfo(
|
||||||
'2023.12.31', version='2023.12.31', requested_version='2023.12.31', commit='b' * 40))
|
'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', None, current_commit='9' * 40)
|
||||||
test('testing', UpdateInfo('testing', commit='9' * 40))
|
test('testing', UpdateInfo('testing', commit='9' * 40))
|
||||||
|
|
||||||
test_version_info_error(
|
stderr = io.StringIO()
|
||||||
api_response={
|
with contextlib.redirect_stderr(stderr):
|
||||||
'tag_name': 'v2024.02.01',
|
test('fork/yt-dlp@broken', UpdateInfo('broken'))
|
||||||
'name': 'Release candidate',
|
self.assertIn('One of either version or commit hash must be available on the release', stderr.getvalue())
|
||||||
'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',
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user