Files
libretro/tests/test_find_pinned_revision.py
T
Abdessamad Derraz e1f2f8685d refactor: move upstream, sourceref, version_basis
upstream reads forges with the standard library alone and scrapers,
packs and the site read it: it goes to core. sourceref is the grammar
of a profile field, which the site parses without the comparison
tool: it goes to model. version_basis is read by profile_sync alone
and opens the profiling package.
2026-11-18 12:39:09 +01:00

42 lines
1.4 KiB
Python

"""A platform's pinned revision found in its upstream history.
RetroArch pins ScummVM's queen.tbl and FBNeo's hiscore.dat at revisions
today's upstream no longer carries, but the bytes are in the project's history.
"""
from __future__ import annotations
import tests
import hashlib
import unittest
from unittest import mock
import find_pinned_revision
from core import upstream
class ThePinnedRevisionIsInTheHistory(unittest.TestCase):
def test_the_newest_matching_revision_is_returned(self):
repo = upstream.parse_repo("https://github.com/scummvm/scummvm")
blobs = {"c3": b"today", "c2": b"pinned", "c1": b"older"}
def api(url, *_a, **_k):
return [{"sha": s} for s in blobs] if "page=1" in url else []
def fetch(url, *_a, **_k):
return next(data for sha, data in blobs.items() if f"/{sha}/" in url)
with mock.patch.object(upstream, "_api", api), mock.patch.object(upstream, "_fetch", fetch):
found = find_pinned_revision.find_revision(
repo, "dists/engine-data/queen.tbl",
hashlib.md5(b"pinned").hexdigest(), "unused")
missing = find_pinned_revision.find_revision(
repo, "dists/engine-data/queen.tbl", "0" * 32, "unused")
self.assertEqual(found, ("c2", b"pinned"))
self.assertIsNone(missing)
if __name__ == "__main__":
unittest.main()