[CI]【Hackathon 9th Sprint No.16】功能模块 fastdeploy/input/ernie4_5_vl_processor/process.py 单测补充 by kesmeey · Pull Request #5264 · PaddlePaddle/FastDeploy (original) (raw)
def test_set_video_frame_args_target_frames_positive_fps_error(self):
"""Test _set_video_frame_args with target_frames > 0 and fps >= 0 (line 514)"""
video_meta = {"duration": 10.0}
video_frame_args = {
"target_frames": 10,
"fps": 2, # Positive fps should raise error
"min_frames": 1,
"max_frames": 100,
}
with self.assertRaises(ValueError) as context:
self.processor._set_video_frame_args(video_frame_args, video_meta)
self.assertIn("fps must be negative", str(context.exception))
def test_set_video_frame_args_target_frames_below_min(self):
"""Test _set_video_frame_args with target_frames < min_frames (line 519)"""
video_meta = {"duration": 10.0}
video_frame_args = {
"target_frames": 5,
"fps": -1,
"min_frames": 10,
"max_frames": 100,
}
with self.assertRaises(ValueError) as context:
self.processor._set_video_frame_args(video_frame_args, video_meta)
self.assertIn("target_frames must be larger", str(context.exception))
def test_set_video_frame_args_target_frames_above_max(self):
"""Test _set_video_frame_args with target_frames > max_frames (line 523)"""
video_meta = {"duration": 10.0}
video_frame_args = {
"target_frames": 200,
"fps": -1,
"min_frames": 1,
"max_frames": 100,
}
with self.assertRaises(ValueError) as context:
self.processor._set_video_frame_args(video_frame_args, video_meta)
self.assertIn("target_frames must be smaller", str(context.exception))
def test_set_video_frame_args_fps_negative_without_target_frames(self):
"""Test _set_video_frame_args with fps < 0 and target_frames <= 0 (line 527)"""
video_meta = {"duration": 10.0}
video_frame_args = {
"target_frames": -1,
"fps": -1,
"min_frames": 1,
"max_frames": 100,
}
with self.assertRaises(ValueError) as context:
self.processor._set_video_frame_args(video_frame_args, video_meta)
self.assertIn("Must provide either positive target_fps", str(context.exception))
def test_set_video_frame_args_min_max_invalid(self):
"""Test _set_video_frame_args with min_frames > max_frames (line 535)"""
video_meta = {"duration": 10.0}
video_frame_args = {
"target_frames": -1,
"fps": 2,
"min_frames": 100,
"max_frames": 10,
}
with self.assertRaises(ValueError) as context:
self.processor._set_video_frame_args(video_frame_args, video_meta)
self.assertIn("min_frames must be smaller", str(context.exception))
def test_set_video_frame_args_frames_too_few_adjustment(self):
"""Test _set_video_frame_args when frames_to_extract < min_frames (line 538)"""
video_meta = {"duration": 1.0} # Short duration
video_frame_args = {
"target_frames": -1,
"fps": 1, # Will extract only 1 frame
"min_frames": 10, # But min is 10
"max_frames": 100,
}
result = self.processor._set_video_frame_args(video_frame_args, video_meta)
self.assertEqual(result["target_frames"], 10)
self.assertEqual(result["fps"], -1)
def test_set_video_frame_args_frames_too_many_adjustment(self):
"""Test _set_video_frame_args when frames_to_extract > max_frames (line 541)"""
video_meta = {"duration": 100.0} # Long duration
video_frame_args = {
"target_frames": -1,
"fps": 10, # Will extract 1000 frames
"min_frames": 1,
"max_frames": 100, # But max is 100
}
result = self.processor._set_video_frame_args(video_frame_args, video_meta)
self.assertEqual(result["target_frames"], 100)
self.assertEqual(result["fps"], -1)