| 1 | """Tests for Novel2MoviePipeline initialization.""" |
| 2 | |
| 3 | import ast |
| 4 | from pathlib import Path |
| 5 | import unittest |
| 6 | |
| 7 | |
| 8 | class TestNovel2MoviePipelineInit(unittest.TestCase): |
| 9 | def _class_node(self): |
| 10 | source = Path("pipelines/novel2movie_pipeline.py").read_text(encoding="utf-8") |
| 11 | tree = ast.parse(source) |
| 12 | return next( |
| 13 | node |
| 14 | for node in tree.body |
| 15 | if isinstance(node, ast.ClassDef) and node.name == "Novel2MoviePipeline" |
| 16 | ) |
| 17 | |
| 18 | def test_initializes_runtime_dependencies(self): |
| 19 | class_node = self._class_node() |
| 20 | init_node = next( |
| 21 | node |
| 22 | for node in class_node.body |
| 23 | if isinstance(node, ast.FunctionDef) and node.name == "__init__" |
| 24 | ) |
| 25 | assigned = { |
| 26 | target.attr |
| 27 | for node in ast.walk(init_node) |
| 28 | if isinstance(node, ast.Assign) |
| 29 | for target in node.targets |
| 30 | if isinstance(target, ast.Attribute) |
| 31 | and isinstance(target.value, ast.Name) |
| 32 | and target.value.id == "self" |
| 33 | } |
| 34 | |
| 35 | self.assertTrue( |
| 36 | { |
| 37 | "working_dir", |
| 38 | "novel_compressor", |
| 39 | "event_extractor", |
| 40 | "embeddings", |
| 41 | "rerank_model", |
| 42 | "scene_extractor", |
| 43 | "global_information_planner", |
| 44 | "image_generator", |
| 45 | "rewriter", |
| 46 | "script2video_pipeline", |
| 47 | }.issubset(assigned) |
| 48 | ) |
| 49 | |
| 50 | |
| 51 | if __name__ == "__main__": |
| 52 | unittest.main() |
| 53 |