Files
libretro/tests/test_find_pinned_revision.py
T
Abdessamad Derraz 5f18caec31 refactor: put scripts/ on the test path once
tests/__init__ now puts the repository root and scripts/ on sys.path,
so no test module inserts them and every import sits in the import
block. ruff accepts the bare `import tests` the modules keep for its
side effects. The last suppressions go: helper test modules import as
tests.<name>, files open in with blocks, lambdas become functions.
2026-11-17 16:11:23 +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
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()