mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-14 07:23:23 -05:00
fix: keep cross-named aliases inside their profile
This commit is contained in:
1 parent
619c282477
commit
fe877ff79c
4 files changed
+90
-9
No files matched your search
@@ -111,5 +111,29 @@ class AcceptedRevisionLists(unittest.TestCase):
|
||||
for sha in ("s1", "s2"):
|
||||
self.assertEqual([a["name"] for a in aliases.get(sha, [])], ["MT32_CONTROL.ROM"])
|
||||
|
||||
class CrossNamingStaysInItsProfile(unittest.TestCase):
|
||||
def test_an_alias_naming_a_sibling_entry_is_not_indexed(self):
|
||||
"""dosbox-x aliases MT32_CONTROL.ROM and CM32L_CONTROL.ROM to each other."""
|
||||
import generate_db
|
||||
|
||||
with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp:
|
||||
previous = os.getcwd()
|
||||
os.chdir(tmp)
|
||||
try:
|
||||
Path("emulators").mkdir()
|
||||
Path("emulators/d.yml").write_text(
|
||||
'files:\n'
|
||||
' - name: "MT32_CONTROL.ROM"\n sha1: "mt"\n aliases: ["CM32L_CONTROL.ROM"]\n'
|
||||
' - name: "CM32L_CONTROL.ROM"\n sha1: "cm"\n aliases: ["MT32_CONTROL.ROM"]\n'
|
||||
)
|
||||
aliases = generate_db._collect_all_aliases({
|
||||
"mt": {"name": "mt32_control.rom", "path": "a", "md5": "m1"},
|
||||
"cm": {"name": "cm32l_control.rom", "path": "b", "md5": "m2"},
|
||||
})
|
||||
finally:
|
||||
os.chdir(previous)
|
||||
self.assertEqual([a["name"] for a in aliases["mt"]], ["MT32_CONTROL.ROM"])
|
||||
self.assertEqual([a["name"] for a in aliases["cm"]], ["CM32L_CONTROL.ROM"])
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,36 @@
|
||||
"""Same-named candidates are ordered by the size the entry declares.
|
||||
|
||||
ScummVM declares MT32_PCM.ROM at 524288 bytes; the name step took the 1 MB
|
||||
CM-32L PCM ROM that sorted first. Ordering rejects nothing, so a size
|
||||
without `validation: [size]` keeps its informative status.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(REPO_ROOT / "scripts"))
|
||||
|
||||
from common import _by_affinity # noqa: E402
|
||||
|
||||
|
||||
class DeclaredSizeOrders(unittest.TestCase):
|
||||
def test_the_fitting_size_comes_first(self):
|
||||
with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp:
|
||||
big = Path(tmp) / "a" / "pcm.rom"
|
||||
small = Path(tmp) / "b" / "pcm.rom"
|
||||
for path, size in ((big, 1024), (small, 512)):
|
||||
path.parent.mkdir()
|
||||
path.write_bytes(b"x" * size)
|
||||
ordered = _by_affinity([str(big), str(small)], {"size": 512}, "")
|
||||
self.assertEqual(ordered[0], str(small))
|
||||
kept = _by_affinity([str(big), str(small)], {}, "")
|
||||
self.assertEqual(kept, [str(big), str(small)])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user