Files
airdef/tools/test_sound_catalog.py
chexit 1553976484
build / mod (push) Failing after 18s
Share sound identifiers and metadata with resource generation
Co-Authored-By: Codex <noreply@openai.com>
2026-11-04 15:59:18 +03:00

36 lines
1.5 KiB
Python

"""Check sound metadata against shipped resources without regenerating audio."""
import ast
import json
from pathlib import Path
import unittest
from airdef_assets.catalog import load_sounds, sound_events
ROOT = Path(__file__).resolve().parents[1]
class SoundCatalogTests(unittest.TestCase):
def test_registry_and_audio_files_match_catalog(self):
assets = ROOT / "airdef-mod/assets/airdef"
expected = sound_events(load_sounds())
actual = json.loads((assets / "sounds.json").read_text(encoding="utf-8"))
self.assertEqual(actual, expected)
files = {sound["name"].split(":", 1)[1] + ".ogg"
for event in expected.values() for sound in event["sounds"]}
self.assertEqual(files, {path.name for path in (assets / "sounds").glob("*.ogg")})
def test_every_catalog_event_has_one_synthesizer(self):
source = (ROOT / "tools/gen_sounds.py").read_text(encoding="utf-8")
tree = ast.parse(source)
mapping = next(node.value for node in tree.body if isinstance(node, ast.Assign)
and any(isinstance(target, ast.Name) and target.id == "SYNTHESIZERS"
for target in node.targets))
keys = [ast.literal_eval(key) for key in mapping.keys]
self.assertEqual(len(keys), len(set(keys)))
# Synthesis uses a shared random stream, so changing order changes the audio.
self.assertEqual(keys, [entry["event"] for entry in load_sounds()])
if __name__ == "__main__":
unittest.main()