from reframe_v2 import ( DELIVERY_MIN_WIDTH, concat_list_content, dedupe_sendcmd_lines, delivery_size, general_filtergraph, scene_frame_ranges, ) VERTICAL = 9 / 16 def test_sendcmd_lines_dedupe_to_change_points(): xs = [100, 100, 100, 104, 104, 110] lines = dedupe_sendcmd_lines(xs, fps=30.0) assert lines == [ "0.0000 crop@c x 100;", "0.1000 crop@c x 104;", "0.1667 crop@c x 110;", ] def test_sendcmd_static_camera_is_single_command(): assert len(dedupe_sendcmd_lines([250] * 300, fps=30.0)) == 1 def test_scene_ranges_clamped_and_keep_strategy(): ranges = scene_frame_ranges( [(0, 100), (100, 250), (250, 400)], ['TRACK', 'GENERAL', 'TRACK'], total_frames=200, ) # Third scene starts past the decoded frame count -> dropped, and the # GENERAL strategy stays attached to its own range. assert ranges == [(0, 100, 'TRACK'), (100, 200, 'GENERAL')] def test_scene_ranges_missing_strategy_defaults_to_track(): assert scene_frame_ranges([(0, 10)], [], 10) == [(0, 10, 'TRACK')] def test_concat_list_format(): content = concat_list_content(["/tmp/a/seg_000.mp4", "/tmp/a/seg_001.mp4"]) assert content == "file '/tmp/a/seg_000.mp4'\nfile '/tmp/a/seg_001.mp4'\n" class TestDeliverySize: """A 720p source must not produce a 406x720 clip (prod audit, 25-jul-2026).""" def test_720p_source_is_upscaled_to_the_delivery_floor(self): assert delivery_size(1280, 720, VERTICAL) == (1080, 1920) def test_1080p_source_lands_on_the_floor_exactly(self): assert delivery_size(1920, 1080, VERTICAL) == (1080, 1920) def test_tiny_source_still_reaches_the_floor(self): # 360x640 sources were shipping as-is; platforms treat that as junk. assert delivery_size(640, 360, VERTICAL) == (1080, 1920) def test_high_res_source_is_never_downscaled(self): # 4K source: the native crop is already well past the floor, so keep it. assert delivery_size(3840, 2160, VERTICAL) == (1216, 2160) def test_already_vertical_source_keeps_its_full_height(self): assert delivery_size(1080, 1920, VERTICAL) == (1080, 1920) def test_square_output_uses_the_same_floor(self): assert delivery_size(1280, 720, 1.0) == (1080, 1080) def test_dimensions_are_always_even(self): for w, h in [(1280, 720), (1920, 1080), (854, 480), (3840, 2160), (641, 361)]: out_w, out_h = delivery_size(w, h, VERTICAL) assert out_w % 2 == 0 and out_h % 2 == 0, (w, h) def test_never_returns_below_the_floor(self): for w, h in [(320, 180), (640, 360), (1280, 720), (1920, 1080)]: assert delivery_size(w, h, VERTICAL)[0] >= DELIVERY_MIN_WIDTH def test_aspect_ratio_is_preserved(self): for w, h in [(1280, 720), (640, 360), (3840, 2160)]: out_w, out_h = delivery_size(w, h, VERTICAL) assert abs(out_w / out_h - VERTICAL) < 0.01, (w, h) def test_general_filtergraph_targets_output_geometry(): graph = general_filtergraph(608, 1080) assert "gblur" in graph assert "scale=608:-2" in graph assert "overlay=x=(W-w)/2:y=(H-h)/2" in graph