fix: stop when a profile does not parse

generate_db wrote a database without the aliases of a profile it could not read, and the MAME and FBNeo refreshes passed without it. Each now names the file and exits non-zero.
This commit is contained in:
Abdessamad Derraz committed 2026-10-18 20:40:23 +02:00
1 parent 9a417dde2a
commit 89ac31780b
5 files changed
+79 -7

No files matched your search

+25
View File
@@ -128,5 +128,30 @@ class CrossNamingStaysInItsProfile(unittest.TestCase):
self.assertEqual([a["name"] for a in aliases["mt"]], ["MT32_CONTROL.ROM"])
self.assertEqual([a["name"] for a in aliases["cm"]], ["CM32L_CONTROL.ROM"])
class AnUnreadableSourceStopsTheRun(unittest.TestCase):
"""A profile with a YAML error was skipped in silence: the database was
written without its aliases and the command exited 0."""
def test_the_file_is_named_and_nothing_collected(self):
import os
import shutil
import tempfile
import generate_db
tmp_root = Path(__file__).resolve().parents[1] / "tmp"
tmp_root.mkdir(exist_ok=True)
root = Path(tempfile.mkdtemp(dir=tmp_root))
self.addCleanup(shutil.rmtree, root, True)
previous = os.getcwd()
os.chdir(root)
self.addCleanup(os.chdir, previous)
Path("emulators").mkdir()
Path("emulators/broken.yml").write_text("files: [\n - name: a\n")
with self.assertRaises(generate_db.UnreadableSource) as caught:
generate_db._collect_all_aliases({})
self.assertIn("broken.yml", str(caught.exception))
if __name__ == "__main__":
unittest.main()
+22
View File
@@ -774,5 +774,27 @@ class OneCloneDirectoryPerRun(unittest.TestCase):
self.assertTrue(clone.name.endswith(f"-{os.getpid()}"))
class ABrokenProfileStopsTheRefresh(unittest.TestCase):
"""A profile with a YAML error left the list in silence: the refresh
printed 'no matching emulator profiles found' and exited 0."""
def test_both_scrapers_name_it(self):
from unittest import mock
from scripts.scraper import fbneo_hash_scraper, mame_hash_scraper
with tempfile.TemporaryDirectory() as directory:
Path(directory, "fbneo.yml").write_text("files: [\n - name: a\n")
for module, attr, finder in (
(fbneo_hash_scraper, "EMULATORS_DIR", "_find_fbneo_profiles"),
(mame_hash_scraper, "_EMULATORS_DIR", "_find_mame_profiles"),
):
with self.subTest(scraper=module.__name__), \
mock.patch.object(module, attr, Path(directory)), \
self.assertRaises(RuntimeError) as caught:
getattr(module, finder)()
self.assertIn("fbneo.yml", str(caught.exception))
if __name__ == "__main__":
unittest.main()