Spaces:
Sleeping
Sleeping
| 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.story_parser import extract_scene_data | |
| class TestStoryExtraction(unittest.TestCase): | |
| def test_standard_format(self): | |
| content = """ | |
| ## Scene 1 : L'Ombre | |
| **Prompt d'image :** Une silhouette noire dans le brouillard. | |
| **Narration :** L'ombre approchait sans un bruit. | |
| **Texte à l'écran :** CHAPITRE 1 | |
| """ | |
| story_file = Path("engine/tests/temp_test.md") | |
| story_file.write_text(content, encoding="utf-8") | |
| try: | |
| scenes = extract_scene_data(str(story_file)) | |
| self.assertEqual(len(scenes), 1) | |
| self.assertEqual(scenes[0]["prompt"], "Une silhouette noire dans le brouillard.") | |
| self.assertEqual(scenes[0]["narration"], "L'ombre approchait sans un bruit.") | |
| self.assertEqual(scenes[0]["text_overlay"], "CHAPITRE 1") | |
| finally: | |
| if story_file.exists(): story_file.unlink() | |
| def test_variations_and_markdown(self): | |
| content = """ | |
| ## Scene 1 : Test | |
| - **Visual Prompt** : cinematic view of a castle | |
| - **Narration** : "Once upon a time." | |
| - Texte : TITLE | |
| ## Scene 2 : Second | |
| **Visuel** : a knight in armor | |
| Narration : he was brave. | |
| """ | |
| story_file = Path("engine/tests/temp_test_var.md") | |
| story_file.write_text(content, encoding="utf-8") | |
| try: | |
| scenes = extract_scene_data(str(story_file)) | |
| self.assertEqual(len(scenes), 2) | |
| self.assertEqual(scenes[0]["prompt"], "cinematic view of a castle") | |
| self.assertEqual(scenes[0]["narration"], "Once upon a time.") | |
| self.assertEqual(scenes[0]["text_overlay"], "TITLE") | |
| self.assertEqual(scenes[1]["prompt"], "a knight in armor") | |
| self.assertEqual(scenes[1]["narration"], "he was brave.") | |
| finally: | |
| if story_file.exists(): story_file.unlink() | |
| def test_multiline_narration(self): | |
| content = """ | |
| ## Scene 1 | |
| **Narration :** | |
| Ceci est une narration | |
| sur plusieurs lignes | |
| pour tester la robustesse. | |
| **Visual Prompt :** Un champ de fleurs. | |
| """ | |
| story_file = Path("engine/tests/temp_test_multi.md") | |
| story_file.write_text(content, encoding="utf-8") | |
| try: | |
| scenes = extract_scene_data(str(story_file)) | |
| self.assertEqual(len(scenes), 1) | |
| self.assertIn("Ceci est une narration", scenes[0]["narration"]) | |
| self.assertIn("plusieurs lignes", scenes[0]["narration"]) | |
| self.assertEqual(scenes[0]["prompt"], "Un champ de fleurs.") | |
| finally: | |
| if story_file.exists(): story_file.unlink() | |
| if __name__ == "__main__": | |
| unittest.main() | |