mirror of
https://github.com/shadoll/moma.git
synced 2026-08-28 03:27:34 +00:00
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:
@@ -1,6 +1,7 @@
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
from renamer.extractors.mediainfo_extractor import MediaInfoExtractor
|
||||
import json
|
||||
|
||||
|
||||
class TestMediaInfoExtractor:
|
||||
@@ -13,6 +14,13 @@ class TestMediaInfoExtractor:
|
||||
"""Use the filenames.txt file for testing"""
|
||||
return Path(__file__).parent / "filenames.txt"
|
||||
|
||||
@pytest.fixture
|
||||
def frame_class_cases(self):
|
||||
"""Load test cases for frame class extraction"""
|
||||
cases_file = Path(__file__).parent / "test_mediainfo_frame_class_cases.json"
|
||||
with open(cases_file, 'r') as f:
|
||||
return json.load(f)
|
||||
|
||||
def test_extract_resolution(self, extractor, test_file):
|
||||
"""Test extracting resolution from media info"""
|
||||
resolution = extractor.extract_resolution()
|
||||
@@ -47,4 +55,22 @@ class TestMediaInfoExtractor:
|
||||
"""Test checking if video is 3D"""
|
||||
is_3d = extractor.is_3d()
|
||||
# Text files don't have video tracks
|
||||
assert is_3d is False
|
||||
assert is_3d is False
|
||||
|
||||
@pytest.mark.parametrize("case", [
|
||||
pytest.param(case, id=case["testname"])
|
||||
for case in json.load(open(Path(__file__).parent / "test_mediainfo_frame_class_cases.json"))
|
||||
])
|
||||
def test_extract_frame_class(self, case):
|
||||
"""Test extracting frame class from various resolutions"""
|
||||
# Create a mock extractor with the test resolution
|
||||
extractor = MediaInfoExtractor.__new__(MediaInfoExtractor)
|
||||
extractor.video_tracks = [{
|
||||
'width': case["resolution"][0],
|
||||
'height': case["resolution"][1],
|
||||
'interlaced': 'Yes' if case["interlaced"] else None
|
||||
}]
|
||||
|
||||
result = extractor.extract_frame_class()
|
||||
print(f"Case: {case['testname']}, resolution: {case['resolution']}, expected: {case['expected_frame_class']}, got: {result}")
|
||||
assert result == case["expected_frame_class"], f"Failed for {case['testname']}: expected {case['expected_frame_class']}, got {result}"
|
||||
@@ -0,0 +1,146 @@
|
||||
[
|
||||
{
|
||||
"testname": "test-480p-sd",
|
||||
"resolution": [720, 480],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "480p"
|
||||
},
|
||||
{
|
||||
"testname": "test-576p-pal",
|
||||
"resolution": [720, 576],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "576p"
|
||||
},
|
||||
{
|
||||
"testname": "test-720p-hd",
|
||||
"resolution": [1280, 720],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "720p"
|
||||
},
|
||||
{
|
||||
"testname": "test-1080p-fullhd",
|
||||
"resolution": [1920, 1080],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "1080p"
|
||||
},
|
||||
{
|
||||
"testname": "test-1080i-broadcast",
|
||||
"resolution": [1920, 1080],
|
||||
"interlaced": true,
|
||||
"expected_frame_class": "1080i"
|
||||
},
|
||||
{
|
||||
"testname": "test-1440p-qhd",
|
||||
"resolution": [2560, 1440],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "1440p"
|
||||
},
|
||||
{
|
||||
"testname": "test-2160p-uhd",
|
||||
"resolution": [3840, 2160],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "2160p"
|
||||
},
|
||||
{
|
||||
"testname": "test-4320p-8k",
|
||||
"resolution": [7680, 4320],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "4320p"
|
||||
},
|
||||
{
|
||||
"testname": "test-1080p-cinema-240",
|
||||
"resolution": [1920, 804],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "1080p"
|
||||
},
|
||||
{
|
||||
"testname": "test-1080p-cinema-235",
|
||||
"resolution": [1920, 816],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "1080p"
|
||||
},
|
||||
{
|
||||
"testname": "test-720p-cinema",
|
||||
"resolution": [1280, 536],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "720p"
|
||||
},
|
||||
{
|
||||
"testname": "test-2160p-cinema",
|
||||
"resolution": [3840, 1608],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "2160p"
|
||||
},
|
||||
{
|
||||
"testname": "test-mobile-vertical-iphone",
|
||||
"resolution": [1170, 2532],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "1440p"
|
||||
},
|
||||
{
|
||||
"testname": "test-mobile-vertical-4k",
|
||||
"resolution": [2160, 3840],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "2160p"
|
||||
},
|
||||
{
|
||||
"testname": "test-square-video",
|
||||
"resolution": [1080, 1080],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "1080p"
|
||||
},
|
||||
{
|
||||
"testname": "test-vhs-capture",
|
||||
"resolution": [720, 404],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "480p"
|
||||
},
|
||||
{
|
||||
"testname": "test-miniDV-pal",
|
||||
"resolution": [720, 576],
|
||||
"interlaced": true,
|
||||
"expected_frame_class": "576i"
|
||||
},
|
||||
{
|
||||
"testname": "test-old-digital-camera-4by3",
|
||||
"resolution": [1024, 768],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "768p"
|
||||
},
|
||||
{
|
||||
"testname": "test-old-digital-camera-lowres",
|
||||
"resolution": [800, 600],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "600p"
|
||||
},
|
||||
{
|
||||
"testname": "test-webcam-legacy",
|
||||
"resolution": [640, 480],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "480p"
|
||||
},
|
||||
{
|
||||
"testname": "test-odd-nonstandard-wide",
|
||||
"resolution": [1600, 900],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "900p"
|
||||
},
|
||||
{
|
||||
"testname": "test-odd-nonstandard-small",
|
||||
"resolution": [854, 480],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "480p"
|
||||
},
|
||||
{
|
||||
"testname": "test-ultrawide-monitor-capture",
|
||||
"resolution": [3440, 1440],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "1440p"
|
||||
},
|
||||
{
|
||||
"testname": "test-strange-lowres",
|
||||
"resolution": [512, 288],
|
||||
"interlaced": false,
|
||||
"expected_frame_class": "288p"
|
||||
}
|
||||
]
|
||||
@@ -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}"
|
||||
Reference in New Issue
Block a user