|
4 | 4 | import json
|
5 | 5 | import subprocess
|
6 | 6 | from unittest.mock import patch, Mock, call
|
| 7 | +import logging |
7 | 8 |
|
8 | 9 | from lyrics_transcriber.output.video import VideoGenerator
|
9 | 10 |
|
@@ -203,3 +204,94 @@ def test_invalid_video_resolution():
|
203 | 204 | styles = {"karaoke": {"background_color": "black"}}
|
204 | 205 | with pytest.raises(ValueError):
|
205 | 206 | VideoGenerator(output_dir="test", cache_dir="test", video_resolution=(0, 0), styles=styles)
|
| 207 | + |
| 208 | + |
| 209 | +def test_build_ass_filter_no_font_path(video_generator): |
| 210 | + """Test _build_ass_filter with no font path configured.""" |
| 211 | + ass_path = "test.ass" |
| 212 | + result = video_generator._build_ass_filter(ass_path) |
| 213 | + assert result == "ass=test.ass" |
| 214 | + |
| 215 | + |
| 216 | +def test_build_ass_filter_with_valid_font_path(video_generator, tmp_path): |
| 217 | + """Test _build_ass_filter with valid font path.""" |
| 218 | + # Create a test font file |
| 219 | + font_dir = tmp_path / "fonts" |
| 220 | + font_dir.mkdir() |
| 221 | + font_file = font_dir / "test.ttf" |
| 222 | + font_file.touch() |
| 223 | + |
| 224 | + # Update styles to include font path |
| 225 | + video_generator.styles["karaoke"]["font_path"] = str(font_file) |
| 226 | + |
| 227 | + ass_path = "test.ass" |
| 228 | + result = video_generator._build_ass_filter(ass_path) |
| 229 | + expected = f"ass=test.ass:fontsdir={str(font_dir)}" |
| 230 | + assert result == expected |
| 231 | + |
| 232 | + |
| 233 | +def test_build_ass_filter_with_invalid_font_path(video_generator): |
| 234 | + """Test _build_ass_filter with invalid font path (file doesn't exist).""" |
| 235 | + # Set non-existent font path |
| 236 | + video_generator.styles["karaoke"]["font_path"] = "/nonexistent/font.ttf" |
| 237 | + |
| 238 | + ass_path = "test.ass" |
| 239 | + result = video_generator._build_ass_filter(ass_path) |
| 240 | + assert result == "ass=test.ass" |
| 241 | + |
| 242 | + |
| 243 | +def test_build_ass_filter_with_empty_font_path(video_generator): |
| 244 | + """Test _build_ass_filter with empty font path.""" |
| 245 | + # Set empty font path |
| 246 | + video_generator.styles["karaoke"]["font_path"] = "" |
| 247 | + |
| 248 | + ass_path = "test.ass" |
| 249 | + result = video_generator._build_ass_filter(ass_path) |
| 250 | + assert result == "ass=test.ass" |
| 251 | + |
| 252 | + |
| 253 | +def test_build_ass_filter_with_none_font_path(video_generator): |
| 254 | + """Test _build_ass_filter with None font path.""" |
| 255 | + # Set None font path |
| 256 | + video_generator.styles["karaoke"]["font_path"] = None |
| 257 | + |
| 258 | + ass_path = "test.ass" |
| 259 | + result = video_generator._build_ass_filter(ass_path) |
| 260 | + assert result == "ass=test.ass" |
| 261 | + |
| 262 | + |
| 263 | +def test_build_ass_filter_no_karaoke_section(tmp_path): |
| 264 | + """Test _build_ass_filter with no karaoke section in styles.""" |
| 265 | + styles = {} # No karaoke section |
| 266 | + generator = VideoGenerator( |
| 267 | + output_dir=str(tmp_path / "output"), |
| 268 | + cache_dir=str(tmp_path / "cache"), |
| 269 | + video_resolution=(1920, 1080), |
| 270 | + styles=styles, |
| 271 | + ) |
| 272 | + |
| 273 | + ass_path = "test.ass" |
| 274 | + result = generator._build_ass_filter(ass_path) |
| 275 | + assert result == "ass=test.ass" |
| 276 | + |
| 277 | + |
| 278 | +def test_build_ass_filter_logging(video_generator, tmp_path, caplog): |
| 279 | + """Test _build_ass_filter logging behavior.""" |
| 280 | + # Set log level to INFO to capture the logs |
| 281 | + caplog.set_level(logging.INFO) |
| 282 | + |
| 283 | + # Create a test font file |
| 284 | + font_dir = tmp_path / "fonts" |
| 285 | + font_dir.mkdir() |
| 286 | + font_file = font_dir / "test.ttf" |
| 287 | + font_file.touch() |
| 288 | + |
| 289 | + # Update styles to include font path |
| 290 | + video_generator.styles["karaoke"]["font_path"] = str(font_file) |
| 291 | + |
| 292 | + ass_path = "test.ass" |
| 293 | + result = video_generator._build_ass_filter(ass_path) |
| 294 | + |
| 295 | + # Check that info log was generated |
| 296 | + assert "Returning ASS filter with fonts dir:" in caplog.text |
| 297 | + assert str(font_dir) in caplog.text |
0 commit comments