Add unit tests for MediaInfo frame class detection

- Created a JSON file containing various test cases for different video resolutions and their expected frame classes.
- Implemented a pytest test script that loads the test cases and verifies the frame class detection functionality of the MediaInfoExtractor.
- Utilized mocking to simulate the behavior of the MediaInfoExtractor and its video track attributes.
This commit is contained in:
sha
2025-12-29 22:03:41 +00:00
parent e0637e9981
commit 6694567ab4
8 changed files with 259 additions and 17 deletions
@@ -0,0 +1,40 @@
#!/usr/bin/env python3
"""Test script for MediaInfo frame class detection by resolution"""
import json
import pytest
from unittest.mock import MagicMock
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from renamer.extractors.mediainfo_extractor import MediaInfoExtractor
test_cases = json.load(open('renamer/test/test_mediainfo_frame_class.json'))
@pytest.mark.parametrize("test_case", test_cases, ids=[tc['testname'] for tc in test_cases])
def test_frame_class_detection(test_case):
"""Test frame class detection for various resolutions"""
testname = test_case['testname']
width, height = test_case['resolution']
interlaced = test_case['interlaced']
expected = test_case['expected_frame_class']
# Create a mock MediaInfoExtractor
extractor = MagicMock(spec=MediaInfoExtractor)
from pathlib import Path
extractor.file_path = Path(f"test_{testname}") # Set a unique file_path for caching
# Mock the video_tracks
mock_track = MagicMock()
mock_track.height = height
mock_track.width = width
mock_track.interlaced = 'Yes' if interlaced else 'No'
extractor.video_tracks = [mock_track]
# Test the method
actual = MediaInfoExtractor.extract_frame_class(extractor)
assert actual == expected, f"{testname}: expected {expected}, got {actual}"