darkmedia-x-api / engine /tests /test_normalizer.py
cybermedia's picture
Upload folder using huggingface_hub
343eed9 verified
import unittest
import sys
from pathlib import Path
# Add project root to path
ROOT_DIR = Path(__file__).resolve().parent.parent.parent
sys.path.append(str(ROOT_DIR))
from engine.utils.normalizer import normalize_content
class TestNormalizer(unittest.TestCase):
def test_gemini_messy_format(self):
"""Teste le format typique renvoyé par Gemini."""
messy_input = """
## Scene 1 : Le Phare (0-5s)
L'Histoire : Il était une fois un phare.
Audio : Corne de brume.
**Visual Prompt** : Establishing shot of lighthouse, dark anime style --ar 9:16
"""
output = normalize_content(messy_input)
self.assertIn('**Visual Prompt :** Establishing shot of lighthouse, dark anime style --ar 9:16', output)
self.assertIn('**Narration :** "Il était une fois un phare. Corne de brume."', output)
self.assertNotIn('(0-5s)', output)
def test_english_prompt_only(self):
"""Teste le cas où Gemini renvoie juste un 'Visual Prompt' sans narration explicite."""
messy_input = """
## Scene 6
**Visual Prompt** : Inside the staircase. Thousands of eyes. --ar 9:16
"""
output = normalize_content(messy_input)
# Le visuel doit être capturé
self.assertIn('**Visual Prompt :** Inside the staircase. Thousands of eyes. --ar 9:16', output)
# La narration doit être vide (et non contenir le label Visual Prompt)
self.assertIn('**Narration :** ""', output)
def test_cinematic_fallback(self):
"""Teste le cas sans aucun label (brut)."""
messy_input = """
## Scene 1
Plan de drone sur la forêt.
"Ils arrivent."
"""
output = normalize_content(messy_input)
self.assertIn('**Visual Prompt :** Plan de drone sur la forêt.', output)
self.assertIn('**Narration :** "Ils arrivent."', output)
def test_idempotency(self):
"""Vérifie que normaliser un fichier déjà standard ne change rien."""
standard = """## Scene 1\n**Visual Prompt :** Test\n**Narration :** "Test"\n\n"""
output = normalize_content(standard)
# On ignore les différences de sauts de ligne finaux pour ce test
self.assertEqual(output.strip(), standard.strip())
def test_cleaning_markers(self):
"""Vérifie le nettoyage des ** et des guillemets dans les champs."""
messy = """## Scene 1\n**Visual Prompt** : **Un monstre**\nNarration : "L'horreur"\n"""
output = normalize_content(messy)
self.assertIn('**Visual Prompt :** Un monstre', output)
self.assertIn('**Narration :** "L\'horreur"', output)
if __name__ == "__main__":
unittest.main()