mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
fix: stop profile loading when pyyaml is missing
load_emulator_profiles warned and returned no profile, so every command reported zero coverage and exited 0. It now goes through model.safeparse.require_yaml: the one-line message and exit 1 the other loaders give.
This commit is contained in:
1 parent
71776198e9
commit
ea68e85c06
2 files changed
+24
-15
No files matched your search
@@ -2,21 +2,16 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
try:
|
||||
import yaml
|
||||
except ImportError:
|
||||
yaml = None
|
||||
|
||||
from core.cli import InputMissing, suggest_names
|
||||
from model.alternatives import derive_member_requirements
|
||||
from model.profilekinds import is_emulator as is_emulator
|
||||
from model.profilekinds import lists_files as lists_files
|
||||
from model.profilekinds import reads_own_files as reads_own_files
|
||||
from model.safeparse import require_yaml
|
||||
from model.sources import source_yaml_file
|
||||
from model.systems import norm_system_id, system_index
|
||||
from core.paths import REPO_ROOT
|
||||
@@ -219,15 +214,9 @@ def load_emulator_profiles(
|
||||
}
|
||||
emulator_profiles_cache[cache_key] = profiles
|
||||
return profiles
|
||||
if importlib.util.find_spec("yaml") is None:
|
||||
# Every consumer reads {} as "this repo documents no emulator", which
|
||||
# is what a broken install looks like from the outside: zero coverage,
|
||||
# no gap, nothing to fix.
|
||||
print(
|
||||
"warning: pyyaml is not installed, no emulator profile was loaded",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return {}
|
||||
# Read as {}, a missing PyYAML looked like a repo documenting no
|
||||
# emulator: zero coverage, no gap, nothing to fix.
|
||||
require_yaml()
|
||||
profiles = {}
|
||||
emu_path = Path(emulators_dir)
|
||||
if not emu_path.is_dir():
|
||||
|
||||
@@ -178,5 +178,25 @@ class TheDownloaderRunsWithoutPyyaml(unittest.TestCase):
|
||||
self.assertEqual(completed.returncode, 0, completed.stderr[-1500:])
|
||||
|
||||
|
||||
class ProfilesWithoutPyyamlStopOnOneLine(unittest.TestCase):
|
||||
"""load_emulator_profiles warned and returned {} without PyYAML: every
|
||||
caller then read a repository that documents no emulator, zero coverage
|
||||
and nothing to fix, and exited 0."""
|
||||
|
||||
def test_the_loader_exits_with_the_shared_message(self):
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
code = (
|
||||
"import sys; sys.modules['yaml'] = None; sys.path.insert(0, 'scripts'); "
|
||||
"from model.profiles import load_emulator_profiles; "
|
||||
"load_emulator_profiles('emulators')"
|
||||
)
|
||||
completed = subprocess.run(
|
||||
[sys.executable, "-I", "-c", code], cwd=root, capture_output=True,
|
||||
text=True, timeout=120, check=False,
|
||||
)
|
||||
self.assertEqual(completed.returncode, 1, completed.stderr[-1500:])
|
||||
self.assertEqual(completed.stderr.strip(), "Error: PyYAML required (pip install pyyaml)")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user