"""
Tests for #632 — Scene description files have no placeholder lyrics or colors.
"""

import json
import os
import unittest
from pathlib import Path

REPO_ROOT = Path(__file__).parent.parent

SCENE_FILES = [
    "training-data/scene-descriptions-rock.jsonl",
    "training-data/scene-descriptions-hip-hop.jsonl",
    "training-data/scene-descriptions-electronic.jsonl",
    "training-data/scene-descriptions-rnb.jsonl",
    "training-data/scene-descriptions-country.jsonl",
    "training-data/scene-descriptions-jazz.jsonl",
    "training-data/scene-descriptions-classical.jsonl",
    "training-data/scene-descriptions-metal.jsonl",
    "training-data/scene-descriptions-latin.jsonl",
]


class TestNoPlaceholders(unittest.TestCase):
    def test_no_placeholder_lyrics(self):
        """No lyric_line contains [Beat N] or other placeholders."""
        for relpath in SCENE_FILES:
            filepath = REPO_ROOT / relpath
            if not filepath.exists():
                continue
            with open(filepath) as f:
                for i, line in enumerate(f, 1):
                    entry = json.loads(line)
                    lyric = entry.get("lyric_line", "")
                    with self.subTest(file=relpath, line=i):
                        self.assertNotIn("[Beat", lyric, f"Placeholder lyric at {relpath}:{i}")
                        self.assertNotIn("[beat", lyric.lower())
                        self.assertGreater(len(lyric), 3, f"Lyric too short at {relpath}:{i}")

    def test_no_placeholder_colors(self):
        """No scene.colors contains 'placeholder'."""
        for relpath in SCENE_FILES:
            filepath = REPO_ROOT / relpath
            if not filepath.exists():
                continue
            with open(filepath) as f:
                for i, line in enumerate(f, 1):
                    entry = json.loads(line)
                    colors = entry.get("scene", {}).get("colors", [])
                    with self.subTest(file=relpath, line=i):
                        for color in colors:
                            self.assertNotIn("placeholder", color.lower(),
                                f"Placeholder color '{color}' at {relpath}:{i}")

    def test_descriptions_are_specific(self):
        """Scene descriptions are not generic templates."""
        for relpath in SCENE_FILES[:1]:  # Just test rock
            filepath = REPO_ROOT / relpath
            if not filepath.exists():
                continue
            with open(filepath) as f:
                for i, line in enumerate(f, 1):
                    entry = json.loads(line)
                    desc = entry.get("scene", {}).get("description", "")
                    with self.subTest(file=relpath, line=i):
                        self.assertGreater(len(desc), 20, f"Description too short at {relpath}:{i}")
                        self.assertNotIn("[placeholder", desc.lower())


if __name__ == "__main__":
    unittest.main()
